diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2013-05-23 15:45:22 +0200 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2013-05-23 17:48:16 +0200 |
commit | ea032ba8b321fad5e896750eae508456676041c1 (patch) | |
tree | 026c8af089391ecddd9dcae5a05d5ee9e07ad3a0 | |
parent | e9e92bf1ac15421b9a29c366b9ef6bf2c1b94943 (diff) | |
download | hyperkitty-ea032ba8b321fad5e896750eae508456676041c1.tar.gz hyperkitty-ea032ba8b321fad5e896750eae508456676041c1.tar.xz hyperkitty-ea032ba8b321fad5e896750eae508456676041c1.zip |
Display the last viewed threads in the user profile
-rw-r--r-- | hyperkitty/static/css/hyperkitty-user.css | 7 | ||||
-rw-r--r-- | hyperkitty/static/js/hyperkitty.js | 29 | ||||
-rw-r--r-- | hyperkitty/templates/ajax/last_views.html | 40 | ||||
-rw-r--r-- | hyperkitty/templates/paginator.html | 4 | ||||
-rw-r--r-- | hyperkitty/templates/user_profile.html | 16 | ||||
-rw-r--r-- | hyperkitty/templatetags/hk_generic.py | 2 | ||||
-rw-r--r-- | hyperkitty/urls.py | 1 | ||||
-rw-r--r-- | hyperkitty/views/accounts.py | 32 |
8 files changed, 127 insertions, 4 deletions
diff --git a/hyperkitty/static/css/hyperkitty-user.css b/hyperkitty/static/css/hyperkitty-user.css index 49edfa6..77d9ad4 100644 --- a/hyperkitty/static/css/hyperkitty-user.css +++ b/hyperkitty/static/css/hyperkitty-user.css @@ -84,3 +84,10 @@ table.user-data label, table.user-data input { margin-bottom: 0; } + + +.ajaxloader { + margin-top: 0; + margin-left: 0; + position: absolute; +} diff --git a/hyperkitty/static/js/hyperkitty.js b/hyperkitty/static/js/hyperkitty.js index fc8e461..5fcb539 100644 --- a/hyperkitty/static/js/hyperkitty.js +++ b/hyperkitty/static/js/hyperkitty.js @@ -420,6 +420,35 @@ function update_list_properties(url) { /* + * Last viewed threads in the user's profile + */ +function update_last_views(base_url) { + var container = $(".views"); + var loader = container.prev(".ajaxloader"); + function _update(url) { + loader.show(); + $.ajax({ + url: url, + success: function(data) { + container.html(data); + container.find(".pager a").click(function(e) { + e.preventDefault(); + _update(base_url + $(this).attr("href")); + }); + }, + error: function(jqXHR, textStatus, errorThrown) { + //alert(jqXHR.responseText); + }, + complete: function(jqXHR, textStatus) { + loader.hide(); + } + }); + } + _update(base_url); +} + + +/* * Misc. */ diff --git a/hyperkitty/templates/ajax/last_views.html b/hyperkitty/templates/ajax/last_views.html new file mode 100644 index 0000000..5455413 --- /dev/null +++ b/hyperkitty/templates/ajax/last_views.html @@ -0,0 +1,40 @@ +{% load url from future %} +{% load i18n %} +{% load hk_generic %} + + {% if last_views %} + <table class="table table-striped table-bordered table-condensed"> + <thead> + <tr> + <th></th> + <th>Subject</th> + <th>Original author</th> + <th>Start date</th> + <th>Last activity</th> + <th>Replies</th> + </tr> + </thead> + <tbody> + {% for lv in last_views %} + <tr> + <td> + {% if thread.unread %} + <i class="unread icon-eye-close" title="New comments"></i> + {% endif %} + </td> + <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|length }}</td> + </tr> + {% endfor %} + </tbody> + </table> + {% include "paginator.html" with pager=last_views page_key="lvpage" %} + {% else %} + <p>Nothing read yet.</p> + {% endif %} + +{# vim: set noet: #} diff --git a/hyperkitty/templates/paginator.html b/hyperkitty/templates/paginator.html index a7559ec..358ae5d 100644 --- a/hyperkitty/templates/paginator.html +++ b/hyperkitty/templates/paginator.html @@ -2,7 +2,7 @@ <ul class="pager"> {% if pager.has_previous %} <li> - <a href="?page={{ pager.previous_page_number }}"> + <a href="?{{ page_key|default:'page' }}={{ pager.previous_page_number }}"> {% else %} <li class="disabled"> <a href="#"> @@ -12,7 +12,7 @@ {% if pager.has_next %} <li> - <a href="?page={{ pager.next_page_number }}"> + <a href="?{{ page_key|default:'page' }}={{ pager.next_page_number }}"> {% else %} <li class="disabled"> <a href="#"> diff --git a/hyperkitty/templates/user_profile.html b/hyperkitty/templates/user_profile.html index f6a4d16..e84c72f 100644 --- a/hyperkitty/templates/user_profile.html +++ b/hyperkitty/templates/user_profile.html @@ -69,6 +69,11 @@ {% endif %} + <h3>Threads you have read</h3> + <img alt="Loading..." class="ajaxloader" src="{{ STATIC_URL }}img/ajax-loader.gif" /> + <div class="views"></div> + + <h3>Votes</h3> <h4>Up Votes</h4> {% if votes_up %} @@ -112,4 +117,15 @@ {% endblock %} +{% block additionaljs %} + +<script type="text/javascript"> + $(document).ready(function() { + // Load the last views + update_last_views("{% url 'user_last_views' %}"); + }); +</script> + +{% endblock %} + {# vim: set noet: #} diff --git a/hyperkitty/templatetags/hk_generic.py b/hyperkitty/templatetags/hk_generic.py index 8442f63..f117b60 100644 --- a/hyperkitty/templatetags/hk_generic.py +++ b/hyperkitty/templatetags/hk_generic.py @@ -189,6 +189,6 @@ def is_message_new(context, refdate): user = context["user"] last_view = context.get("last_view") return (user.is_authenticated() and - (last_view is None or refdate > last_view) + (not last_view or refdate > last_view) ) register.assignment_tag(takes_context=True)(is_message_new) diff --git a/hyperkitty/urls.py b/hyperkitty/urls.py index 6a332c3..8956c6e 100644 --- a/hyperkitty/urls.py +++ b/hyperkitty/urls.py @@ -45,6 +45,7 @@ urlpatterns = patterns('hyperkitty.views', url(r'^accounts/login/$', 'accounts.login_view', {'template_name': 'login.html', 'SSL': True}, name='user_login'), url(r'^accounts/logout/$', logout_view, {'next_page': '/'}, name='user_logout'), url(r'^accounts/profile/$', 'accounts.user_profile', name='user_profile'), + url(r'^accounts/profile/last_views$', 'accounts.last_views', name='user_last_views'), url(r'^accounts/register/$', 'accounts.user_registration', {'SSL': True}, name='user_registration'), diff --git a/hyperkitty/views/accounts.py b/hyperkitty/views/accounts.py index cd64cde..b283392 100644 --- a/hyperkitty/views/accounts.py +++ b/hyperkitty/views/accounts.py @@ -24,6 +24,7 @@ import logging from django.conf import settings from django.core.urlresolvers import reverse from django.core.exceptions import SuspiciousOperation +from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.contrib.auth import authenticate, login, get_backends from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User @@ -31,9 +32,10 @@ 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.translation import gettext as _ +from django.template import RequestContext, loader from social_auth.backends import SocialAuthBackend -from hyperkitty.models import UserProfile, Rating, Favorite +from hyperkitty.models import UserProfile, Rating, Favorite, LastView from hyperkitty.views.forms import RegistrationForm, UserProfileForm from hyperkitty.lib import get_store, FLASH_MESSAGES @@ -112,6 +114,7 @@ def user_profile(request, user_email=None): thread = store.get_thread(fav.list_address, fav.threadid) fav.thread = thread + # Flash messages flash_messages = [] flash_msg = request.GET.get("msg") if flash_msg: @@ -166,3 +169,30 @@ def user_registration(request): 'next': redirect_to, } return render(request, 'register.html', context) + + +@login_required +def last_views(request): + store = get_store(request) + # Last viewed threads + try: + last_views = LastView.objects.filter(user=request.user + ).order_by("view_date") + except Favorite.DoesNotExist: + last_views = [] + last_views_paginator = Paginator(last_views, 10) + last_views_page = request.GET.get('lvpage') + try: + last_views = last_views_paginator.page(last_views_page) + except PageNotAnInteger: + last_views = last_views_paginator.page(1) + except EmptyPage: + 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) + thread.unread = bool( thread.date_active > last_view.view_date ) + last_view.thread = thread + + return render(request, 'ajax/last_views.html', { + "last_views": last_views, + }) |