From ef37e6e8191b3f4e54c5f4214ec0514da09a1b61 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Wed, 5 Jul 2017 00:54:22 +0200 Subject: [PATCH] Fix all upload views --- teleforma/exam/views.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/teleforma/exam/views.py b/teleforma/exam/views.py index 7c147f9a..022bd640 100644 --- a/teleforma/exam/views.py +++ b/teleforma/exam/views.py @@ -176,8 +176,13 @@ class ScriptCreateView(CreateView): def get_context_data(self, **kwargs): context = super(ScriptCreateView, self).get_context_data(**kwargs) - context['upload'] = (getattr(settings, 'TELEFORMA_EXAM_SCRiIPT_UPLOAD', True) or self.request.user.is_superuser) - context['period'] = Period.objects.get(id=self.kwargs['period_id']) + period = Period.objects.get(id=self.kwargs['period_id']) + context['period'] = period + if getattr(settings, 'TELEFORMA_EXAM_SCRIPT_UPLOAD', True) and period.date_exam_end: + context['upload'] = datetime.datetime.now() <= period.date_exam_end + else: + context['upload'] = False + context['period'] = period context['create_fields'] = ['course', 'session', 'type', 'file' ] course_pk_list = [c['course'].id for c in get_courses(self.request.user)] context['form'].fields['course'].queryset = Course.objects.filter(pk__in=course_pk_list) @@ -344,12 +349,6 @@ class ScoreCreateView(ScriptCreateView): def get_context_data(self, **kwargs): context = super(ScriptCreateView, self).get_context_data(**kwargs) - period = Period.objects.get(id=self.kwargs['period_id']) - context['period'] = period - if getattr(settings, 'TELEFORMA_EXAM_SCRIPT_UPLOAD', True) and period.date_exam_end: - context['upload'] = datetime.datetime.now() <= period.date_exam_end - else: - context['upload'] = False context['create_fields'] = ['course', 'session', 'type', 'score' ] course_pk_list = [c['course'].id for c in get_courses(self.request.user)] context['form'].fields['course'].queryset = Course.objects.filter(pk__in=course_pk_list) -- 2.39.5