diff options
-rw-r--r-- | hyperkitty/static/css/thread.css | 21 | ||||
-rw-r--r-- | hyperkitty/templates/thread.html | 8 | ||||
-rw-r--r-- | hyperkitty/templatetags/storm.py | 34 | ||||
-rw-r--r-- | hyperkitty/views/thread.py | 12 |
4 files changed, 64 insertions, 11 deletions
diff --git a/hyperkitty/static/css/thread.css b/hyperkitty/static/css/thread.css index 90d2add..e600074 100644 --- a/hyperkitty/static/css/thread.css +++ b/hyperkitty/static/css/thread.css @@ -2,7 +2,7 @@ header { /*background-color: #f6f6f6;*/ /*border-bottom: 1px solid #b3b3b3;*/ - margin-bottom: 3em; + margin-bottom: 5em; padding: 1em 0; } @@ -12,6 +12,25 @@ h1 { line-height: 26px; } +header .thread-older, +header .thread-newer { + display: block; + padding-top: 38px; + width: 160px; + overflow: hidden; + background-repeat: no-repeat; + background-position: top center; + text-align: center; + color: #aaaaaa; +} +header .thread-older { + float: right; + background-image: url('../img/button_older.png'); +} +header .thread-newer { + float: left; + background-image: url('../img/button_newer.png'); +} #thread_nav{ margin:auto; diff --git a/hyperkitty/templates/thread.html b/hyperkitty/templates/thread.html index 78b4891..20181b8 100644 --- a/hyperkitty/templates/thread.html +++ b/hyperkitty/templates/thread.html @@ -1,6 +1,7 @@ {% extends "base.html" %} {% load gravatar %} +{% load storm %} {% block additional_stylesheets %} <link rel="stylesheet" type="text/css" media="all" href="{{ STATIC_URL }}css/thread.css" /> @@ -9,6 +10,13 @@ {% block content %} <header> + {% for thread in neighbors %} + {% if thread %} + <a class="thread-{% ifequal forloop.counter 1 %}older{% else %}newer{% endifequal %}" + href="{% url thread threadid=thread.thread_id, mlist_fqdn=list_address %}" + >{{ thread.subject|strip_subject:mlist|truncatesmart:"25" }}</a> + {% endif %} + {% endfor %} <h1>{{ subject }}</h1> </header> diff --git a/hyperkitty/templatetags/storm.py b/hyperkitty/templatetags/storm.py index a116430..e0443ad 100644 --- a/hyperkitty/templatetags/storm.py +++ b/hyperkitty/templatetags/storm.py @@ -11,3 +11,37 @@ 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) + '...' diff --git a/hyperkitty/views/thread.py b/hyperkitty/views/thread.py index 397a158..558e51d 100644 --- a/hyperkitty/views/thread.py +++ b/hyperkitty/views/thread.py @@ -43,12 +43,7 @@ def thread_index (request, mlist_fqdn, threadid): messages = store.get_messages_in_thread(mlist_fqdn, threadid) if not messages: raise Http404 - prev_thread = [] - if len(prev_thread) > 30: - prev_thread = '%s...' % prev_thread[:31] - next_thread = [] - if len(next_thread) > 30: - next_thread = '%s...' % next_thread[:31] + prev_thread, next_thread = store.get_thread_neighbors(mlist_fqdn, threadid) participants = {} cnt = 0 @@ -112,10 +107,7 @@ def thread_index (request, mlist_fqdn, threadid): 'answers': cnt, 'first_mail': messages[0], 'replies': messages[1:], - 'next_thread': next_thread, - 'next_thread_id': 0, - 'prev_thread': prev_thread, - 'prev_thread_id': 0, + 'neighbors': (prev_thread, next_thread), 'archives_length': archives_length, 'days_inactive': days_inactive.days, 'days_old': days_old.days, |