Mercurial > public > sg101
changeset 382:a1b03de20345
Fixing #185; add a global forums catchup button.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 09 Mar 2011 02:39:24 +0000 |
parents | 6df1091b11b2 |
children | b2b37cdd020a |
files | gpp/forums/urls.py gpp/forums/views/main.py gpp/templates/forums/index.html |
diffstat | 3 files changed, 37 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/gpp/forums/urls.py Wed Mar 09 01:50:13 2011 +0000 +++ b/gpp/forums/urls.py Wed Mar 09 02:39:24 2011 +0000 @@ -5,6 +5,7 @@ urlpatterns = patterns('forums.views.main', url(r'^$', 'index', name='forums-index'), + url(r'^catchup/$', 'catchup_all', name='forums-catchup_all'), url(r'^new-topic-success/(?P<tid>\d+)$', 'new_topic_thanks', name='forums-new_topic_thanks'), url(r'^topic/(?P<id>\d+)/$', 'topic_index', name='forums-topic_index'), url(r'^topic/(?P<id>\d+)/unread/$', 'topic_unread', name='forums-topic_unread'),
--- a/gpp/forums/views/main.py Wed Mar 09 01:50:13 2011 +0000 +++ b/gpp/forums/views/main.py Wed Mar 09 02:39:24 2011 +0000 @@ -740,6 +740,37 @@ @login_required @require_POST +def catchup_all(request): + """ + This view marks all forums as being read. + """ + forums = Forum.objects.forums_for_user(request.user) + forum_dict = dict((forum.id, forum) for forum in forums) + forum_ids = forum_dict.keys() + + tlvs = TopicLastVisit.objects.filter(user=request.user, + topic__forum__id__in=forum_ids).delete() + + flvs = ForumLastVisit.objects.filter(user=request.user, + forum__id__in=forum_ids).select_related('forum') + + flv_dict = dict((flv.forum.id, flv) for flv in flvs) + + now = datetime.datetime.now() + for forum in forums: + flv = flv_dict.get(forum.id) + if flv is None: + flv = ForumLastVisit(user=request.user, forum=forum) + + flv.begin_date = now + flv.end_date = now + flv.save() + + return HttpResponseRedirect(reverse('forums-index')) + + +@login_required +@require_POST def forum_catchup(request, slug): """ This view marks all the topics in the forum as being read.
--- a/gpp/templates/forums/index.html Wed Mar 09 01:50:13 2011 +0000 +++ b/gpp/templates/forums/index.html Wed Mar 09 02:39:24 2011 +0000 @@ -1,4 +1,5 @@ {% extends 'base.html' %} +{% load url from future %} {% load cache %} {% load forum_tags %} {% load core_tags %} @@ -44,6 +45,10 @@ </tbody> </table> {% endfor %} +<form action="{% url 'forums-catchup_all' %}" method="post">{% csrf_token %} + <input type="submit" value="Mark All Forums Read" /> +</form> +<br /> {% cache 900 forum-stats-block %} {% forum_stats %} {% endcache %}