# 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
    calendar = None
    if event:
        calendar = event.calendar
    else:
        calendar_slug = get_kwarg_or_param(request, kwargs, "calendar_slug")
        calendar = (
            Calendar.objects.filter(slug=calendar_slug).first()
            if calendar_slug
            else None
        )
    return calendar


def get_objects(request, **kwargs):
    occurrence = get_occurrence(request, **kwargs)
    event = get_event(occurrence, request, **kwargs)
    calendar = get_calendar(event, request, **kwargs)
    return occurrence, event, calendar


def check_occurrence_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 and event:
            allowed = (
                CHECK_EVENT_PERM_FUNC(event, user)

# 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

    calendar = None
    if event:
        calendar = event.calendar
    else:
        calendar_slug = get_kwarg_or_param(request, kwargs, "calendar_slug")
        calendar = (
            Calendar.objects.filter(slug=calendar_slug).first()
            if calendar_slug
            else None
        )
    return calendar


def get_objects(request, **kwargs):
    occurrence = get_occurrence(request, **kwargs)
    event = get_event(occurrence, request, **kwargs)
    calendar = get_calendar(event, request, **kwargs)
    return occurrence, event, calendar


def check_occurrence_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 and event:
            allowed = (
                CHECK_EVENT_PERM_FUNC(event, user)

                and CHECK_CALENDAR_PERM_FUNC(calendar, user)