Mercurial > public > sg101
diff gpp/forums/views/main.py @ 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 | 6f963e5e7b03 |
children | 957955279a15 |
line wrap: on
line diff
--- 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.