# HG changeset patch # User Brian Neal # Date 1299638364 0 # Node ID a1b03de20345cc0c80c6e832bc4a763f8bf8d693 # Parent 6df1091b11b221338ffb25598f7fae78ec2405dc Fixing #185; add a global forums catchup button. diff -r 6df1091b11b2 -r a1b03de20345 gpp/forums/urls.py --- 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\d+)$', 'new_topic_thanks', name='forums-new_topic_thanks'), url(r'^topic/(?P\d+)/$', 'topic_index', name='forums-topic_index'), url(r'^topic/(?P\d+)/unread/$', 'topic_unread', name='forums-topic_unread'), diff -r 6df1091b11b2 -r a1b03de20345 gpp/forums/views/main.py --- 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. diff -r 6df1091b11b2 -r a1b03de20345 gpp/templates/forums/index.html --- 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 @@ {% endfor %} +
{% csrf_token %} + +
+
{% cache 900 forum-stats-block %} {% forum_stats %} {% endcache %}