From a737fefd5bcae2121b2c9fb730e87664c136610b Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Mon, 30 Jun 2014 00:09:41 +0200 Subject: [PATCH] add "Read" script status (5), update queries --- teleforma/exam/models.py | 7 +++++-- .../exam/templates/exam/inc/script_list.html | 2 +- teleforma/exam/views.py | 19 ++++++++++++++++--- teleforma/templates/telemeta/base.html | 8 ++++---- teleforma/templatetags/teleforma_tags.py | 8 ++++++-- 5 files changed, 32 insertions(+), 12 deletions(-) diff --git a/teleforma/exam/models.py b/teleforma/exam/models.py index 376eb36a..98b8e109 100644 --- a/teleforma/exam/models.py +++ b/teleforma/exam/models.py @@ -58,7 +58,7 @@ import crocodoc crocodoc.api_token = settings.BOX_API_TOKEN SCRIPT_STATUS = ((0, _('rejected')), (1, _('draft')), (2, _('submitted')), - (3, _('pending')),(4, _('marked')) ) + (3, _('pending')),(4, _('marked')), (5, _('read')) ) REJECT_REASON = ((1, _('unreadable')), (2, _('bad orientation')), (3, _('bad framing')), (4, _('incomplete')),) @@ -281,7 +281,10 @@ class Script(BaseResource): def submit(self): self.date_submitted = datetime.datetime.now() self.url = settings.MEDIA_URL + unicode(self.file) - self.box_uuid = crocodoc.document.upload(url=self.url) + try: + self.box_uuid = crocodoc.document.upload(url=self.url) + except: + pass if not self.corrector: self.auto_set_corrector() diff --git a/teleforma/exam/templates/exam/inc/script_list.html b/teleforma/exam/templates/exam/inc/script_list.html index 33bfaf29..6d544bf8 100644 --- a/teleforma/exam/templates/exam/inc/script_list.html +++ b/teleforma/exam/templates/exam/inc/script_list.html @@ -23,7 +23,7 @@ {% for script in object_list %} - + {{ script.course.title }} {{ script.session }} {{ script.type }} diff --git a/teleforma/exam/views.py b/teleforma/exam/views.py index d907ff0d..486743ec 100644 --- a/teleforma/exam/views.py +++ b/teleforma/exam/views.py @@ -39,6 +39,11 @@ class ScriptView(CourseAccessMixin, UpdateView): if not access: context['access_error'] = access_error context['message'] = contact_message + + if script.status == 4 and self.request.user == script.author: + script.status = 5 + script.save() + return context @method_decorator(login_required) @@ -66,7 +71,9 @@ class ScriptsPendingView(ScriptsView): def get_queryset(self): user = self.request.user period = Period.objects.get(id=self.kwargs['period_id']) - scripts = Script.objects.filter(Q(status=3, author=user, period=period) | Q(status=3, corrector=user, period=period)) + Q1 = Q(status=3, author=user, period=period) + Q2 = Q(status=3, corrector=user, period=period) + scripts = Script.objects.filter(Q1 | Q2) return scripts def get_context_data(self, **kwargs): @@ -79,7 +86,11 @@ class ScriptsTreatedView(ScriptsView): def get_queryset(self): user = self.request.user - scripts = Script.objects.filter(Q(status=4, author=user) | Q(status=4, corrector=user)) + Q1 = Q(status=4, author=user) + Q2 = Q(status=5, author=user) + Q3 = Q(status=4, corrector=user) + Q4 = Q(status=5, corrector=user) + scripts = Script.objects.filter(Q1 | Q2 | Q3 | Q4) return scripts def get_context_data(self, **kwargs): @@ -92,7 +103,9 @@ class ScriptsRejectedView(ScriptsView): def get_queryset(self): user = self.request.user - scripts = Script.objects.filter(Q(status=0, author=user) | Q(status=0, corrector=user)) + Q1 = Q(status=0, author=user) + Q2 = Q(status=0, corrector=user) + scripts = Script.objects.filter(Q1 | Q2) return scripts def get_context_data(self, **kwargs): diff --git a/teleforma/templates/telemeta/base.html b/teleforma/templates/telemeta/base.html index 8f27e366..89f8315f 100644 --- a/teleforma/templates/telemeta/base.html +++ b/teleforma/templates/telemeta/base.html @@ -113,13 +113,13 @@ alt="logo" /> {% if exam_access %} {% if periods|length == 1 %} -
  •  {% trans "Scripts" %}  - {% if user.is_staff or user.correctors.all %}{% untreated_scripts_count user periods.0.id %} +
  •  {% trans "Scripts" %} + {% if user.is_staff or user.quotas.all %}{% untreated_scripts_count user periods.0.id %} {% else %}{% treated_scripts_count user periods.0.id %}{% endif %}
  • {% else %} -
  •  {% trans "Scripts" %}  - {% if user.is_staff or user.correctors.all %}{% untreated_scripts_count user periods.0.id %} +
  •  {% trans "Scripts" %} + {% if user.is_staff or user.quotas.all %}{% untreated_scripts_count user periods.0.id %} {% else %}{% treated_scripts_count user periods.0.id %}{% endif %}