1. Yann Malet
  2. byteflow

Commits

Alexander Solovyov  committed 0d5f8b8

datelinks: be able to render to different urls

  • Participants
  • Parent commits 652aa9a
  • Branches default

Comments (0)

Files changed (3)

File apps/blog/templatetags/datelinks.py

View file
 from django.core.urlresolvers import reverse
 from django.utils.safestring import mark_safe
 
+from lib.helpers import reverse
+
 register = Library()
 
 @register.filter
-def datelinks(value):
+def datelinks(value, tail='_archive'):
     """
     This filter formats date as "day.month.year" and sets links to
     day/month/year-based archives.
         - month_archive
         - year_archive
     """
-    return mark_safe(loader.render_to_string('templatetags/datelinks.html', {'date': value}))
+    ctx = {'year': reverse('year'+tail, year=value.year),
+           'month': reverse('month'+tail, year=value.year,
+                            month=value.strftime('%m')),
+           'day': reverse('day'+tail, year=value.year,
+                          month=value.strftime('%m'),
+                          day=value.strftime('%d')),
+           'date': value}
+    return mark_safe(loader.render_to_string('templatetags/datelinks.html', ctx))
 
 
 @register.filter

File templates/templatetags/datelinks.html

View file
-{% load i18n %}<a href="{% url day_archive date.year,date|date:"m",date|date:"d" %}" class="archive" title="{% trans "Click to see day archive" %}">{{ date|date:"d" }}</a>.<a href="{% url month_archive date.year,date|date:"m" %}" class="archive" title="{% trans "Click to see month archive" %}">{{ date|date:"m" }}</a>.<a href="{% url year_archive year=date.year %}" class="archive" title="{% trans "Click to see year archive" %}">{{ date|date:"Y" }}</a>
+{% load i18n %}<a href="{{ day }}" class="archive" title="{% trans "Click to see day archive" %}">{{ date|date:"d" }}</a>.<a href="{{ month }}" class="archive" title="{% trans "Click to see month archive" %}">{{ date|date:"m" }}</a>.<a href="{{ year }}" class="archive" title="{% trans "Click to see year archive" %}">{{ date|date:"Y" }}</a>

File themes/mirev/templatetags/datelinks.html

View file
-{% load i18n %}<a href="{% url year_archive year=date.year %}" class="archive" title="{% trans "Click to see year archive" %}">{{ date|date:"Y" }}</a>,
-<a href="{% url month_archive date.year,date|date:"m" %}" class="archive" title="{% trans "Click to see month archive" %}">{{ date|date:"F" }}</a>
-<a href="{% url day_archive date.year,date|date:"m",date|date:"d" %}" class="archive" title="{% trans "Click to see day archive" %}">{{ date|date:"d" }}</a>
+{% load i18n %}<a href="{{ year }}" class="archive" title="{% trans "Click to see year archive" %}">{{ date|date:"Y" }}</a>,
+<a href="{{ month }}" class="archive" title="{% trans "Click to see month archive" %}">{{ date|date:"F" }}</a>
+<a href="{{ day }}" class="archive" title="{% trans "Click to see day archive" %}">{{ date|date:"d" }}</a>