summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAurélien Bompard <aurelien@bompard.org>2013-07-15 11:39:45 +0200
committerAurélien Bompard <aurelien@bompard.org>2013-07-15 11:39:45 +0200
commit1a339ac1f7dac6e63b83864b6421aed1b0fdde75 (patch)
tree36e547489dee3ba3e192dd5c3254dab3bec03e9d
parent6c60d43903503d01173098c456211e79a318221e (diff)
downloadhyperkitty-1a339ac1f7dac6e63b83864b6421aed1b0fdde75.tar.gz
hyperkitty-1a339ac1f7dac6e63b83864b6421aed1b0fdde75.tar.xz
hyperkitty-1a339ac1f7dac6e63b83864b6421aed1b0fdde75.zip
Show the unread icon in the overview page
-rw-r--r--hyperkitty/lib/__init__.py22
-rw-r--r--hyperkitty/static/hyperkitty/css/hyperkitty-common.css3
-rw-r--r--hyperkitty/static/hyperkitty/css/hyperkitty-threadslist.css4
-rw-r--r--hyperkitty/templates/threads/summary_thread.html6
-rw-r--r--hyperkitty/templates/threads/summary_thread_large.html2
-rw-r--r--hyperkitty/tests/test_views.py8
-rw-r--r--hyperkitty/views/list.py20
-rw-r--r--hyperkitty/views/message.py16
8 files changed, 44 insertions, 37 deletions
diff --git a/hyperkitty/lib/__init__.py b/hyperkitty/lib/__init__.py
index a25dcd7..9bcded3 100644
--- a/hyperkitty/lib/__init__.py
+++ b/hyperkitty/lib/__init__.py
@@ -26,10 +26,11 @@ import datetime
from django.core.exceptions import SuspiciousOperation
from django.core.mail import EmailMessage
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
+from django.utils.timezone import utc
from mailmanclient import MailmanConnectionError
from hyperkitty.lib import mailman
-from hyperkitty.models import ThreadCategory
+from hyperkitty.models import ThreadCategory, LastView
from hyperkitty.views.forms import CategoryForm
@@ -214,3 +215,22 @@ def get_category_widget(request=None, current_category=None):
except ThreadCategory.DoesNotExist:
category = None
return category, category_form
+
+
+def is_thread_unread(request, mlist_name, thread):
+ """Returns True or False if the thread is unread or not."""
+ unread = False
+ if request.user.is_authenticated():
+ try:
+ last_view_obj = LastView.objects.get(
+ list_address=mlist_name,
+ threadid=thread.thread_id,
+ user=request.user)
+ except LastView.DoesNotExist:
+ unread = True
+ else:
+ if thread.date_active.replace(tzinfo=utc) \
+ > last_view_obj.view_date:
+ unread = True
+ return unread
+
diff --git a/hyperkitty/static/hyperkitty/css/hyperkitty-common.css b/hyperkitty/static/hyperkitty/css/hyperkitty-common.css
index a6f47ca..91c4556 100644
--- a/hyperkitty/static/hyperkitty/css/hyperkitty-common.css
+++ b/hyperkitty/static/hyperkitty/css/hyperkitty-common.css
@@ -92,6 +92,9 @@ form .buttons .submit {
background-image: url("../img/discussion.png");
margin-right: 2em;
}
+i.unread {
+ vertical-align: baseline;
+}
/*
diff --git a/hyperkitty/static/hyperkitty/css/hyperkitty-threadslist.css b/hyperkitty/static/hyperkitty/css/hyperkitty-threadslist.css
index 7331f90..73f4864 100644
--- a/hyperkitty/static/hyperkitty/css/hyperkitty-threadslist.css
+++ b/hyperkitty/static/hyperkitty/css/hyperkitty-threadslist.css
@@ -91,10 +91,6 @@
margin-left: 2em;
}
-.thread.unread i.unread {
- vertical-align: baseline;
-}
-
.thread-content {
margin-top: 0.5em;
}
diff --git a/hyperkitty/templates/threads/summary_thread.html b/hyperkitty/templates/threads/summary_thread.html
index 82c9398..2176936 100644
--- a/hyperkitty/templates/threads/summary_thread.html
+++ b/hyperkitty/templates/threads/summary_thread.html
@@ -6,7 +6,11 @@
{% if counter %}<span class="thread-id">#{{counter}}</span>{% endif %}
<span class="thread-title"><a name="{{thread.thread_id}}"
href="{% url 'thread' threadid=thread.thread_id mlist_fqdn=mlist.name %}"
- >{{ thread.subject|strip_subject:mlist }}</a></span>
+ >{{ thread.subject|strip_subject:mlist }}</a>
+ {% if thread.unread %}
+ <i class="unread icon-eye-close" title="New messages in this thread"></i>
+ {% endif %}
+ </span>
<div class="thread-stats">
<ul class="inline-block">
{% if thread.category %}
diff --git a/hyperkitty/templates/threads/summary_thread_large.html b/hyperkitty/templates/threads/summary_thread_large.html
index 05a7e99..450278b 100644
--- a/hyperkitty/templates/threads/summary_thread_large.html
+++ b/hyperkitty/templates/threads/summary_thread_large.html
@@ -7,7 +7,7 @@
<div class="{% if thread.favorite %}saved{% else %}notsaved{% endif %}">
<span class="thread-title">
{% if thread.unread %}
- <i class="unread icon-eye-close" title="Unread"></i>
+ <i class="unread icon-eye-close" title="New messages in this thread"></i>
{% endif %}
<a name="{{thread.thread_id}}"
href="{% url 'thread' threadid=thread.thread_id mlist_fqdn=mlist.name %}"
diff --git a/hyperkitty/tests/test_views.py b/hyperkitty/tests/test_views.py
index b1ad38a..fb7945d 100644
--- a/hyperkitty/tests/test_views.py
+++ b/hyperkitty/tests/test_views.py
@@ -146,6 +146,14 @@ class LastViewsTestCase(TestCase):
self.assertContains(response, "icon-eye-close",
count=2, status_code=200)
+ def test_overview(self):
+ now = datetime.datetime.now()
+ request = self.factory.get(reverse('list_overview', args=["list@example.com"]))
+ 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/list.py b/hyperkitty/views/list.py
index a61f0a9..4857c27 100644
--- a/hyperkitty/views/list.py
+++ b/hyperkitty/views/list.py
@@ -31,9 +31,10 @@ 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
+from hyperkitty.models import Tag, Favorite
from hyperkitty.lib import get_months, get_store, get_display_dates, daterange
from hyperkitty.lib import FLASH_MESSAGES, paginate, get_category_widget
+from hyperkitty.lib import is_thread_unread
from hyperkitty.lib.voting import get_votes, set_message_votes, set_thread_votes
@@ -43,7 +44,7 @@ if settings.USE_MOCKUPS:
Thread = namedtuple('Thread', [
"thread_id", "subject", "participants", "length", "date_active",
- "likes", "dislikes", "likestatus", "category",
+ "likes", "dislikes", "likestatus", "category", "unread",
])
@@ -112,19 +113,7 @@ def _thread_list(request, mlist, threads, template_name='thread_list.html', extr
get_category_widget(request, thread.category)
# Unread status
- thread.unread = False
- if request.user.is_authenticated():
- try:
- last_view_obj = LastView.objects.get(
- list_address=mlist.name,
- threadid=thread.thread_id,
- user=request.user)
- except LastView.DoesNotExist:
- thread.unread = True
- else:
- if thread.date_active.replace(tzinfo=utc) \
- > last_view_obj.view_date:
- thread.unread = True
+ thread.unread = is_thread_unread(request, mlist.name, thread)
threads = paginate(threads, request.GET.get('page'))
@@ -175,6 +164,7 @@ def overview(request, mlist_fqdn=None):
thread_obj.likes, thread_obj.dislikes,
thread_obj.likestatus,
get_category_widget(None, thread_obj.category)[0],
+ is_thread_unread(request, mlist.name, thread_obj),
)
# Statistics on how many participants and threads this month
participants.update(thread.participants)
diff --git a/hyperkitty/views/message.py b/hyperkitty/views/message.py
index 4266877..66cc314 100644
--- a/hyperkitty/views/message.py
+++ b/hyperkitty/views/message.py
@@ -33,7 +33,7 @@ from django.contrib.auth.decorators import login_required
from hyperkitty.lib import get_store, get_months, post_to_list, PostingFailed
from hyperkitty.lib.voting import set_message_votes
-from hyperkitty.models import Rating, LastView
+from hyperkitty.models import Rating
from forms import ReplyForm, PostForm
@@ -50,26 +50,12 @@ def index(request, mlist_fqdn, message_id_hash):
set_message_votes(message, request.user)
mlist = store.get_list(mlist_fqdn)
- # Last thread view
- last_view = None
- if request.user.is_authenticated():
- try:
- last_view_obj = LastView.objects.get(
- list_address=mlist.name,
- threadid=message.thread_id,
- user=request.user)
- except LastView.DoesNotExist:
- pass
- else:
- last_view = last_view_obj.view_date
-
context = {
'mlist' : mlist,
'message': message,
'message_id_hash' : message_id_hash,
'months_list': get_months(store, mlist.name),
'reply_form': ReplyForm(),
- 'last_view': last_view,
}
return render(request, "message.html", context)