Permalink
Browse files

implement prev/next year in entry_archive_year view

  • Loading branch information...
1 parent db19071 commit 08a52c01a4a23f632fb9ba4adaedec41437d9654 @Fantomas42 committed Mar 9, 2013
@@ -20,4 +20,17 @@ <h2>{% trans "Monthly archives" %}</h2>
</li>
{% endfor %}
</ul>
+
+{% if previous_year %}
+<h3>{% trans "Previous year" %}</h3>
+<p>
+ <a href="{% url 'zinnia_entry_archive_year' previous_year|date:"Y" %}" rel="archives">{{ previous_year|date:"Y" }}</a>
+</p>
+{% endif %}
+{% if next_year %}
+<h3>{% trans "Next year" %}</h3>
+<p>
+ <a href="{% url 'zinnia_entry_archive_year' next_year|date:"Y" %}" rel="archives">{{ next_year|date:"Y" }}</a>
+</p>
+{% endif %}
{% endblock %}
View
@@ -239,7 +239,7 @@ def test_previous_next_published_mixin(self):
params = {'title': 'Entry 3', 'content': 'Entry 3',
'slug': 'entry-3', 'status': PUBLISHED,
- 'creation_date': datetime(2012, 6, 2, 12)}
+ 'creation_date': datetime(2013, 6, 2, 12)}
entry_3 = Entry.objects.create(**params)
entry_3.sites.add(site)
@@ -249,32 +249,42 @@ def get_queryset(self):
epnp = EntryPreviousNextPublished()
test_date = datetime(2009, 12, 1)
+ self.assertEquals(epnp.get_previous_year(test_date), None)
self.assertEquals(epnp.get_previous_month(test_date), None)
self.assertEquals(epnp.get_previous_day(test_date), None)
+ self.assertEquals(epnp.get_next_year(test_date), date(2012, 1, 1))
self.assertEquals(epnp.get_next_month(test_date), date(2012, 1, 1))
self.assertEquals(epnp.get_next_day(test_date), date(2012, 1, 1))
test_date = datetime(2012, 1, 1)
+ self.assertEquals(epnp.get_previous_year(test_date), None)
self.assertEquals(epnp.get_previous_month(test_date), None)
self.assertEquals(epnp.get_previous_day(test_date), None)
+ self.assertEquals(epnp.get_next_year(test_date), date(2013, 1, 1))
self.assertEquals(epnp.get_next_month(test_date), date(2012, 3, 1))
self.assertEquals(epnp.get_next_day(test_date), date(2012, 3, 15))
test_date = datetime(2012, 3, 15)
+ self.assertEquals(epnp.get_previous_year(test_date), None)
self.assertEquals(epnp.get_previous_month(test_date), date(2012, 1, 1))
self.assertEquals(epnp.get_previous_day(test_date), date(2012, 1, 1))
- self.assertEquals(epnp.get_next_month(test_date), date(2012, 6, 1))
- self.assertEquals(epnp.get_next_day(test_date), date(2012, 6, 2))
+ self.assertEquals(epnp.get_next_year(test_date), date(2013, 1, 1))
+ self.assertEquals(epnp.get_next_month(test_date), date(2013, 6, 1))
+ self.assertEquals(epnp.get_next_day(test_date), date(2013, 6, 2))
- test_date = datetime(2012, 6, 2)
+ test_date = datetime(2013, 6, 2)
+ self.assertEquals(epnp.get_previous_year(test_date), date(2012, 1, 1))
self.assertEquals(epnp.get_previous_month(test_date), date(2012, 3, 1))
self.assertEquals(epnp.get_previous_day(test_date), date(2012, 3, 15))
+ self.assertEquals(epnp.get_next_year(test_date), None)
self.assertEquals(epnp.get_next_month(test_date), None)
self.assertEquals(epnp.get_next_day(test_date), None)
- test_date = datetime(2013, 5, 1)
- self.assertEquals(epnp.get_previous_month(test_date), date(2012, 6, 1))
- self.assertEquals(epnp.get_previous_day(test_date), date(2012, 6, 2))
+ test_date = datetime(2014, 5, 1)
+ self.assertEquals(epnp.get_previous_year(test_date), date(2013, 1, 1))
+ self.assertEquals(epnp.get_previous_month(test_date), date(2013, 6, 1))
+ self.assertEquals(epnp.get_previous_day(test_date), date(2013, 6, 2))
+ self.assertEquals(epnp.get_next_year(test_date), None)
self.assertEquals(epnp.get_next_month(test_date), None)
self.assertEquals(epnp.get_next_day(test_date), None)
View
@@ -136,7 +136,7 @@ def test_zinnia_entry_archive_year(self):
setup_test_template_loader(
{'zinnia/archives/2010/entry_archive_year.html': ''})
response = self.check_publishing_context(
- '/2010/', 2, 3, 'entry_list', 2)
+ '/2010/', 2, 3, 'entry_list', 4)
self.assertTemplateUsed(
response, 'zinnia/archives/2010/entry_archive_year.html')
restore_template_loaders()
@@ -44,6 +44,18 @@ def get_previous_next_published(self, date, period, previous=True):
if dates:
return dates[0].date()
+ def get_next_year(self, date):
+ """Get the next year with published Entries"""
+ return self.get_previous_next_published(
+ datetime(date.year, 1, 1), 'year',
+ previous=False)
+
+ def get_previous_year(self, date):
+ """Get the previous year with published Entries"""
+ return self.get_previous_next_published(
+ datetime(date.year, 1, 1), 'year',
+ previous=True)
+
def get_next_month(self, date):
"""Get the next month with published Entries"""
return self.get_previous_next_published(

0 comments on commit 08a52c0

Please sign in to comment.