From 1cbd856d7fae9a838f477fd4ed884f1bc16dd881 Mon Sep 17 00:00:00 2001 From: Gael Le Mignot Date: Tue, 19 Dec 2017 15:17:03 +0100 Subject: [PATCH] Various fixes and additions on remaining steps, quiz, and disabling download link for non-admin --- teleforma/context_processors.py | 46 +++++++++++++++--- teleforma/locale/fr/LC_MESSAGES/django.mo | Bin 20132 -> 20253 bytes teleforma/locale/fr/LC_MESSAGES/django.po | 10 ++-- .../templates/teleforma/course_media.html | 2 +- .../teleforma/inc/document_simple_list.html | 2 +- .../templates/teleforma/inc/media_list.html | 2 +- .../teleforma/inc/media_package_list.html | 6 ++- .../teleforma/inc/question_list.html | 2 + .../templates/teleforma/inc/quiz_list.html | 8 +-- teleforma/templatetags/teleforma_tags.py | 7 ++- teleforma/views/pro.py | 17 +++++-- 11 files changed, 77 insertions(+), 25 deletions(-) diff --git a/teleforma/context_processors.py b/teleforma/context_processors.py index 13108098..bab539b5 100644 --- a/teleforma/context_processors.py +++ b/teleforma/context_processors.py @@ -36,20 +36,42 @@ from teleforma.views.core import * -def seminar_progress(user, seminar): +def seminar_progress(user, seminar, more=False): """return the user progress of a seminar in percent + if more is True, return additionals informations """ progress = 0 total = 0 - - objects = [seminar.docs_1, seminar.docs_2, seminar.medias, seminar.docs_correct] - for obj in objects: + missing_steps = set() + + objects = [ + { + 'obj': seminar.docs_1, + 'step': '1' + }, + { + 'obj': seminar.medias, + 'step': '2' + }, + { + 'obj': seminar.docs_2, + 'step': '3' + }, + { + 'obj': seminar.docs_correct, + 'step': '5' + }] + for item in objects: + obj = item['obj'] + step = item['step'] for item in obj.all(): if item.weight: total += item.weight if user in item.readers.all(): progress += item.weight + else: + missing_steps.add(step) questions = Question.objects.filter(seminar=seminar, status=3) for question in questions: @@ -59,6 +81,8 @@ def seminar_progress(user, seminar): validated=True, treated=True) if answer: progress += question.weight + else: + missing_steps.add('4') if seminar.quiz: quiz_weight = 3 @@ -66,11 +90,19 @@ def seminar_progress(user, seminar): total += quiz_weight if quiz_validations: progress += quiz_weight + else: + missing_steps.add('2bis') if total != 0: - return int(progress*100/total) + progress = int(progress*100/total) + else: + progress = 0 + if not more: + return progress else: - return 0 + return {'progress':progress, 'missing_steps':missing_steps} + + def seminar_validated(user, seminar): validated = [] @@ -78,7 +110,7 @@ def seminar_validated(user, seminar): if seminar.quiz: quiz_validations = QuizValidation.objects.filter(user=user, quiz=seminar.quiz, validated=True) if not quiz_validations: - return False + return False if questions: for question in questions: answers = Answer.objects.filter(question=question, user=user, diff --git a/teleforma/locale/fr/LC_MESSAGES/django.mo b/teleforma/locale/fr/LC_MESSAGES/django.mo index 920cb5c29a5891ef623f1bd379ae08b02200c5ac..ee44003ed2048c10a91526247473cacb9767d59a 100644 GIT binary patch delta 5935 zcmYk=33OD|9mnxE*?=SjNdh4T%&>;A89<~8F`$I71d$48tRf>!=p2#^CSwpveJX-b ztVjnGdIVXIf(uY8MlEhER*hRMiy}l(77-K$RFtLPU*12beaAnad+&SifB*NsH#0e| zUG7`H!si}Lja%YyWcwVaEv7ef9G7--szx2BX&c8$#Aet8(~(P@wq_SQpNEqeAAkd5 z9Oo%~mOT3}cbs$hFv$mU{(&pJe6L{=Q#tR@NZ`b7OvBGn6P?0a@fSNkCfggo72_G7 zh$L`IZM@RPXQB$eACqwb#^F*MUyjQEOoOiDY@*Seff`i8U8n?gs0$CE3OtNW@dPU2 zS=4pEqVA9PJ5CCwq4IPV|`Kg=c5)dRDG95F^yOprvWU%7I>Fgi8}uvYQnkZ zBGd#=q6%Gwx^F#df|pU}Uq|i44(or6%C`qyo%oDKCp?P$=OnlH3h9Ze{AzO$D&Yvc z3`e6@J`q)Th4rUfe-3Kr9z_+n1eI^O`E+}pzbe_xfD*rmTH!0Ggga4N`GNI6Lv8U_ zHvXfHUqs$Hr%4BIf<)AP>8J(zQTO#k*nSsQjByJ5l3W<1N(6Ywd!)sLJb6m7YKq zbQ)XYdDJ6F;khYMHtKvXs?a{D!U{1COHdO}K)oBK)_2QjXyOPep^KW}F;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wGzn&KOi M+G*o~)ILG~0}&U5eE {% if doc.file %}{% endif %} {{ doc.title }}{% if doc.file %}{% endif %} - {% if doc.file %}{% if user in doc.readers.all %} {% endif %}{% endif %} + {% if doc.file %}{% if user in doc.readers.all %}{% else %} {% endif %}{% endif %} {% endfor %} diff --git a/teleforma/templates/teleforma/inc/media_list.html b/teleforma/templates/teleforma/inc/media_list.html index dea22473..c96bbd86 100644 --- a/teleforma/templates/teleforma/inc/media_list.html +++ b/teleforma/templates/teleforma/inc/media_list.html @@ -51,7 +51,7 @@ {% elif not media.is_published and user.is_staff %} {% endif %} - {% if media.item.file %} + {% if media.item.file and user.is_staff %} diff --git a/teleforma/templates/teleforma/inc/media_package_list.html b/teleforma/templates/teleforma/inc/media_package_list.html index 7584f6d1..9f58496e 100644 --- a/teleforma/templates/teleforma/inc/media_package_list.html +++ b/teleforma/templates/teleforma/inc/media_package_list.html @@ -42,12 +42,14 @@ {% if user in media.readers.all %} + {% else %} + {% endif %} - {% if media.item.file %} + diff --git a/teleforma/templates/teleforma/inc/question_list.html b/teleforma/templates/teleforma/inc/question_list.html index f87b7b7b..507a5a0f 100644 --- a/teleforma/templates/teleforma/inc/question_list.html +++ b/teleforma/templates/teleforma/inc/question_list.html @@ -23,6 +23,8 @@ {% elif question|submitted:user and question|validated:user %} + {% else %} + {% endif %} diff --git a/teleforma/templates/teleforma/inc/quiz_list.html b/teleforma/templates/teleforma/inc/quiz_list.html index 6745d308..a6ba8aea 100644 --- a/teleforma/templates/teleforma/inc/quiz_list.html +++ b/teleforma/templates/teleforma/inc/quiz_list.html @@ -10,13 +10,15 @@ {% endif %} - {% if seminar.quiz|quiz_validated:user %} - {% trans "validé le" %} {{ seminar.quiz|quiz_validated:user }} + {% if seminar|quiz_validated:user %} + {% trans "validé le" %} {{ seminar|quiz_validated:user }} {% endif %} - {% if seminar.quiz|quiz_validated:user %} + {% if seminar|quiz_validated:user %} + {% else %} + {% endif %} diff --git a/teleforma/templatetags/teleforma_tags.py b/teleforma/templatetags/teleforma_tags.py index 60a9bb55..415d731b 100644 --- a/teleforma/templatetags/teleforma_tags.py +++ b/teleforma/templatetags/teleforma_tags.py @@ -242,8 +242,11 @@ def validated(question, user): return '' @register.filter -def quiz_validated(quiz, user): - validations = QuizValidation.objects.filter(quiz=quiz, user=user, validated=True) +def quiz_validated(seminar, user): + quiz = seminar.quiz + startdate = seminar.date_added + enddate = seminar.expiry_date + validations = QuizValidation.objects.filter(quiz=quiz, user=user, validated=True,date_validated__range=[startdate, enddate]) if validations: return validations[0].date_validated else: diff --git a/teleforma/views/pro.py b/teleforma/views/pro.py index 2285561a..da13bacd 100644 --- a/teleforma/views/pro.py +++ b/teleforma/views/pro.py @@ -197,20 +197,29 @@ class SeminarView(SeminarAccessMixin, DetailView): # mess.moderation_status = 'a' # mess.save() # notify_user(mess, 'acceptance') + progress_data = seminar_progress(user, seminar, more=True) - - progress = seminar_progress(user, seminar) + progress = progress_data['progress'] + missing_steps = progress_data['missing_steps'] context['seminar_progress'] = progress context['seminar_validated'] = validated delta_sec = context['delta_sec'] if progress == 100 and not validated and self.template_name == 'teleforma/seminar_detail.html': messages.info(self.request, _("You have successfully terminated your e-learning seminar. A training testimonial will be available as soon as the pedagogical team validate all your answers (48h maximum).")) - elif progress < 100 and validated and self.template_name == 'teleforma/seminar_detail.html': + elif progress < 100 and validated and self.template_name == 'teleforma/seminar_detail.html' and missing_steps == set('5'): messages.info(self.request, _("All your answers have been validated. You can now read the corrected documents (step 5).")) elif progress == 100 and validated and delta_sec >= 0 and self.template_name == 'teleforma/seminar_detail.html': messages.info(self.request, _("You have successfully terminated all steps of your e-learning seminar. You can now download your training testimonial below.")) + elif len(missing_steps) == 1: + messages.warning(self.request, _("You still need to complete step %(step)s in order to get yout testimonial.") % {'step':missing_steps.pop()}) if progress == 100 and validated and delta_sec < 0: - messages.info(self.request, _("Your connexion time is not sufficient. In order to get your testimonial, you have to work at least the time required for this seminar.")) + minutes = -delta_sec / 60 + hours = minutes / 60 + missing = "%d minutes" % minutes + if hours >= 1: + missing = "%dh%02d" % (hours, minutes % 60) + messages.warning(self.request, _("Your connexion time is not sufficient. In order to get your testimonial, you " + "still have to work at least %(time)s.") % {'time':missing}) return context -- 2.39.5