# Path: schedule/settings.py
# CALENDAR_VIEW_PERM = getattr(settings, "CALENDAR_VIEW_PERM", False)
# 
# CHECK_CALENDAR_PERM_FUNC = getattr(settings, "CHECK_CALENDAR_PERM_FUNC", None)
# 
# CHECK_EVENT_PERM_FUNC = getattr(settings, "CHECK_EVENT_PERM_FUNC", None)
# 
# CHECK_OCCURRENCE_PERM_FUNC = getattr(settings, "CHECK_OCCURRENCE_PERM_FUNC", None)


import heapq
from functools import wraps
from django.conf import settings
from django.http import HttpResponseNotFound, HttpResponseRedirect
from django.utils import timezone
from schedule.settings import (
    CALENDAR_VIEW_PERM,
    CHECK_CALENDAR_PERM_FUNC,
    CHECK_EVENT_PERM_FUNC,
    CHECK_OCCURRENCE_PERM_FUNC,
)
        from schedule.models import Occurrence
    from schedule.models import Occurrence
    from schedule.models import Event
    from schedule.models import Calendar

def check_event_permissions(function):
    @wraps(function)
    def decorator(request, *args, **kwargs):
        user = request.user
        if not user:
            return HttpResponseRedirect(settings.LOGIN_URL)
        occurrence, event, calendar = get_objects(request, **kwargs)
        if calendar:
            allowed = CHECK_EVENT_PERM_FUNC(event, user) and CHECK_CALENDAR_PERM_FUNC(
                calendar, user
            )
            if not allowed:
                return HttpResponseRedirect(settings.LOGIN_URL)
            # all checks passed
            return function(request, *args, **kwargs)
        return HttpResponseNotFound("<h1>Page not found</h1>")

    return decorator


def check_calendar_permissions(function):
    @wraps(function)
    def decorator(request, *args, **kwargs):
        if CALENDAR_VIEW_PERM:
            user = request.user
            if not user:
                return HttpResponseRedirect(settings.LOGIN_URL)
            occurrence, event, calendar = get_objects(request, **kwargs)
            if calendar:

# Path: schedule/settings.py
# CALENDAR_VIEW_PERM = getattr(settings, "CALENDAR_VIEW_PERM", False)
# 
# CHECK_CALENDAR_PERM_FUNC = getattr(settings, "CHECK_CALENDAR_PERM_FUNC", None)
# 
# CHECK_EVENT_PERM_FUNC = getattr(settings, "CHECK_EVENT_PERM_FUNC", None)
# 
# CHECK_OCCURRENCE_PERM_FUNC = getattr(settings, "CHECK_OCCURRENCE_PERM_FUNC", None)


# Path: schedule/utils.py
import heapq
from functools import wraps
from django.conf import settings
from django.http import HttpResponseNotFound, HttpResponseRedirect
from django.utils import timezone
from schedule.settings import (
    CALENDAR_VIEW_PERM,
    CHECK_CALENDAR_PERM_FUNC,
    CHECK_EVENT_PERM_FUNC,
    CHECK_OCCURRENCE_PERM_FUNC,
)
        from schedule.models import Occurrence
    from schedule.models import Occurrence
    from schedule.models import Event
    from schedule.models import Calendar


def check_event_permissions(function):
    @wraps(function)
    def decorator(request, *args, **kwargs):
        user = request.user
        if not user:
            return HttpResponseRedirect(settings.LOGIN_URL)
        occurrence, event, calendar = get_objects(request, **kwargs)
        if calendar:
            allowed = CHECK_EVENT_PERM_FUNC(event, user) and CHECK_CALENDAR_PERM_FUNC(
                calendar, user
            )
            if not allowed:
                return HttpResponseRedirect(settings.LOGIN_URL)
            # all checks passed
            return function(request, *args, **kwargs)
        return HttpResponseNotFound("<h1>Page not found</h1>")

    return decorator


def check_calendar_permissions(function):
    @wraps(function)
    def decorator(request, *args, **kwargs):
        if CALENDAR_VIEW_PERM:
            user = request.user
            if not user:
                return HttpResponseRedirect(settings.LOGIN_URL)
            occurrence, event, calendar = get_objects(request, **kwargs)
            if calendar:

                allowed = CHECK_CALENDAR_PERM_FUNC(calendar, user)