From 543e0de243c7a6298428f815bd725e4560759491 Mon Sep 17 00:00:00 2001 From: "Bc. Petr Pecha" Date: Sun, 13 Sep 2015 17:06:22 +0200 Subject: [PATCH] Zobrazovani casu do konce TODO humanize --- seminar/templates/seminar/titulnistrana.html | 13 ++++++++++++- seminar/views.py | 11 +++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/seminar/templates/seminar/titulnistrana.html b/seminar/templates/seminar/titulnistrana.html index d135e9e6..18c6184b 100644 --- a/seminar/templates/seminar/titulnistrana.html +++ b/seminar/templates/seminar/titulnistrana.html @@ -11,7 +11,18 @@
- Do konce odeslání řešení zbývá: {{cas_do_konce}}. + Do konce odeslání řešení zbývá: + {# TODO humanize #} + {{cas_do_konce_dni}} dní + {% if cas_do_konce_dni < 5 %} + {{cas_do_konce_hodin}} hodin + {% if cas_do_konce_hodin < 5 %} + {{cas_do_konce_minut}} minut + {% if cas_do_konce_minut < 5 %} + {{cas_do_konce_sekund}} + {% endif %} + {% endif %} + {% endif %}

diff --git a/seminar/views.py b/seminar/views.py index 5d29dfe2..7727548f 100644 --- a/seminar/views.py +++ b/seminar/views.py @@ -48,13 +48,12 @@ class TitulniStranaView(generic.ListView): context = super(TitulniStranaView, self).get_context_data(**kwargs) nastaveni = get_object_or_404(Nastaveni) cas_deadline = nastaveni.aktualni_cislo.datum_deadline - cas_do_konce = datetime.combine(cas_deadline, datetime.min.time()) \ + rozdil_casu = datetime.combine(cas_deadline, datetime.max.time()) \ - datetime.now() - context['cas_do_konce'] = \ - str(cas_do_konce.days) + " dní " + \ - str(cas_do_konce.seconds / 3600) + " hodin " + \ - str((cas_do_konce.seconds / 60) % 60)+" min " + \ - str(cas_do_konce.seconds % 60) + " sekund" + context['cas_do_konce_dni'] = rozdil_casu.days + context['cas_do_konce_hodin'] = rozdil_casu.seconds / 3600 + context['cas_do_konce_minut'] = (rozdil_casu.seconds / 60) % 60 + context['cas_do_konce_sekund'] = rozdil_casu.seconds % 60 return context class StareNovinkyView(generic.ListView):