diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2012-10-10 19:12:07 +0200 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2012-10-10 19:12:07 +0200 |
commit | fbfe8fc7ea6ba91661027ea51dec290823f9e0bb (patch) | |
tree | 0000af97b2ca88ee0b92f5ac666a9a91682f0e7e /hyperkitty/templatetags | |
parent | 7558ef3a1e4f2625075d8a34b25224f7e595c939 (diff) | |
download | hyperkitty-fbfe8fc7ea6ba91661027ea51dec290823f9e0bb.tar.gz hyperkitty-fbfe8fc7ea6ba91661027ea51dec290823f9e0bb.tar.xz hyperkitty-fbfe8fc7ea6ba91661027ea51dec290823f9e0bb.zip |
Improve styling in headers and thread view
Diffstat (limited to 'hyperkitty/templatetags')
-rw-r--r-- | hyperkitty/templatetags/hk_generic.py (renamed from hyperkitty/templatetags/poll_extras.py) | 55 | ||||
-rw-r--r-- | hyperkitty/templatetags/storm.py | 34 |
2 files changed, 46 insertions, 43 deletions
diff --git a/hyperkitty/templatetags/poll_extras.py b/hyperkitty/templatetags/hk_generic.py index 0f243c6..5f30bc2 100644 --- a/hyperkitty/templatetags/poll_extras.py +++ b/hyperkitty/templatetags/hk_generic.py @@ -1,14 +1,17 @@ +import datetime +import re + from django import template -from django.http import HttpRequest from django.utils.datastructures import SortedDict -import re register = template.Library() -@register.filter(name="trimString") + +@register.filter def trimString(str): return re.sub('\s+', ' ', str) + @register.filter(name='sort') def listsort(value): if isinstance(value, dict): @@ -30,13 +33,13 @@ def listsort(value): return value listsort.is_safe = True -@register.filter(name="tomonth") -def to_month(value): - months = ('January', 'February', 'March', 'April', 'May', 'June', - 'July', 'August', 'September', 'October', 'November', 'December') - return months[value -1] -@register.filter(name="strip_page") +@register.filter(name="monthtodate") +def to_date(month, year): + return datetime.date(year, month, 1) + + +@register.filter def strip_page(value): print repr(value), repr(value)[-2] if not value: @@ -53,3 +56,37 @@ def strip_page(value): else: output = value.rsplit('/', 1) return output[0] + + +# From http://djangosnippets.org/snippets/1259/ +@register.filter +def truncatesmart(value, limit=80): + """ + Truncates a string after a given number of chars keeping whole words. + + Usage: + {{ string|truncatesmart }} + {{ string|truncatesmart:50 }} + """ + try: + limit = int(limit) + # invalid literal for int() + except ValueError: + # Fail silently. + return value + + # Make sure it's unicode + value = unicode(value) + + # Return the string itself if length is smaller or equal to the limit + if len(value) <= limit: + return value + + # Cut the string + value = value[:limit] + + # Break into words and remove the last + words = value.split(' ')[:-1] + + # Join the words and return + return ' '.join(words) + '...' diff --git a/hyperkitty/templatetags/storm.py b/hyperkitty/templatetags/storm.py index e0443ad..a116430 100644 --- a/hyperkitty/templatetags/storm.py +++ b/hyperkitty/templatetags/storm.py @@ -11,37 +11,3 @@ def count(expr): @register.filter(name="strip_subject") def count(subject, mlist): return stripped_subject(mlist, subject) - - -# From http://djangosnippets.org/snippets/1259/ -@register.filter -def truncatesmart(value, limit=80): - """ - Truncates a string after a given number of chars keeping whole words. - - Usage: - {{ string|truncatesmart }} - {{ string|truncatesmart:50 }} - """ - try: - limit = int(limit) - # invalid literal for int() - except ValueError: - # Fail silently. - return value - - # Make sure it's unicode - value = unicode(value) - - # Return the string itself if length is smaller or equal to the limit - if len(value) <= limit: - return value - - # Cut the string - value = value[:limit] - - # Break into words and remove the last - words = value.split(' ')[:-1] - - # Join the words and return - return ' '.join(words) + '...' |