arbiter counts for supervisor
[edumed.git] / stage2 / views.py
index 59c2d82..3d6a72d 100644 (file)
@@ -5,7 +5,10 @@ from django.http import Http404
 from django.http.response import HttpResponseRedirect, HttpResponse, HttpResponseForbidden
 from django.shortcuts import get_object_or_404, render
 from django.utils import timezone
+from django.utils.cache import patch_cache_control
+from django.views.decorators.cache import never_cache
 from django.views.decorators.http import require_POST
+from unidecode import unidecode
 
 from stage2.forms import AttachmentForm, MarkForm
 from stage2.models import Participant, Assignment, Answer, Attachment, Mark
@@ -22,13 +25,17 @@ def all_assignments(participant):
     return assignments
 
 
+@never_cache
 def participant_view(request, participant_id, key):
     participant = get_object_or_404(Participant, id=participant_id)
     if not participant.check(key):
         raise Http404
-    return render(request, 'stage2/participant.html', {
+    response = render(request, 'stage2/participant.html', {
         'participant': participant,
         'assignments': all_assignments(participant)})
+    # not needed in Django 1.8
+    patch_cache_control(response, no_cache=True, no_store=True, must_revalidate=True)
+    return response
 
 
 @require_POST
@@ -54,8 +61,8 @@ def upload(request, assignment_id, participant_id, key):
 def attachment_download(attachment):
     response = HttpResponse(content_type='application/force-download')
     response.write(attachment.file.read())
-    base, ext = attachment.filename().rsplit('.', 1)
-    response['Content-Disposition'] = 'attachment; filename="%s.%s"' % (base[:20].replace('\n', '').strip(), ext)
+    # workaround to this: https://code.djangoproject.com/ticket/20889
+    response['Content-Disposition'] = 'attachment; filename="%s"' % unidecode(attachment.filename().replace('\n', ' '))
     response['Content-Length'] = response.tell()
     return response
 
@@ -80,6 +87,9 @@ def assignment_list(request):
     for assignment in assignments:
         assignment.marked_count = Mark.objects.filter(expert=request.user, answer__assignment=assignment).count()
         assignment.to_mark_count = assignment.available_answers(request.user).count()
+        assignment.supervisor = request.user in assignment.supervisors.all()
+        assignment.arbiter_count = assignment.answer_set.filter(need_arbiter=True).count()
+
     non_empty_assignments = [ass for ass in assignments if ass.marked_count > 0 or ass.to_mark_count > 0]
     if len(non_empty_assignments) == 1 and non_empty_assignments[0].to_mark_count > 0:
         return HttpResponseRedirect(reverse('stage2_answer_list', args=[non_empty_assignments[0].id]))