diff --git a/mamweb/settings_common.py b/mamweb/settings_common.py index 75a5493c..925d5961 100644 --- a/mamweb/settings_common.py +++ b/mamweb/settings_common.py @@ -78,6 +78,7 @@ TEMPLATES = [ 'django.contrib.messages.context_processors.messages', 'sekizai.context_processors.sekizai', 'header_fotky.context_processors.vzhled', + 'various.context_processors.april', ) }, }, @@ -132,6 +133,7 @@ INSTALLED_APPS = ( 'korektury', 'prednasky', 'header_fotky', + 'various', # Admin upravy: diff --git a/mamweb/templates/base.html b/mamweb/templates/base.html index b79060b5..8f2b7a7d 100644 --- a/mamweb/templates/base.html +++ b/mamweb/templates/base.html @@ -131,6 +131,48 @@ $("a[rel^='gallery-image']").prettyPhoto(prettyparams); }); + {% if april == 2021 %} + + {% endif %} {% render_block "js" %} diff --git a/seminar/templates/seminar/odevzdavatko/detail.html b/seminar/templates/seminar/odevzdavatko/detail.html index dadeff41..14094fb8 100644 --- a/seminar/templates/seminar/odevzdavatko/detail.html +++ b/seminar/templates/seminar/odevzdavatko/detail.html @@ -1,5 +1,6 @@ {% extends "base.html" %} {% load static %} +{% load deadliny %} {% block content %} @@ -62,7 +63,9 @@ $(document).ready(function(){

Řešitelé: {{ object.resitele.all | join:", " }}

{# https://docs.djangoproject.com/en/3.1/ref/models/instances/#django.db.models.Model.get_FOO_display #} -

Forma: {{ object.get_forma_display }}, doručeno {{ object.cas_doruceni }}

+

Forma: {{ object.get_forma_display }}

+ +

Doručeno {{ object.cas_doruceni }}, deadline: {{object.cas_doruceni | deadline_html }}

{# Soubory: #}

Přílohy:

diff --git a/seminar/templates/seminar/registrace/password_reset_email.html b/seminar/templates/seminar/registrace/password_reset_email.html index 8e7186f9..8687a6cb 100644 --- a/seminar/templates/seminar/registrace/password_reset_email.html +++ b/seminar/templates/seminar/registrace/password_reset_email.html @@ -4,5 +4,5 @@ Obdrželi jsme od Tebe žádost o obnovu hesla uživatele {{ user }} na webu M&M Pro zadání nového hesla přejdi na následující stránku: {{ protocol}}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %} -S pozdravem, +S pozdravem organizátoři M&M \ No newline at end of file diff --git a/seminar/templatetags/deadliny.py b/seminar/templatetags/deadliny.py new file mode 100644 index 00000000..b7a0142d --- /dev/null +++ b/seminar/templatetags/deadliny.py @@ -0,0 +1,25 @@ +from django import template +from django.utils.safestring import mark_safe +from seminar.utils import TypDeadline, deadline +register = template.Library() + +@register.filter(name='deadline') +def deadline_text(datum): + typ, cislo, dl = deadline(datum) + strings = { + TypDeadline.PredDeadline: f"1. deadline čísla {cislo} ({dl})", + TypDeadline.SousDeadline: f"Soustřeďkový deadline čísla {cislo} ({dl})", + TypDeadline.FinalDeadline: f"Finální deadline čísla {cislo} ({dl})", + } + return strings[typ] + +@register.filter(name='deadline_html') +def deadline_html(datum): + typ, _, _ = deadline(datum) + text = deadline_text(datum) + classes = { + TypDeadline.PredDeadline: 'preddeadline', + TypDeadline.SousDeadline: 'sous_deadline', + TypDeadline.FinalDeadline: 'final_deadline', + } + return mark_safe(f'{text}') diff --git a/seminar/utils.py b/seminar/utils.py index a41b4111..68bce110 100644 --- a/seminar/utils.py +++ b/seminar/utils.py @@ -309,7 +309,7 @@ def deadline_v_rocniku(datum, rocnik): deadliny.append((TypDeadline.FinalDeadline, c, c.datum_deadline)) deadliny = sorted(deadliny, key=lambda x: x[2]) # podle data for dl in deadliny: - if datum <= dl: + if datum <= dl[2]: # První takový deadline je ten nejtěsnější return dl @@ -319,20 +319,22 @@ def deadline(datum): Vrací trojici (TypDeadline, Cislo, datumDeadline: date). """ + if isinstance(datum, datetime.datetime): + datum = datum.date() rok = datum.year # Dva ročníky podezřelé z obsahování dat - pozdejsi_rocnik = m.Rocnik.filter(prvni_rok=rok) - drivejsi_rocnik = m.Rocnik.filter(druhy_rok=rok) - if any( + pozdejsi_rocnik = m.Rocnik.objects.filter(prvni_rok=rok) + drivejsi_rocnik = m.Rocnik.objects.filter(prvni_rok=rok-1) + if any([ pozdejsi_rocnik.count() > 1, drivejsi_rocnik.count() > 1, - ): + ]): raise ValueError(f"Více ročníků začíná/končí stejným rokem: {rok}") pozdejsi_rocnik = pozdejsi_rocnik.first() if pozdejsi_rocnik.count() > 0 else None drivejsi_rocnik = drivejsi_rocnik.first() if drivejsi_rocnik.count() > 0 else None # Předpokládáme, že neexistuje číslo, které má deadline ale nemá finální deadline. - posledni_deadline_drivejsiho_rocniku = m.Cislo.objects.get(rocnik=drivejsi_rocnik, datum_deadline__isnull=False).datum_deadline + posledni_deadline_drivejsiho_rocniku = m.Cislo.objects.filter(rocnik=drivejsi_rocnik, datum_deadline__isnull=False).last().datum_deadline if datum <= posledni_deadline_drivejsiho_rocniku: return deadline_v_rocniku(datum, drivejsi_rocnik) diff --git a/various/__init__.py b/various/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/various/admin.py b/various/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/various/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/various/apps.py b/various/apps.py new file mode 100644 index 00000000..c24a4428 --- /dev/null +++ b/various/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class VariousConfig(AppConfig): + name = 'various' diff --git a/various/context_processors.py b/various/context_processors.py new file mode 100644 index 00000000..c0be2975 --- /dev/null +++ b/various/context_processors.py @@ -0,0 +1,14 @@ +def april(req): + if 'X-April' in req.headers: + try: + year = int(req.headers['X-April']) + return {'april': year} + except: + pass # Fall-back to regular behaviour + + import datetime + today = datetime.date.today() + if today.day == 1 and today.month == 4: + return {'april': today.year} + return {} + diff --git a/various/migrations/__init__.py b/various/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/various/models.py b/various/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/various/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/various/tests.py b/various/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/various/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/various/views.py b/various/views.py new file mode 100644 index 00000000..91ea44a2 --- /dev/null +++ b/various/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here.