From: Guillaume Pellerin Date: Mon, 24 Nov 2014 16:20:32 +0000 (+0100) Subject: fix positive seminar delta X-Git-Tag: 2.8.1-pro~282^2~35 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=35bfd1692c419b3af66fe6ae7dba644f37e193a6;p=teleforma.git fix positive seminar delta --- diff --git a/teleforma/management/commands/teleforma-increase-revision-time.py b/teleforma/management/commands/teleforma-increase-revision-time.py index 81556d79..75391cd0 100644 --- a/teleforma/management/commands/teleforma-increase-revision-time.py +++ b/teleforma/management/commands/teleforma-increase-revision-time.py @@ -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 diff --git a/teleforma/templates/teleforma/seminar_detail.html b/teleforma/templates/teleforma/seminar_detail.html index 57b05e7c..c5371f1f 100644 --- a/teleforma/templates/teleforma/seminar_detail.html +++ b/teleforma/templates/teleforma/seminar_detail.html @@ -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 %}

{% trans "Step" %} 7 : {% trans "download your testimonial" %}

diff --git a/teleforma/views/pro.py b/teleforma/views/pro.py index 5c2c457e..d5f69f24 100644 --- a/teleforma/views/pro.py +++ b/teleforma/views/pro.py @@ -98,6 +98,14 @@ def render_to_pdf(request, template, context, filename=None, encoding='utf-8', return HttpResponse('Errors rendering pdf:
%s
' % 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