Skip to content

Commit

Permalink
Merge pull request #373 from jdufresne/drop-annoying
Browse files Browse the repository at this point in the history
Remove unnecessary django-annoying dependency
  • Loading branch information
kimarakov committed Jan 3, 2018
2 parents 866cdcc + 63f4053 commit 59f9b0e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 48 deletions.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
coverage>=3.7.1
coveralls>=0.5
django-annoying>=0.8.0
Django>=1.11
flake8
icalendar>=3.8.4
Expand Down
24 changes: 12 additions & 12 deletions schedule/settings.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from annoying.functions import get_config
from django.conf import settings

# whether to display cancelled occurrences
# (if they are displayed then they have a css class "cancelled")
# this controls behaviour of Period.classify_occurrence method
SHOW_CANCELLED_OCCURRENCES = get_config('SHOW_CANCELLED_OCCURRENCES', False)
SHOW_CANCELLED_OCCURRENCES = getattr(settings, 'SHOW_CANCELLED_OCCURRENCES', False)

# Callable used to check if a user has edit permissions to event
# (and occurrence). Used by check_edit_permission decorator
# if ob==None we check permission to add occurrence
CHECK_EVENT_PERM_FUNC = get_config('CHECK_EVENT_PERM_FUNC', None)
CHECK_EVENT_PERM_FUNC = getattr(settings, 'CHECK_EVENT_PERM_FUNC', None)

if not CHECK_EVENT_PERM_FUNC:
def check_event_permission(ob, user):
Expand All @@ -17,43 +17,43 @@ def check_event_permission(ob, user):
CHECK_EVENT_PERM_FUNC = check_event_permission

# Callable used to check if a user has edit permissions to occurrence
CHECK_OCCURRENCE_PERM_FUNC = get_config('CHECK_OCCURRENCE_PERM_FUNC', None)
CHECK_OCCURRENCE_PERM_FUNC = getattr(settings, 'CHECK_OCCURRENCE_PERM_FUNC', None)

if not CHECK_OCCURRENCE_PERM_FUNC:
def check_occurrence_permission(ob, user):
return CHECK_EVENT_PERM_FUNC(ob.event, user)
CHECK_OCCURRENCE_PERM_FUNC = check_occurrence_permission

CALENDAR_VIEW_PERM = get_config('CALENDAR_VIEW_PERM', False)
CALENDAR_VIEW_PERM = getattr(settings, 'CALENDAR_VIEW_PERM', False)

# Callable used to check if a user has edit permissions to calendar
CHECK_CALENDAR_PERM_FUNC = get_config('CHECK_CALENDAR_PERM_FUNC', None)
CHECK_CALENDAR_PERM_FUNC = getattr(settings, 'CHECK_CALENDAR_PERM_FUNC', None)

if not CHECK_CALENDAR_PERM_FUNC:
def check_calendar_permission(ob, user):
return user.is_authenticated

CHECK_CALENDAR_PERM_FUNC = check_calendar_permission

CALENDAR_VIEW_PERM = get_config('CALENDAR_VIEW_PERM', False)
CALENDAR_VIEW_PERM = getattr(settings, 'CALENDAR_VIEW_PERM', False)

# Callable used to customize the event list given for a calendar and user
# (e.g. all events on that calendar, those events plus another calendar's events,
# or the events filtered based on user permissions)
# Imports have to be placed within the function body to avoid circular imports
GET_EVENTS_FUNC = get_config('GET_EVENTS_FUNC', None)
GET_EVENTS_FUNC = getattr(settings, 'GET_EVENTS_FUNC', None)
if not GET_EVENTS_FUNC:
def get_events(request, calendar):
return calendar.event_set.prefetch_related('occurrence_set', 'rule')

GET_EVENTS_FUNC = get_events

# URL to redirect to to after an occurrence is canceled
OCCURRENCE_CANCEL_REDIRECT = get_config('OCCURRENCE_CANCEL_REDIRECT', None)
OCCURRENCE_CANCEL_REDIRECT = getattr(settings, 'OCCURRENCE_CANCEL_REDIRECT', None)

SCHEDULER_PREVNEXT_LIMIT_SECONDS = get_config('SCHEDULER_PREVNEXT_LIMIT_SECONDS', 62208000) # two years
SCHEDULER_PREVNEXT_LIMIT_SECONDS = getattr(settings, 'SCHEDULER_PREVNEXT_LIMIT_SECONDS', 62208000) # two years

USE_FULLCALENDAR = get_config('USE_FULLCALENDAR', False)
USE_FULLCALENDAR = getattr(settings, 'USE_FULLCALENDAR', False)

# This name is used when a new event is created through selecting in fullcalendar
EVENT_NAME_PLACEHOLDER = get_config('EVENT_NAME_PLACEHOLDER', 'Event Name')
EVENT_NAME_PLACEHOLDER = getattr(settings, 'EVENT_NAME_PLACEHOLDER', 'Event Name')
54 changes: 20 additions & 34 deletions schedule/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import heapq
from functools import wraps

from annoying.functions import get_object_or_None
from django.conf import settings
from django.http import HttpResponseNotFound, HttpResponseRedirect
from django.utils import timezone
Expand Down Expand Up @@ -93,37 +92,31 @@ def get_additional_occurrences(self, start, end):
return [occ for _, occ in list(self.lookup.items()) if (occ.start < end and occ.end >= start and not occ.cancelled)]


def get_kwarg_or_param(request, kwargs, key):
value = None
try:
value = kwargs[key]
except KeyError:
if request.method == 'GET':
value = request.GET.get(key)
elif request.method == 'POST':
value = request.POST.get(key)
return value


def get_occurrence(request, **kwargs):
from schedule.models import Occurrence
occurrence = None
if 'occurrence_id' in kwargs:
occurrence = get_object_or_None(Occurrence, id=kwargs['occurrence_id'])
elif request.GET:
occurrence = get_object_or_None(
Occurrence,
id=request.GET.get('occurrence_id'))
elif request.POST:
occurrence = get_object_or_None(
Occurrence,
id=request.POST.get('occurrence_id'))
return occurrence
occurrence_id = get_kwarg_or_param(request, kwargs, 'occurrence_id')
return Occurrence.objects.filter(pk=occurrence_id).first() if occurrence_id else None


def get_event(occurrence, request, **kwargs):
from schedule.models import Event
event = None
if occurrence:
event = occurrence.event
elif 'event_id' in kwargs:
event = get_object_or_None(Event, id=kwargs['event_id'])
elif request.GET:
event = get_object_or_None(
Event,
id=request.GET.get('event_id'))
elif request.POST:
event = get_object_or_None(
Event,
id=request.POST.get('event_id'))
else:
event_id = get_kwarg_or_param(request, kwargs, 'event_id')
event = Event.objects.filter(pk=event_id).first() if event_id else None
return event


Expand All @@ -132,16 +125,9 @@ def get_calendar(event, request, **kwargs):
calendar = None
if event:
calendar = event.calendar
elif 'calendar_slug' in kwargs:
calendar = get_object_or_None(Calendar, slug=kwargs['calendar_slug'])
elif request.GET:
calendar = get_object_or_None(
Calendar,
slug=request.GET.get('calendar_slug'))
elif request.POST:
calendar = get_object_or_None(
Calendar,
slug=request.POST.get('calendar_slug'))
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


Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
'python-dateutil>=2.1',
'pytz>=2013.9',
'icalendar>=3.8.4',
'django-annoying>=0.8.0',
],
license='BSD',
test_suite='runtests.runtests',
Expand Down

0 comments on commit 59f9b0e

Please sign in to comment.