diff --git a/mamweb/urls.py b/mamweb/urls.py index 95fd90a4..9d438d93 100644 --- a/mamweb/urls.py +++ b/mamweb/urls.py @@ -51,6 +51,9 @@ urlpatterns = [ # Aesop (ma vlastni podadresare) path('', include('aesop.urls')), + # Various = co se nevešlo jinam + path('', include('various.urls')), + # REST API # path('api/', include(router.urls)), diff --git a/odevzdavatko/views.py b/odevzdavatko/views.py index e5de47c2..9215d3f8 100644 --- a/odevzdavatko/views.py +++ b/odevzdavatko/views.py @@ -21,7 +21,7 @@ import seminar.models as m from . import forms as f from .forms import OdevzdavatkoTabulkaFiltrForm as FiltrForm from seminar.utils import resi_v_rocniku -from seminar.views import formularOKView +from various.views.pomocne import formularOKView logger = logging.getLogger(__name__) diff --git a/personalni/views.py b/personalni/views.py index c2712b30..96ef2405 100644 --- a/personalni/views.py +++ b/personalni/views.py @@ -17,7 +17,7 @@ from datetime import date import logging import csv -from seminar.views import formularOKView +from various.views.pomocne import formularOKView from various.autentizace.views import LoginView from various.autentizace.utils import posli_reset_hesla diff --git a/seminar/templates/seminar/jakresit/jak-resit.html b/seminar/templates/seminar/jakresit/jak-resit.html deleted file mode 100644 index fd278c68..00000000 --- a/seminar/templates/seminar/jakresit/jak-resit.html +++ /dev/null @@ -1,16 +0,0 @@ -{% extends 'base.html' %} - -{% load humanize %} -{% load static %} - - -{% block content %} - -
- -{% include 'seminar/jakresit/jakresit_1.svg' %} -{% include 'seminar/jakresit/jakresit_2.svg' %} -{% include 'seminar/jakresit/jakresit_3.svg' %} - -
-{% endblock %} diff --git a/seminar/urls.py b/seminar/urls.py index d64320c1..afc2cd1d 100644 --- a/seminar/urls.py +++ b/seminar/urls.py @@ -65,19 +65,11 @@ urlpatterns = [ org_required(views.TitulyView), name='seminar_cislo_titul' ), - path( - 'stav', - org_required(views.StavDatabazeView), - name='stav_databaze' - ), path( 'cislo/./odmeny/./', org_required(views.OdmenyView.as_view()), name="seminar_archiv_odmeny"), - path('', views.TitulniStranaView.as_view(), name='titulni_strana'), - path('jak-resit/', views.JakResitView.as_view(), name='jak_resit'), - # Dočasné & neodladěné: path( 'hidden/hromadne_pridani', diff --git a/seminar/views/views_all.py b/seminar/views/views_all.py index f58e8706..3c3d4b16 100644 --- a/seminar/views/views_all.py +++ b/seminar/views/views_all.py @@ -18,7 +18,6 @@ from seminar.models import Problem, Cislo, Reseni, Nastaveni, Rocnik, \ #from .models import VysledkyZaCislo, VysledkyKCisluZaRocnik, VysledkyKCisluOdjakziva from seminar import utils from treenode import treelib -from novinky.views import spravne_novinky import treenode.templatetags as tnltt import treenode.serializers as vr from vysledkovky.utils import body_resitelu, VysledkovkaCisla, \ @@ -37,7 +36,6 @@ from django.conf import settings import unicodedata import logging import time -from collections.abc import Sequence import http from seminar.utils import aktivniResitele @@ -226,33 +224,6 @@ def aktualni_temata(rocnik): return Tema.objects.filter(rocnik=rocnik, stav='zadany').order_by('kod') -class TitulniStranaView(generic.ListView): - template_name= 'seminar/titulnistrana/titulnistrana.html' - - def get_queryset(self): - return spravne_novinky(self.request)[:3] - - def get_context_data(self, **kwargs): - context = super(TitulniStranaView, self).get_context_data(**kwargs) - nastaveni = get_object_or_404(Nastaveni) - - deadline = m.Deadline.objects.filter(deadline__gte=timezone.now()).order_by("deadline").first() - context['nejblizsi_deadline'] = deadline - - # Aktuální témata - nazvy_a_odkazy_na_aktualni_temata = [] - akt_temata = aktualni_temata(nastaveni.aktualni_rocnik) - - for tema in akt_temata: - # FIXME: netuším, jestli funguje tema.verejne_url(), nemáme testdata na témátka - je to asi url vzhledem k ročníku - nazvy_a_odkazy_na_aktualni_temata.append({'nazev':tema.nazev,'url':tema.verejne_url()}) - - context['aktualni_temata'] = nazvy_a_odkazy_na_aktualni_temata - - print(context) - - return context - ### Co je M&M @@ -652,47 +623,7 @@ class ClankyResitelView(generic.ListView): # queryset = Problem.objects.filter(stav=Problem.STAV_ZADANY).select_related('cislo_zadani__rocnik').order_by('-cislo_zadani__rocnik__rocnik', 'kod') -### Status -def StavDatabazeView(request): -# nastaveni = Nastaveni.objects.get() - problemy = utils.seznam_problemu() - muzi = Resitel.objects.filter(osoba__osloveni=m.Osoba.OSLOVENI_MUZSKE) - zeny = Resitel.objects.filter(osoba__osloveni=m.Osoba.OSLOVENI_ZENSKE) - return render(request, 'seminar/stav_databaze.html', - { -# 'nastaveni': nastaveni, - 'problemy': problemy, - - 'resitele': Resitel.objects.all(), - 'muzi': muzi, - 'zeny': zeny, - 'jmena_muzu': utils.histogram([r.osoba.jmeno for r in muzi]), - 'jmena_zen': utils.histogram([r.osoba.jmeno for r in zeny]), - }) - - -# Interní, nemá se nikdy objevit v urls (jinak to účastníci vytrolí) -def formularOKView(request, text='', dalsi_odkazy: Sequence[tuple[str, str]] = ()): - template_name = 'seminar/formular_ok.html' - odkazy = list(dalsi_odkazy) + [ - # (Text, odkaz) - ('Vrátit se na titulní stránku', reverse('titulni_strana')), - ('Zobrazit aktuální zadání', reverse('seminar_aktualni_zadani')), - ] - context = { - 'odkazy': odkazy, - 'text': text, - } - return render(request, template_name, context) - -#------------------ Jak řešit - možná má být udělané úplně jinak - -class JakResitView(generic.ListView): - template_name = 'seminar/jakresit/jak-resit.html' - - def get_queryset(self): - return None class AktualniRocnikRedirectView(RedirectView): permanent=False diff --git a/sifrovacka/views.py b/sifrovacka/views.py index 0bfa994f..2a111faf 100644 --- a/sifrovacka/views.py +++ b/sifrovacka/views.py @@ -1,7 +1,7 @@ from django.urls import reverse from django.views.generic import FormView, ListView -from seminar.views import formularOKView +from various.views.pomocne import formularOKView from .forms import SifrovackaForm, NapovedaForm from .models import OdpovedUcastnika, SpravnaOdpoved, Napoveda, NapovezenoUcastnikovi from personalni.models import Resitel diff --git a/seminar/templates/seminar/formular_ok.html b/various/templates/various/formular_ok.html similarity index 100% rename from seminar/templates/seminar/formular_ok.html rename to various/templates/various/formular_ok.html diff --git a/various/templates/various/jakresit/jak-resit.html b/various/templates/various/jakresit/jak-resit.html new file mode 100644 index 00000000..8aba9597 --- /dev/null +++ b/various/templates/various/jakresit/jak-resit.html @@ -0,0 +1,16 @@ +{% extends 'base.html' %} + +{% load humanize %} +{% load static %} + + +{% block content %} + +
+ +{% include 'various/jakresit/jakresit_1.svg' %} +{% include 'various/jakresit/jakresit_2.svg' %} +{% include 'various/jakresit/jakresit_3.svg' %} + +
+{% endblock %} diff --git a/seminar/templates/seminar/jakresit/jakresit_1.svg b/various/templates/various/jakresit/jakresit_1.svg similarity index 100% rename from seminar/templates/seminar/jakresit/jakresit_1.svg rename to various/templates/various/jakresit/jakresit_1.svg diff --git a/seminar/templates/seminar/jakresit/jakresit_2.svg b/various/templates/various/jakresit/jakresit_2.svg similarity index 100% rename from seminar/templates/seminar/jakresit/jakresit_2.svg rename to various/templates/various/jakresit/jakresit_2.svg diff --git a/seminar/templates/seminar/jakresit/jakresit_3.svg b/various/templates/various/jakresit/jakresit_3.svg similarity index 100% rename from seminar/templates/seminar/jakresit/jakresit_3.svg rename to various/templates/various/jakresit/jakresit_3.svg diff --git a/seminar/templates/seminar/pracuje_se.html b/various/templates/various/pracuje_se.html similarity index 85% rename from seminar/templates/seminar/pracuje_se.html rename to various/templates/various/pracuje_se.html index 1a396534..e80fea23 100644 --- a/seminar/templates/seminar/pracuje_se.html +++ b/various/templates/various/pracuje_se.html @@ -10,7 +10,7 @@

Na této stránce velmi intenzivně pracujeme. Za dočasnou nedostupnost se omlouváme. - Zkuste přejít na titulní stránku + Zkuste přejít na titulní stránku nebo se podívat na aktuální zadání.

diff --git a/seminar/templates/seminar/stav_databaze.html b/various/templates/various/stav_databaze.html similarity index 100% rename from seminar/templates/seminar/stav_databaze.html rename to various/templates/various/stav_databaze.html diff --git a/seminar/templates/seminar/titulnistrana/graph.svg b/various/templates/various/titulnistrana/graph.svg similarity index 100% rename from seminar/templates/seminar/titulnistrana/graph.svg rename to various/templates/various/titulnistrana/graph.svg diff --git a/seminar/templates/seminar/titulnistrana/titulnistrana.html b/various/templates/various/titulnistrana/titulnistrana.html similarity index 97% rename from seminar/templates/seminar/titulnistrana/titulnistrana.html rename to various/templates/various/titulnistrana/titulnistrana.html index 7a6e3185..10354c2f 100644 --- a/seminar/templates/seminar/titulnistrana/titulnistrana.html +++ b/various/templates/various/titulnistrana/titulnistrana.html @@ -79,7 +79,7 @@ function sousdeadline() {
- {% include 'seminar/titulnistrana/graph.svg' %} + {% include 'various/titulnistrana/graph.svg' %}
diff --git a/various/urls.py b/various/urls.py new file mode 100644 index 00000000..ae2d3042 --- /dev/null +++ b/various/urls.py @@ -0,0 +1,9 @@ +from django.urls import path +from .views.final import TitulniStranaView, JakResitView, StavDatabazeView +from seminar.utils import org_required + +urlpatterns = [ + path('', TitulniStranaView.as_view(), name='titulni_strana'), + path('jak-resit/', JakResitView.as_view(), name='jak_resit'), + path('stav', org_required(StavDatabazeView), name='stav_databaze'), +] diff --git a/various/views/final.py b/various/views/final.py new file mode 100644 index 00000000..a4c06f74 --- /dev/null +++ b/various/views/final.py @@ -0,0 +1,73 @@ +""" +Stránky, které se mi nepovedlo lépe zařadit. + +Oproti `./pomocne.py` se tyto views používají přímo ve various +a naopak importují spoustu věcí odjinud +""" + +from django.shortcuts import get_object_or_404, render +from django.utils import timezone +from django.views import generic + +import novinky.views +import seminar.utils +import seminar.views +from personalni.models import Resitel +from seminar import models as m + +from ..models import Nastaveni + + +class TitulniStranaView(generic.ListView): + template_name = 'various/titulnistrana/titulnistrana.html' + + def get_queryset(self): + return novinky.views.spravne_novinky(self.request)[:3] + + def get_context_data(self, **kwargs): + context = super(TitulniStranaView, self).get_context_data(**kwargs) + nastaveni = get_object_or_404(Nastaveni) + + deadline = m.Deadline.objects.filter( + deadline__gte=timezone.now()).order_by("deadline").first() + context['nejblizsi_deadline'] = deadline + + # Aktuální témata + nazvy_a_odkazy_na_aktualni_temata = [] + akt_temata = seminar.views.aktualni_temata(nastaveni.aktualni_rocnik) + + for tema in akt_temata: + # FIXME: netuším, jestli funguje tema.verejne_url(), nemáme testdata na témátka - je to asi url vzhledem k ročníku + nazvy_a_odkazy_na_aktualni_temata.append({ + 'nazev': tema.nazev, + 'url': tema.verejne_url() + }) + + context['aktualni_temata'] = nazvy_a_odkazy_na_aktualni_temata + + return context + + +class JakResitView(generic.ListView): + template_name = 'various/jakresit/jak-resit.html' + + def get_queryset(self): + return None + + +### Status +def StavDatabazeView(request): + # nastaveni = Nastaveni.objects.get() + problemy = seminar.utils.seznam_problemu() + muzi = Resitel.objects.filter(osoba__osloveni=m.Osoba.OSLOVENI_MUZSKE) + zeny = Resitel.objects.filter(osoba__osloveni=m.Osoba.OSLOVENI_ZENSKE) + return render(request, 'various/stav_databaze.html', { + # 'nastaveni': nastaveni, + 'problemy': problemy, + + 'resitele': Resitel.objects.all(), + 'muzi': muzi, + 'zeny': zeny, + 'jmena_muzu': seminar.utils.histogram([r.osoba.jmeno for r in muzi]), + 'jmena_zen': seminar.utils.histogram([r.osoba.jmeno for r in zeny]), + }) diff --git a/various/views/pomocne.py b/various/views/pomocne.py new file mode 100644 index 00000000..42547467 --- /dev/null +++ b/various/views/pomocne.py @@ -0,0 +1,26 @@ +""" +Stránky, které se mi nepovedlo lépe zařadit. + +Oproti `./final.py` se tyto views importují odjinud +tedy ideálně neimportovat sem nic od jinud +""" + +from typing import Sequence + +from django.shortcuts import render +from django.urls import reverse + + +# Interní, nemá se nikdy objevit v urls (jinak to účastníci vytrolí) +def formularOKView(request, text='', dalsi_odkazy: Sequence[tuple[str, str]] = ()): + template_name = 'seminar/formular_ok.html' + odkazy = list(dalsi_odkazy) + [ + # (Text, odkaz) + ('Vrátit se na titulní stránku', reverse('titulni_strana')), + ('Zobrazit aktuální zadání', reverse('seminar_aktualni_zadani')), + ] + context = { + 'odkazy': odkazy, + 'text': text, + } + return render(request, template_name, context) diff --git a/vyroci/views.py b/vyroci/views.py index 207ed619..455d6e25 100644 --- a/vyroci/views.py +++ b/vyroci/views.py @@ -1,7 +1,7 @@ from django.views.generic import FormView, ListView from seminar.models import Osoba -from seminar.views import formularOKView +from various.views.pomocne import formularOKView from .forms import UcastnikVyrociForm from .models import UcastnikVyroci