Better notice contribution handling
authorveltr
Wed, 09 Oct 2013 11:53:16 +0200
changeset 142 8edfc641a25c
parent 141 93500ff3b697
child 143 dfb76c5aa3ff
Better notice contribution handling
src/jocondelab/views/front_office.py
--- a/src/jocondelab/views/front_office.py	Tue Oct 08 16:35:44 2013 +0200
+++ b/src/jocondelab/views/front_office.py	Wed Oct 09 11:53:16 2013 +0200
@@ -182,16 +182,20 @@
                 context['next_notice'] = notice_history[p + 1]
             if p > 0:
                 context['prev_notice'] = notice_history[p - 1]
+        context['done_notices'] = len(notice_history)
         
         return context
 
 def describe_view(request):
     notice_history = request.session.get('notice_history',[])
-    queryset = Notice.objects.filter(image=True, repr='', peri__contains='4e quart 19e siècle', noticeterm__term__id__in=ContributableTerm.objects.values('term__id'))
-    for i in range(10):
-        id = queryset[random.randint(0, queryset.count() - 1)].id
-        if id not in notice_history:
-            break
+    all_qs = Notice.objects.filter(image=True, repr='', peri__contains='4e quart 19e siècle', noticeterm__term__id__in=ContributableTerm.objects.values('term__id'))
+    qs = all_qs.exclude(id__in=notice_history)
+    found_notices = qs.count()
+    if not found_notices:
+        notice_history = []
+        qs = all_qs
+        found_notices = qs.count()
+    id = qs[random.randint(0, found_notices - 1)].id
     notice_history.append(id)
     request.session['notice_history'] = notice_history
     return redirect('front_describe', pk=id)