comparison 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
comparison
equal deleted inserted replaced
381:6df1091b11b2 382:a1b03de20345
738 context_instance=RequestContext(request)) 738 context_instance=RequestContext(request))
739 739
740 740
741 @login_required 741 @login_required
742 @require_POST 742 @require_POST
743 def catchup_all(request):
744 """
745 This view marks all forums as being read.
746 """
747 forums = Forum.objects.forums_for_user(request.user)
748 forum_dict = dict((forum.id, forum) for forum in forums)
749 forum_ids = forum_dict.keys()
750
751 tlvs = TopicLastVisit.objects.filter(user=request.user,
752 topic__forum__id__in=forum_ids).delete()
753
754 flvs = ForumLastVisit.objects.filter(user=request.user,
755 forum__id__in=forum_ids).select_related('forum')
756
757 flv_dict = dict((flv.forum.id, flv) for flv in flvs)
758
759 now = datetime.datetime.now()
760 for forum in forums:
761 flv = flv_dict.get(forum.id)
762 if flv is None:
763 flv = ForumLastVisit(user=request.user, forum=forum)
764
765 flv.begin_date = now
766 flv.end_date = now
767 flv.save()
768
769 return HttpResponseRedirect(reverse('forums-index'))
770
771
772 @login_required
773 @require_POST
743 def forum_catchup(request, slug): 774 def forum_catchup(request, slug):
744 """ 775 """
745 This view marks all the topics in the forum as being read. 776 This view marks all the topics in the forum as being read.
746 """ 777 """
747 forum = get_object_or_404(Forum.objects.select_related(), slug=slug) 778 forum = get_object_or_404(Forum.objects.select_related(), slug=slug)