Skip to content

Commit

Permalink
improve some code smells and errors
Browse files Browse the repository at this point in the history
  • Loading branch information
llazzaro committed Jul 11, 2015
1 parent 69da14e commit bf2c707
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
4 changes: 1 addition & 3 deletions schedule/conf/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from six.moves.builtins import str
from django.core.exceptions import ImproperlyConfigured
from annoying.functions import get_config

AUTH_USER_MODEL = get_config('AUTH_USER_MODEL')
Expand Down Expand Up @@ -40,7 +38,7 @@ def check_calendar_permission(ob, user):
GET_EVENTS_FUNC = get_config('GET_EVENTS_FUNC', None)
if not GET_EVENTS_FUNC:
def get_events(request, calendar):
return calendar.event_set.prefetch_related('occurrence_set','rule')
return calendar.event_set.prefetch_related('occurrence_set', 'rule')

GET_EVENTS_FUNC = get_events

Expand Down
4 changes: 2 additions & 2 deletions schedule/feeds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from django.core.exceptions import ObjectDoesNotExist
from django.conf import settings
from schedule.feeds.ical import ICalendarFeed
from django.http import HttpResponse
import datetime, itertools
import itertools
from django.utils import timezone


class UpcomingEventsFeed(Feed):
feed_id = "upcoming"

Expand Down
6 changes: 3 additions & 3 deletions schedule/periods.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import calendar as standardlib_calendar

from django.conf import settings
from django.utils.translation import ugettext
from django.utils.encoding import python_2_unicode_compatible
from django.template.defaultfilters import date as date_filter
from django.utils.dates import WEEKDAYS, WEEKDAYS_ABBR
Expand Down Expand Up @@ -178,15 +179,14 @@ def get_months(self):
def next_year(self):
return Year(self.events, self.end, tzinfo=self.tzinfo)
next = __next__ = next_year


def prev_year(self):
start = datetime.datetime(self.start.year - 1, self.start.month, self.start.day)
return Year(self.events, start, tzinfo=self.tzinfo)
prev = prev_year

def _get_year_range(self, year):
#If tzinfo is not none get the local start of the year and convert it to utc.
# If tzinfo is not none get the local start of the year and convert it to utc.
naive_start = datetime.datetime(year.year, datetime.datetime.min.month, datetime.datetime.min.day)
naive_end = datetime.datetime(year.year + 1, datetime.datetime.min.month, datetime.datetime.min.day)

Expand Down Expand Up @@ -254,7 +254,7 @@ def next_year(self):
def _get_month_range(self, month):
year = month.year
month = month.month
#If tzinfo is not none get the local start of the month and convert it to utc.
# If tzinfo is not none get the local start of the month and convert it to utc.
naive_start = datetime.datetime.min.replace(year=year, month=month)
if month == 12:
naive_end = datetime.datetime.min.replace(month=1, year=year + 1, day=1)
Expand Down
7 changes: 4 additions & 3 deletions schedule/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.utils import timezone
from django.utils.module_loading import import_string
from schedule.conf.settings import (
CHECK_EVENT_PERM_FUNC,
CHECK_EVENT_PERM_FUNC,
CHECK_CALENDAR_PERM_FUNC,
CALENDAR_VIEW_PERM)

Expand Down Expand Up @@ -116,6 +116,7 @@ def decorator(request, *args, **kwargs):

return decorator


def check_calendar_permissions(function):
@wraps(function)
def decorator(request, *args, **kwargs):
Expand All @@ -138,6 +139,7 @@ def decorator(request, *args, **kwargs):

return decorator


def coerce_date_dict(date_dict):
"""
given a dictionary (presumed to be from request.GET) it returns a tuple
Expand All @@ -163,12 +165,11 @@ def coerce_date_dict(date_dict):
break
return modified and ret_val or {}


def get_model_bases():
from django.conf import settings
from django.db.models import Model
baseStrings = getattr(settings, 'SCHEDULER_BASE_CLASSES', None)
if baseStrings is None:
return [Model]
else:
return [import_string(x) for x in baseStrings]

0 comments on commit bf2c707

Please sign in to comment.