summaryrefslogtreecommitdiffstats
path: root/hyperkitty
diff options
context:
space:
mode:
Diffstat (limited to 'hyperkitty')
-rw-r--r--hyperkitty/templates/ajax/last_views.html4
-rw-r--r--hyperkitty/templates/messages/message.html7
-rw-r--r--hyperkitty/templates/threads/summary_thread_large.html2
-rw-r--r--hyperkitty/templates/user_profile.html6
-rw-r--r--hyperkitty/templatetags/hk_generic.py22
-rw-r--r--hyperkitty/tests/test_views.py9
-rw-r--r--hyperkitty/views/accounts.py3
-rw-r--r--hyperkitty/views/list.py6
-rw-r--r--hyperkitty/views/thread.py3
9 files changed, 38 insertions, 24 deletions
diff --git a/hyperkitty/templates/ajax/last_views.html b/hyperkitty/templates/ajax/last_views.html
index 25fe995..aeea651 100644
--- a/hyperkitty/templates/ajax/last_views.html
+++ b/hyperkitty/templates/ajax/last_views.html
@@ -25,8 +25,8 @@
<td><a href="{% url 'thread' mlist_fqdn=lv.list_address threadid=lv.threadid %}"
>{{ lv.thread.starting_email.subject }}</a></td>
<td>{{ lv.thread.starting_email.sender_name }}</td>
- <td>{{ lv.thread.starting_email|viewer_date|date:"l, j F Y H:i:s" }}</td>
- <td>{{ lv.thread|viewer_date|timesince }}</td>
+ <td>{{ lv.thread.starting_email|get_date|date:"l, j F Y H:i:s" }}</td>
+ <td>{{ lv.thread|get_date|timesince }}</td>
<td>
{{ lv.thread|length }}
{% if thread.unread %}
diff --git a/hyperkitty/templates/messages/message.html b/hyperkitty/templates/messages/message.html
index 6a42066..0676dd8 100644
--- a/hyperkitty/templates/messages/message.html
+++ b/hyperkitty/templates/messages/message.html
@@ -2,6 +2,7 @@
{% load storm %}
{% load gravatar %}
{% load hk_generic %}
+{% load tz %}
{% is_message_new email.date as is_new %}
<div class="email{% if unfolded %} email-first{% endif %}{% if is_new %} unread{% endif %}">
@@ -10,14 +11,14 @@
<div class="email-date inline-block pull-right">
{% ifchanged %}
<span class="date">
- {{email|viewer_date|date:"l, j F"}}
+ {{email|get_date|date:"l, j F"}}
{% if unfolded %}
- {{email|viewer_date|date:"Y"}}
+ {{email|get_date|date:"Y"}}
{% endif %}
</span>
{% endifchanged %}
{% if unfolded %}<br />{% endif %}
- <span class="time" title="Sender's time: {{email|sender_date|date:"l, j F H:i:s"}}">{{email|viewer_date|date:"H:i:s"}}</span>
+ <span class="time" title="Sender's time: {% localtime off %}{{email|get_date|date:"l, j F H:i:s e"}}{% endlocaltime %}">{{email|get_date|date:"H:i:s"}}</span>
</div>
{% if is_new %}
<i class="unread icon-eye-close" title="Unread"></i>
diff --git a/hyperkitty/templates/threads/summary_thread_large.html b/hyperkitty/templates/threads/summary_thread_large.html
index cea2be2..70dcd7f 100644
--- a/hyperkitty/templates/threads/summary_thread_large.html
+++ b/hyperkitty/templates/threads/summary_thread_large.html
@@ -12,7 +12,7 @@
<a name="{{thread.thread_id}}"
href="{% url 'thread' threadid=thread.thread_id mlist_fqdn=mlist.name %}"
>{{ thread.starting_email.subject|strip_subject:mlist }}</a></span>
- <span class="thread-date">{{thread.date_active|timesince }}</span>
+ <span class="thread-date">{{ thread|get_date|timesince }}</span>
</div>
<div class="thread-content">
{% if thread.category_tag %}
diff --git a/hyperkitty/templates/user_profile.html b/hyperkitty/templates/user_profile.html
index e84c72f..69c2ad7 100644
--- a/hyperkitty/templates/user_profile.html
+++ b/hyperkitty/templates/user_profile.html
@@ -60,7 +60,7 @@
<li>
<a href="{% url 'thread' mlist_fqdn=fav.list_address threadid=fav.threadid %}"
>{{ fav.thread.starting_email.subject }}</a> by {{ fav.thread.starting_email.sender_name }}
- ({{ fav.thread|viewer_date|date:"l, j F Y H:i:s" }})
+ ({{ fav.thread|get_date|date:"l, j F Y H:i:s" }})
</li>
{% endfor %}
</ul>
@@ -83,7 +83,7 @@
{% if vote.message.content|trimString|length > 0 %}
<a href="{% url 'message_index' mlist_fqdn=vote.list_address message_id_hash=vote.messageid %}"
>{{ vote.message.subject }}</a> by {{ vote.message.sender_name }}
- ({{ vote.message|viewer_date|date:"l, j F Y H:i:s" }})
+ ({{ vote.message|get_date|date:"l, j F Y H:i:s" }})
{% else %}
<a href="{% url 'message_index' mlist_fqdn=vote.list_address message_id_hash=vote.messageid %}">Message is empty</a>
{% endif %}
@@ -102,7 +102,7 @@
{% if vote.message.content|trimString|length > 0 %}
<a href="{% url 'message_index' mlist_fqdn=vote.list_address message_id_hash=vote.messageid %}"
>{{ vote.message.subject }}</a> by {{ vote.message.sender_name }}
- ({{ vote.message|viewer_date|date:"l, j F Y H:i:s" }})
+ ({{ vote.message|get_date|date:"l, j F Y H:i:s" }})
{% else %}
<a href="{% url 'message_index' mlist_fqdn=vote.list_address message_id_hash=vote.messageid %}">Message is empty</a>
{% endif %}
diff --git a/hyperkitty/templatetags/hk_generic.py b/hyperkitty/templatetags/hk_generic.py
index 07c1a77..d5512e9 100644
--- a/hyperkitty/templatetags/hk_generic.py
+++ b/hyperkitty/templatetags/hk_generic.py
@@ -22,12 +22,13 @@
import datetime
import re
-from dateutil.tz import tzutc, tzoffset
+from dateutil.tz import tzoffset
from django import template
from django.utils.datastructures import SortedDict
from django.templatetags.tz import localtime
from django.utils.html import conditional_escape
from django.utils.safestring import mark_safe
+from django.utils.timezone import utc
register = template.Library()
@@ -127,19 +128,17 @@ def escapeemail(text):
@register.filter()
-def sender_date(email):
- tz = tzoffset(None, email.timezone * 60)
- email_date = email.date.replace(tzinfo=tzutc())
- return email_date.astimezone(tz)
-
-
-@register.filter()
-def viewer_date(email_or_thread):
+def get_date(email_or_thread):
+ """
+ Rebuild the date of an email or a thread taking the timezone into account
+ when applicable.
+ """
if hasattr(email_or_thread, 'date'):
- date_obj = email_or_thread.date
+ tz = tzoffset(None, email_or_thread.timezone * 60)
+ date_obj = email_or_thread.date.replace(tzinfo=tz)
elif hasattr(email_or_thread, 'date_active'):
date_obj = email_or_thread.date_active
- return localtime(date_obj.replace(tzinfo=tzutc()))
+ return date_obj
SNIPPED_RE = re.compile("^(\s*&gt;).*$", re.M)
@@ -188,6 +187,7 @@ def multiply(num1, num2):
def is_message_new(context, refdate):
user = context["user"]
last_view = context.get("last_view")
+ refdate = refdate.replace(tzinfo=utc)
return (user.is_authenticated() and
(not last_view or refdate > last_view)
)
diff --git a/hyperkitty/tests/test_views.py b/hyperkitty/tests/test_views.py
index 9deab94..ec34c08 100644
--- a/hyperkitty/tests/test_views.py
+++ b/hyperkitty/tests/test_views.py
@@ -88,6 +88,7 @@ class AccountViewsTestCase(TestCase):
from hyperkitty.views.accounts import last_views
from hyperkitty.views.thread import thread_index
+from hyperkitty.views.list import archives
@override_settings(DEBUG=True, ASSETS_DEBUG=True)
class LastViewsTestCase(TestCase):
@@ -148,6 +149,14 @@ class LastViewsTestCase(TestCase):
self.assertNotContains(responses[1], "icon-eye-close", status_code=200)
self.assertContains(responses[2], "icon-eye-close", count=1, status_code=200)
+ def test_thread_list(self):
+ now = datetime.datetime.now()
+ request = self.factory.get(reverse('archives_with_month', args=["list@example.com", now.year, now.month]))
+ request.user = self.user
+ response = archives(request, "list@example.com", now.year, now.month)
+ self.assertContains(response, "icon-eye-close",
+ count=2, status_code=200)
+
from hyperkitty.views.message import vote
diff --git a/hyperkitty/views/accounts.py b/hyperkitty/views/accounts.py
index 42edd49..43ee5c6 100644
--- a/hyperkitty/views/accounts.py
+++ b/hyperkitty/views/accounts.py
@@ -31,6 +31,7 @@ from django.contrib.auth.models import User
from django.contrib.auth.views import login as django_login_view
from django.shortcuts import render, redirect
from django.utils.http import is_safe_url
+from django.utils.timezone import utc
#from django.utils.translation import gettext as _
from social_auth.backends import SocialAuthBackend
@@ -189,7 +190,7 @@ def last_views(request):
last_views = last_views_paginator.page(last_views_paginator.num_pages)
for last_view in last_views:
thread = store.get_thread(last_view.list_address, last_view.threadid)
- if thread.date_active > last_view.view_date:
+ if thread.date_active.replace(tzinfo=utc) > last_view.view_date:
# small optimization: only query the replies if necessary
# XXX: Storm-specific (count method)
thread.unread = thread.replies_after(last_view.view_date).count()
diff --git a/hyperkitty/views/list.py b/hyperkitty/views/list.py
index f4f75dd..8bb832e 100644
--- a/hyperkitty/views/list.py
+++ b/hyperkitty/views/list.py
@@ -29,6 +29,7 @@ from django.core.urlresolvers import reverse
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.utils import formats
from django.utils.dateformat import format as date_format
+from django.utils.timezone import utc
from django.http import Http404
from hyperkitty.models import Tag, Favorite, LastView
@@ -139,7 +140,8 @@ def _thread_list(request, mlist, threads, template_name='thread_list.html', extr
except LastView.DoesNotExist:
thread.unread = True
else:
- if thread.date_active > last_view_obj.view_date:
+ if thread.date_active.replace(tzinfo=utc) \
+ > last_view_obj.view_date:
thread.unread = True
paginator = Paginator(threads, 10)
@@ -196,7 +198,7 @@ def overview(request, mlist_fqdn=None):
for thread_obj in threads_result:
thread = Thread(thread_obj.thread_id, thread_obj.subject,
thread_obj.participants, len(thread_obj),
- thread_obj.date_active)
+ thread_obj.date_active.replace(tzinfo=utc))
# Statistics on how many participants and threads this month
participants.update(thread.participants)
threads.append(thread)
diff --git a/hyperkitty/views/thread.py b/hyperkitty/views/thread.py
index 34fc5d9..03cfd6a 100644
--- a/hyperkitty/views/thread.py
+++ b/hyperkitty/views/thread.py
@@ -30,6 +30,7 @@ from django.template import RequestContext, loader
from django.shortcuts import render
from django.core.urlresolvers import reverse
from django.core.exceptions import SuspiciousOperation
+from django.utils.timezone import utc
import robot_detection
from hyperkitty.models import Tag, Favorite, LastView
@@ -166,7 +167,7 @@ def replies(request, mlist_fqdn, threadid):
last_view = request.GET.get("last_view")
if last_view:
try:
- last_view = datetime.datetime.fromtimestamp(int(last_view))
+ last_view = datetime.datetime.fromtimestamp(int(last_view), utc)
except ValueError:
last_view = None
context = {