add tag for entry url
[django-migdal.git] / migdal / templatetags / migdal_tags.py
index c1b824c..9c2609c 100644 (file)
@@ -2,12 +2,12 @@
 # This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later.
 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
 #
+from django.shortcuts import get_object_or_404
 from django_comments_xtd.models import XtdComment
-from django.contrib import comments
+import django_comments as comments
 from django import template
 from migdal import app_settings
 from migdal.models import Category, Entry
-from django.utils.translation import ugettext_lazy as _
 
 register = template.Library()
 
@@ -57,16 +57,15 @@ def entry_promobox(context, entry, counter):
 def categories(context, taxonomy):
     context = {
         'request': context['request'],
-        'object_list': Category.objects.filter(taxonomy=taxonomy
-                ).exclude(entry__isnull=True)
+        'object_list': Category.objects.filter(taxonomy=taxonomy).exclude(entry__isnull=True)
     }
     return context
 
 
 @register.inclusion_tag('migdal/last_comments.html')
 def last_comments(limit=app_settings.LAST_COMMENTS):
-    return {'object_list': 
-        XtdComment.objects.filter(is_public=True, is_removed=False).order_by('-submit_date')[:limit]}
+    return {
+        'object_list': XtdComment.objects.filter(is_public=True, is_removed=False).order_by('-submit_date')[:limit]}
 
 
 @register.inclusion_tag(['comments/form.html'])
@@ -75,3 +74,9 @@ def entry_comment_form(entry):
             'form': comments.get_form()(entry),
             'next': entry.get_absolute_url(),
         }
+
+
+@register.simple_tag
+def entry_url(slug, lang='pl'):
+    entry = get_object_or_404(Entry, **{'slug_%s' % lang: slug})
+    return entry.get_absolute_url()