Skip to content

Commit

Permalink
Merge branch 'feature/week-for-calendar' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Fantomas42 committed Jan 13, 2015
2 parents 35ac60b + 7bbb4a7 commit 6053651
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
11 changes: 7 additions & 4 deletions zinnia/templatetags/zinnia.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,13 @@ def get_calendar_entries(context, year=None, month=None,
Return an HTML calendar of entries.
"""
if not (year and month):
month_day = context.get('month') or context.get('day')
creation_date = getattr(context.get('object'), 'creation_date', None)
if month_day:
current_month = month_day
day_week_month = (context.get('day') or
context.get('week') or
context.get('month'))
creation_date = getattr(context.get('object'),
'creation_date', None)
if day_week_month:
current_month = day_week_month
elif creation_date:
if settings.USE_TZ:
creation_date = timezone.localtime(creation_date)
Expand Down
24 changes: 24 additions & 0 deletions zinnia/tests/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,30 @@ def test_get_calendar_entries_month_context(self):
self.assertEqual(context['previous_month'], None)
self.assertEqual(context['next_month'], None)

def test_get_calendar_entries_week_context(self):
self.publish_entry()
source_context = Context({'week': date(2009, 1, 5)})
with self.assertNumQueries(2):
context = get_calendar_entries(source_context)
self.assertEqual(context['previous_month'], None)
self.assertEqual(
context['next_month'],
self.make_local(self.entry.creation_date).date().replace(day=1))

source_context = Context({'week': date(2010, 5, 31)})
with self.assertNumQueries(2):
context = get_calendar_entries(source_context)
self.assertEqual(
context['previous_month'],
self.make_local(self.entry.creation_date).date().replace(day=1))
self.assertEqual(context['next_month'], None)

source_context = Context({'week': date(2010, 1, 4)})
with self.assertNumQueries(2):
context = get_calendar_entries(source_context)
self.assertEqual(context['previous_month'], None)
self.assertEqual(context['next_month'], None)

def test_get_calendar_entries_day_context(self):
self.publish_entry()
source_context = Context({'day': date(2009, 1, 15)})
Expand Down

0 comments on commit 6053651

Please sign in to comment.