]> git.parisson.com Git - teleforma.git/commitdiff
fix positive seminar delta
authorGuillaume Pellerin <yomguy@parisson.com>
Mon, 24 Nov 2014 16:20:32 +0000 (17:20 +0100)
committerGuillaume Pellerin <yomguy@parisson.com>
Mon, 24 Nov 2014 16:20:32 +0000 (17:20 +0100)
teleforma/management/commands/teleforma-increase-revision-time.py
teleforma/templates/teleforma/seminar_detail.html
teleforma/views/pro.py

index 81556d79cba5181c237ad32c9b6bf1a79d484421..75391cd027748f22f806c0983ce53586643391cf 100644 (file)
@@ -11,6 +11,7 @@ from django.utils import translation
 from telemeta.models import *
 from telemeta.util.unaccent import unaccent
 from teleforma.models import *
+from teleforma.views import *
 import logging
 import datetime
 
@@ -30,18 +31,21 @@ class Command(BaseCommand):
                 for seminar in seminars:
                     revisions = SeminarRevision.objects.filter(user=user, seminar=seminar)
                     if revisions:
-                        delta = datetime.timedelta(seconds=seminar.duration.as_seconds())
-                        if not revisions[0].date_modified:
-                            if len(revisions) > 1:
-                                revision = revisions[1]
-                                if revision.date_modified:
-                                    revision.date_modified = revision.date_modified + delta
+                        timer = get_seminar_timer(user, seminar)
+                        bonus = datetime.timedelta(seconds=seminar.duration.as_seconds())
+                        delta = timer - bonus
+                        if delta.total_seconds() < 0:
+                            if not revisions[0].date_modified:
+                                if len(revisions) > 1:
+                                    revision = revisions[1]
+                                    if revision.date_modified:
+                                        revision.date_modified = revision.date_modified + bonus
+                                    else:
+                                        revision.date_modified = revision.date + bonus
                                 else:
-                                    revision.date_modified = revision.date + delta
+                                    revision = revisions[0]
+                                    revision.date_modified = revision.date + bonus
                             else:
                                 revision = revisions[0]
-                                revision.date_modified = revision.date + delta
-                        else:
-                            revision = revisions[0]
-                            revision.date_modified = revision.date_modified + delta
-                        revision.save()
\ No newline at end of file
+                                revision.date_modified = revision.date_modified + bonus
+                            revision.save()
\ No newline at end of file
index 57b05e7c8edef3dac4ed26291268a07d119e8839..c5371f1fc0bd7b1a21cf7a9566f3a24621522d41 100644 (file)
@@ -198,7 +198,7 @@ $(window).ready(function( ){
       {% endwith %}
      {% endif %}
 
-     {% if seminar_validated and seminar_progress == 100 and seminar_time >= 0 %}
+     {% if seminar_validated and seminar_progress == 100 and delta_sec >= 0 %}
        <div class="course_content">
         <div class="course_subtitle">
           <h3><img src="{{ STATIC_URL }}/telemeta/images/item_title.png" width="10px" alt="" /> {% trans "Step" %} 7 : {% trans "download your testimonial" %}</h3>
index 5c2c457eff86602ba5eac175bf5eb7e3c2963273..d5f69f2442c483587dcda8b47e80de8c728caacc 100644 (file)
@@ -98,6 +98,14 @@ def render_to_pdf(request, template, context, filename=None, encoding='utf-8',
     return HttpResponse('Errors rendering pdf:<pre>%s</pre>' % escape(content))
 
 
+def get_seminar_timer(user, seminar):
+    t = datetime.timedelta()
+    for r in SeminarRevision.objects.filter(user=user, seminar=seminar, date__gte=REVISION_DATE_FILTER):
+        if r.date_modified:
+            t += r.delta()
+    return t
+
+
 class SeminarAccessMixin(object):
 
 
@@ -146,13 +154,6 @@ class SeminarView(SeminarAccessMixin, DetailView):
     model = Seminar
     template_name='teleforma/seminar_detail.html'
 
-    def get_delta(self, user, seminar):
-        t = datetime.timedelta()
-        for r in SeminarRevision.objects.filter(user=user, seminar=seminar, date__gte=REVISION_DATE_FILTER):
-            if r.date_modified:
-                t += r.delta()
-        return t
-
     @method_decorator(login_required)
     def dispatch(self, *args, **kwargs):
         return super(SeminarView, self).dispatch(*args, **kwargs)
@@ -167,19 +168,20 @@ class SeminarView(SeminarAccessMixin, DetailView):
         context['seminar_progress'] = progress
         context['seminar_validated'] = validated
 
-        delta = self.get_delta(user, seminar)
-        time = delta - datetime.timedelta(seconds=seminar.duration.as_seconds())
-        seminar_time = time.total_seconds()
-        context['seminar_time'] = seminar_time
+        timer = get_seminar_timer(seminar)
+        delta = timer - datetime.timedelta(seconds=seminar.duration.as_seconds())
+        delta_sec = delta.total_seconds()
+        context['delta_sec'] = delta_sec
         context['delta'] = str(delta).split('.')[0]
 
-        if progress == 100 and not validated and self.template_name == 'teleforma/seminar_detail.html':
+        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':
             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 seminar_time >= 0 and self.template_name == 'teleforma/seminar_detail.html':
+        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."))
-        if progress == 100 and validated and seminar_time < 0:
+        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."))
 
         return context