From 1a2bef328b9735c61681e8efd643c3221d9ddc27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Tue, 21 Jan 2025 21:43:43 +0100 Subject: [PATCH] =?UTF-8?q?Inteligentn=C4=9Bj=C5=A1=C3=AD=20p=C5=99i=C5=99?= =?UTF-8?q?azov=C3=A1n=C3=AD=20seznamu=20p=C5=99edn=C3=A1=C5=A1ek=20hlasov?= =?UTF-8?q?=C3=A1tku=20a=20upozorn=C4=9Bn=C3=AD=20na=20neexistuj=C3=ADc?= =?UTF-8?q?=C3=AD=20seznam?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- prednasky/views.py | 10 +++++++++- .../0007_nastaveni_aktualni_sous.py | 20 +++++++++++++++++++ various/models.py | 5 +++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 various/migrations/0007_nastaveni_aktualni_sous.py diff --git a/prednasky/views.py b/prednasky/views.py index 52302262..a2a2594c 100644 --- a/prednasky/views.py +++ b/prednasky/views.py @@ -1,3 +1,5 @@ +import http + from django.shortcuts import render, get_object_or_404 from django.views import generic from django.shortcuts import HttpResponseRedirect @@ -7,14 +9,20 @@ from django.forms import Form from various.views.pomocne import formularOKView +from various.models import Nastaveni from prednasky.models import Prednaska, Hlasovani, Seznam, STAV_NAVRH from soustredeni.models import Soustredeni from personalni.models import Osoba def newPrednaska(request): # hlasovani se vztahuje k nejnovejsimu soustredeni - sous = Soustredeni.objects.first() + sous = Nastaveni.get_solo().aktualni_sous seznam = Seznam.objects.filter(soustredeni = sous, stav = STAV_NAVRH).first() + if sous is None or seznam is None: + return render(request, 'universal.html', { + 'title': "Nelze hlasovat", + 'text': "Není žádný seznam přednášek, o kterém by se dalo hlasovat.", + }, status=http.HTTPStatus.NOT_FOUND) osoba = Osoba.objects.filter(user=request.user).first() ucastnik = osoba.plne_jmeno() + ' ' + str(osoba.id) # obsluha formulare diff --git a/various/migrations/0007_nastaveni_aktualni_sous.py b/various/migrations/0007_nastaveni_aktualni_sous.py new file mode 100644 index 00000000..718aabd4 --- /dev/null +++ b/various/migrations/0007_nastaveni_aktualni_sous.py @@ -0,0 +1,20 @@ +# Generated by Django 4.2.16 on 2025-01-21 20:34 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('soustredeni', '0013_alter_soustredeni_kontaktnicek_pdf_and_more'), + ('various', '0006_tvorba_post'), + ] + + operations = [ + migrations.AddField( + model_name='nastaveni', + name='aktualni_sous', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='soustredeni.soustredeni', verbose_name='Aktuálně připravovaný sous'), + ), + ] diff --git a/various/models.py b/various/models.py index 363c3137..b662b029 100644 --- a/various/models.py +++ b/various/models.py @@ -26,6 +26,11 @@ class Nastaveni(SingletonModel): verbose_name="Účastnický poplatek za soustředění", default=1000) + aktualni_sous = models.ForeignKey( + "soustredeni.Soustredeni", verbose_name='Aktuálně připravovaný sous', + null=True, blank=False, on_delete=models.PROTECT, + ) + @property def aktualni_rocnik(self): return self.aktualni_cislo.rocnik