From a59e2f99777c36eb24f8c03909092fec10b17dd0 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Sun, 3 Mar 2024 22:44:59 +0100 Subject: [PATCH 01/10] =?UTF-8?q?U=C5=BEite=C4=8Dn=C3=A1=20chybov=C3=A1=20?= =?UTF-8?q?str=C3=A1nka=20pro=20ne=C3=BAsp=C4=9B=C5=A1n=C3=A9=20generov?= =?UTF-8?q?=C3=A1n=C3=AD=20ob=C3=A1lek?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/views/views_all.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/seminar/views/views_all.py b/seminar/views/views_all.py index 318eee21..9dc03550 100644 --- a/seminar/views/views_all.py +++ b/seminar/views/views_all.py @@ -562,6 +562,11 @@ def cisloObalkyView(request, rocnik, cislo): def obalkyView(request, resitele): + if len(resitele) == 0: + return render(request, 'universal.html', { + 'title': 'Není pro koho vyrobit obálky.', + 'text': 'Právě ses pokusil/a vygenerovat obálky pro prázdnou množinu lidí. Můžeš to zkusit změnit, případně se zeptej webařů :-)', + }) tex = render(request,'seminar/archiv/obalky.tex', {'resitele': resitele}).content tempdir = tempfile.mkdtemp() From d2926bd1a7b577c5ec7a4afbae67f5ba24784e15 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Sun, 3 Mar 2024 23:05:39 +0100 Subject: [PATCH 02/10] =?UTF-8?q?Spr=C3=A1vn=C3=A9=20hled=C3=A1n=C3=AD=20l?= =?UTF-8?q?i=C5=A1=C3=A1ka=20pro=20ob=C3=A1lky?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/views/views_all.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/seminar/views/views_all.py b/seminar/views/views_all.py index 9dc03550..e345e45d 100644 --- a/seminar/views/views_all.py +++ b/seminar/views/views_all.py @@ -8,6 +8,7 @@ from django.http import Http404 from django.db.models import Q, Sum, Count from django.views.generic.base import RedirectView from django.core.exceptions import PermissionDenied +from django.contrib.staticfiles.finders import find import seminar.models as s import seminar.models as m @@ -572,7 +573,7 @@ def obalkyView(request, resitele): tempdir = tempfile.mkdtemp() with open(tempdir+"/obalky.tex","w") as texfile: texfile.write(tex.decode()) - shutil.copy(os.path.join(settings.STATIC_ROOT, 'seminar/lisak.pdf'), tempdir) + shutil.copy(find('seminar/lisak.pdf'), tempdir) subprocess.call(["pdflatex","obalky.tex"], cwd = tempdir) with open(tempdir+"/obalky.pdf","rb") as pdffile: From 4ecd2a7a61509f7a1b7d50ebd1e87ba79ae3e127 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Sun, 3 Mar 2024 23:06:43 +0100 Subject: [PATCH 03/10] =?UTF-8?q?Je=C5=A1t=C4=9B=20status=20k=C3=B3d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/views/views_all.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/seminar/views/views_all.py b/seminar/views/views_all.py index e345e45d..1d0d87ba 100644 --- a/seminar/views/views_all.py +++ b/seminar/views/views_all.py @@ -37,6 +37,7 @@ import unicodedata import logging import time from collections.abc import Sequence +import http from seminar.utils import aktivniResitele @@ -564,10 +565,14 @@ def cisloObalkyView(request, rocnik, cislo): def obalkyView(request, resitele): if len(resitele) == 0: - return render(request, 'universal.html', { - 'title': 'Není pro koho vyrobit obálky.', - 'text': 'Právě ses pokusil/a vygenerovat obálky pro prázdnou množinu lidí. Můžeš to zkusit změnit, případně se zeptej webařů :-)', - }) + return HttpResponse( + render(request, 'universal.html', { + 'title': 'Není pro koho vyrobit obálky.', + 'text': 'Právě ses pokusil/a vygenerovat obálky pro prázdnou množinu lidí. Můžeš to zkusit změnit, případně se zeptej webařů :-)', + }), + status=http.HTTPStatus.NOT_FOUND, + ) + tex = render(request,'seminar/archiv/obalky.tex', {'resitele': resitele}).content tempdir = tempfile.mkdtemp() From 213d3cc7b239ddedd3ff4c91fb20af63b910ca4e Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Sun, 3 Mar 2024 23:07:51 +0100 Subject: [PATCH 04/10] =?UTF-8?q?Lep=C5=A1=C3=AD=20vyr=C3=A1b=C4=9Bn=C3=AD?= =?UTF-8?q?=20do=C4=8Dasn=C3=BDch=20adres=C3=A1=C5=99=C5=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Chceme je po sobě nejspíš mazat i když to spadne. Možná to zesložití vývoj, ale je to odolnější proti náhodnému pádu čehokoliv. --- seminar/views/views_all.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/seminar/views/views_all.py b/seminar/views/views_all.py index 1d0d87ba..662c5025 100644 --- a/seminar/views/views_all.py +++ b/seminar/views/views_all.py @@ -575,15 +575,14 @@ def obalkyView(request, resitele): tex = render(request,'seminar/archiv/obalky.tex', {'resitele': resitele}).content - tempdir = tempfile.mkdtemp() - with open(tempdir+"/obalky.tex","w") as texfile: - texfile.write(tex.decode()) - shutil.copy(find('seminar/lisak.pdf'), tempdir) - subprocess.call(["pdflatex","obalky.tex"], cwd = tempdir) - - with open(tempdir+"/obalky.pdf","rb") as pdffile: - response = HttpResponse(pdffile.read(), content_type='application/pdf') - shutil.rmtree(tempdir) + with tempfile.TemporaryDirectory() as tempdir: + with open(tempdir+"/obalky.tex","w") as texfile: + texfile.write(tex.decode()) + shutil.copy(find('seminar/lisak.pdf'), tempdir) + subprocess.call(["pdflatex","obalky.tex"], cwd = tempdir) + + with open(tempdir+"/obalky.pdf","rb") as pdffile: + response = HttpResponse(pdffile.read(), content_type='application/pdf') return response From 88ae103ec11c5cfa874bd9bc915e44ba7946aae0 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Sun, 3 Mar 2024 23:09:18 +0100 Subject: [PATCH 05/10] =?UTF-8?q?Lep=C5=A1=C3=AD=20slo=C5=BEky=20i=20pro?= =?UTF-8?q?=20stvrzenky?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- soustredeni/views.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/soustredeni/views.py b/soustredeni/views.py index f2aafdf7..899ee7f9 100644 --- a/soustredeni/views.py +++ b/soustredeni/views.py @@ -79,14 +79,14 @@ def soustredeniStvrzenkyView(request, soustredeni): castka = Nastaveni.get_solo().cena_sous tex = render(request, 'soustredeni/stvrzenky.tex', {'ucastnici': ucastnici, 'soustredeni': soustredeni, 'castka': castka}).content - tempdir = Path(tempfile.mkdtemp()) - with open(tempdir / "stvrzenky.tex", "w") as texfile: - texfile.write(tex.decode()) + with tempfile.TemporaryDirectory() as tempdirfn: + tempdir = Path(tempdirfn) + with open(tempdir / "stvrzenky.tex", "w") as texfile: + texfile.write(tex.decode()) - shutil.copy(find('images/logomm.pdf'), tempdir) - subprocess.call(["pdflatex", "stvrzenky.tex"], cwd = tempdir, stdout=subprocess.DEVNULL) + shutil.copy(find('images/logomm.pdf'), tempdir) + subprocess.call(["pdflatex", "stvrzenky.tex"], cwd = tempdir, stdout=subprocess.DEVNULL) - with open(tempdir / "stvrzenky.pdf", "rb") as pdffile: - response = HttpResponse(pdffile.read(), content_type='application/pdf') - shutil.rmtree(tempdir) + with open(tempdir / "stvrzenky.pdf", "rb") as pdffile: + response = HttpResponse(pdffile.read(), content_type='application/pdf') return response From a1000ad2bfbc5258f513b258d553f10386593a30 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Sun, 3 Mar 2024 23:11:51 +0100 Subject: [PATCH 06/10] =?UTF-8?q?Chybov=C3=A1=20hl=C3=A1=C5=A1ka=20i=20pro?= =?UTF-8?q?=20stvrzenky?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- soustredeni/views.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/soustredeni/views.py b/soustredeni/views.py index 899ee7f9..f150b6b8 100644 --- a/soustredeni/views.py +++ b/soustredeni/views.py @@ -9,6 +9,7 @@ import tempfile import shutil import subprocess from pathlib import Path +import http from seminar.views import obalkyView @@ -76,6 +77,14 @@ def soustredeniUcastniciExportView(request, soustredeni): def soustredeniStvrzenkyView(request, soustredeni): soustredeni = get_object_or_404(Soustredeni, id=soustredeni) ucastnici = Resitel.objects.filter(soustredeni=soustredeni) + if ucastnici.count() == 0: + return HttpResponse( + render(request, 'universal.html', { + 'title': 'Není pro koho vyrobit stvrzenky.', + 'text': 'Právě ses pokusil/a vygenerovat stvrzenky pro prázdnou množinu lidí. Můžeš to zkusit změnit, případně se zeptej webařů :-)', + }), + status=http.HTTPStatus.NOT_FOUND, + ) castka = Nastaveni.get_solo().cena_sous tex = render(request, 'soustredeni/stvrzenky.tex', {'ucastnici': ucastnici, 'soustredeni': soustredeni, 'castka': castka}).content From a301b122fd3dc824fc1ad8dbdf59a7dd74d03410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Sun, 31 Mar 2024 19:12:24 +0200 Subject: [PATCH 07/10] =?UTF-8?q?Apr=C3=ADl=202024?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mamweb/templates/base.html | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/mamweb/templates/base.html b/mamweb/templates/base.html index a29d4697..fafce9fa 100644 --- a/mamweb/templates/base.html +++ b/mamweb/templates/base.html @@ -188,6 +188,24 @@ walkText(document.body); {% endif %} + + {% if april == 2024 %} + + {% endif %} + {% block js %}{% endblock %} From 026efe2467646fc8aa95eba5c7f67da103ee310a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Sun, 14 Apr 2024 15:09:03 +0200 Subject: [PATCH 08/10] =?UTF-8?q?N=C3=A1pov=C4=9Bdy=20v=20=C5=A1ifrova?= =?UTF-8?q?=C4=8Dce?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sifrovacka/admin.py | 4 +- sifrovacka/forms.py | 14 +++- .../0004_napoveda_napovezenoucastnikovi.py | 65 +++++++++++++++++++ sifrovacka/models.py | 17 +++++ sifrovacka/templates/sifrovacka/napoveda.html | 48 ++++++++++++++ .../templates/sifrovacka/napovedy_list.html | 23 +++++++ .../templates/sifrovacka/sifrovacka.html | 2 + sifrovacka/urls.py | 12 +++- sifrovacka/views.py | 27 +++++++- 9 files changed, 206 insertions(+), 6 deletions(-) create mode 100644 sifrovacka/migrations/0004_napoveda_napovezenoucastnikovi.py create mode 100644 sifrovacka/templates/sifrovacka/napoveda.html create mode 100644 sifrovacka/templates/sifrovacka/napovedy_list.html diff --git a/sifrovacka/admin.py b/sifrovacka/admin.py index 71d191d4..5099c241 100644 --- a/sifrovacka/admin.py +++ b/sifrovacka/admin.py @@ -1,8 +1,10 @@ from django.contrib import admin -from .models import OdpovedUcastnika, SpravnaOdpoved +from .models import OdpovedUcastnika, SpravnaOdpoved, NapovezenoUcastnikovi, Napoveda # Register your models here. admin.site.register(OdpovedUcastnika) admin.site.register(SpravnaOdpoved) +admin.site.register(Napoveda) +admin.site.register(NapovezenoUcastnikovi) diff --git a/sifrovacka/forms.py b/sifrovacka/forms.py index e3eba7c7..8a1e16d1 100644 --- a/sifrovacka/forms.py +++ b/sifrovacka/forms.py @@ -1,6 +1,6 @@ from django.core.exceptions import ValidationError from django.forms import ModelForm, Textarea -from .models import OdpovedUcastnika, SpravnaOdpoved +from .models import OdpovedUcastnika, SpravnaOdpoved, NapovezenoUcastnikovi, Napoveda class SifrovackaForm(ModelForm): @@ -16,3 +16,15 @@ class SifrovackaForm(ModelForm): if SpravnaOdpoved.objects.filter(sifra=sifra).count() == 0: raise ValidationError("Tohle číslo šifry v databázi nemáme. Zkontrolujte si ho prosím.") return sifra + + +class NapovedaForm(ModelForm): + class Meta: + model = NapovezenoUcastnikovi + fields = ["sifra",] + + def clean_sifra(self): + sifra = self.cleaned_data.get('sifra') + if Napoveda.objects.filter(sifra=sifra).count() == 0: + raise ValidationError("K tomuto číslu šifry nemáme nápovědu. Zkonstolujte si ho prosím.") + return sifra diff --git a/sifrovacka/migrations/0004_napoveda_napovezenoucastnikovi.py b/sifrovacka/migrations/0004_napoveda_napovezenoucastnikovi.py new file mode 100644 index 00000000..cba7ae8f --- /dev/null +++ b/sifrovacka/migrations/0004_napoveda_napovezenoucastnikovi.py @@ -0,0 +1,65 @@ +# Generated by Django 4.2.8 on 2024-04-14 12:57 + +from django.db import migrations, models +import django.db.models.deletion +import django.utils.timezone + + +class Migration(migrations.Migration): + dependencies = [ + ( + "seminar", + "0114_related_name_se_zmenilo_a_django_chce_migraci_tak_dostane_migraci", + ), + ("sifrovacka", "0003_odpoveducastnika_uspech"), + ] + + operations = [ + migrations.CreateModel( + name="Napoveda", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("text", models.TextField()), + ("sifra", models.IntegerField()), + ], + ), + migrations.CreateModel( + name="NapovezenoUcastnikovi", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("sifra", models.IntegerField(verbose_name="Číslo šifry")), + ( + "timestamp", + models.DateTimeField( + default=django.utils.timezone.now, verbose_name="Timestamp" + ), + ), + ( + "resitel", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to="seminar.resitel", + ), + ), + ], + options={ + "ordering": ["-timestamp"], + }, + ), + ] diff --git a/sifrovacka/models.py b/sifrovacka/models.py index 6517c2e0..beabd0a7 100644 --- a/sifrovacka/models.py +++ b/sifrovacka/models.py @@ -25,3 +25,20 @@ class SpravnaOdpoved(models.Model): def __str__(self): return f"{self.sifra}: {self.odpoved}" + + +class NapovezenoUcastnikovi(models.Model): + class Meta: + ordering = ["-timestamp"] + + resitel = models.ForeignKey(Resitel, blank=False, null=False, on_delete=models.CASCADE) + sifra = models.IntegerField("Číslo šifry", blank=False, null=False,) + timestamp = models.DateTimeField("Timestamp", blank=False, null=False, default=timezone.now) + + +class Napoveda(models.Model): + text = models.TextField(blank=False, null=False,) + sifra = models.IntegerField(blank=False, null=False,) + + def __str__(self): + return f"{self.sifra}: {self.text}" diff --git a/sifrovacka/templates/sifrovacka/napoveda.html b/sifrovacka/templates/sifrovacka/napoveda.html new file mode 100644 index 00000000..88944216 --- /dev/null +++ b/sifrovacka/templates/sifrovacka/napoveda.html @@ -0,0 +1,48 @@ +{% extends "base.html" %} + +{% block content %} + +
+ +

{% block nadpis1a %}M&Mí šifrovačka{% endblock nadpis1a %}

+ +
+ +

Získat nápovědu k šifře:

+ +
+ + {{form.non_field_errors}} + {% for field in form %} + + + + + + + + + {% if field.errors %} + + + + {% endif %} + {% endfor %} +
+ + + + {{ field }} + {{ field.help_text|safe }} +
{{ field.errors }}
+ + {% csrf_token %} + + +
+ + Nechceme nápovědu, známe řešení! + +{% endblock content %} diff --git a/sifrovacka/templates/sifrovacka/napovedy_list.html b/sifrovacka/templates/sifrovacka/napovedy_list.html new file mode 100644 index 00000000..dc729947 --- /dev/null +++ b/sifrovacka/templates/sifrovacka/napovedy_list.html @@ -0,0 +1,23 @@ +{% extends "base.html" %} + +{% block content %} + +

{% block nadpis1a %}Šifrovačka vzaté nápovědy{% endblock nadpis1a %}

+ + + + + + + + + {% for u in object_list %} + + + + + + {% endfor %} +
TimestampŘešitelŠifra
{{ u.timestamp }}{{ u.resitel }}{{ u.sifra }}
+ +{% endblock content %} diff --git a/sifrovacka/templates/sifrovacka/sifrovacka.html b/sifrovacka/templates/sifrovacka/sifrovacka.html index 4e0cc15a..74943406 100644 --- a/sifrovacka/templates/sifrovacka/sifrovacka.html +++ b/sifrovacka/templates/sifrovacka/sifrovacka.html @@ -43,4 +43,6 @@ + Získat nápovědu + {% endblock content %} diff --git a/sifrovacka/urls.py b/sifrovacka/urls.py index a7af5e54..916d73ec 100644 --- a/sifrovacka/urls.py +++ b/sifrovacka/urls.py @@ -1,7 +1,7 @@ from django.urls import path from seminar.utils import org_required, resitel_or_org_required -from .views import SifrovackaView, SifrovackaListView +from .views import SifrovackaView, SifrovackaListView, NapovedaView, NapovedaListView urlpatterns = [ path( @@ -14,4 +14,14 @@ urlpatterns = [ org_required(SifrovackaListView.as_view()), name='sifrovacka_odpovedi' ), + path( + 'napoveda/', + resitel_or_org_required(NapovedaView.as_view()), + name='sifrovacka_napoveda' + ), + path( + 'napovedy/', + org_required(NapovedaListView.as_view()), + name='sifrovacka_napovedy' + ), ] diff --git a/sifrovacka/views.py b/sifrovacka/views.py index 9c4af3ed..5537344b 100644 --- a/sifrovacka/views.py +++ b/sifrovacka/views.py @@ -2,8 +2,8 @@ from django.urls import reverse from django.views.generic import FormView, ListView from seminar.views import formularOKView -from .forms import SifrovackaForm -from .models import OdpovedUcastnika, SpravnaOdpoved +from .forms import SifrovackaForm, NapovedaForm +from .models import OdpovedUcastnika, SpravnaOdpoved, Napoveda, NapovezenoUcastnikovi from seminar.models.personalni import Resitel @@ -24,10 +24,31 @@ class SifrovackaView(FormView): instance.uspech = True instance.save() - + return formularOKView(self.request, f'

{sifra.skryty_text}

Odevzdat další.




') class SifrovackaListView(ListView): template_name = 'sifrovacka/odpovedi_list.html' model = OdpovedUcastnika + + +class NapovedaView(FormView): + template_name = 'sifrovacka/napoveda.html' + form_class = NapovedaForm + + def form_valid(self, form): + instance = form.save(commit=False) + resitel = Resitel.objects.get(osoba__user=self.request.user) + instance.resitel = resitel + + if NapovezenoUcastnikovi.objects.filter(resitel=resitel, sifra=instance.sifra).first() is None: + instance.save() + + napoveda = Napoveda.objects.filter(sifra=instance.sifra).first() + return formularOKView(self.request, f'

Nápověda k šifře číslo {instance.sifra} je:

{napoveda.text}

Odevzdat řešení.




') + + +class NapovedaListView(ListView): + template_name = 'sifrovacka/napovedy_list.html' + model = NapovezenoUcastnikovi From 9a93f954906d1eeaccc2a447d0c6c73a1f7a2445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Sun, 21 Apr 2024 21:06:56 +0200 Subject: [PATCH 09/10] =?UTF-8?q?fix:=20N=C3=A1pov=C4=9Bdy=20v=20=C5=A1ifr?= =?UTF-8?q?ova=C4=8Dce?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sifrovacka/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sifrovacka/forms.py b/sifrovacka/forms.py index 8a1e16d1..3ae75cc1 100644 --- a/sifrovacka/forms.py +++ b/sifrovacka/forms.py @@ -26,5 +26,5 @@ class NapovedaForm(ModelForm): def clean_sifra(self): sifra = self.cleaned_data.get('sifra') if Napoveda.objects.filter(sifra=sifra).count() == 0: - raise ValidationError("K tomuto číslu šifry nemáme nápovědu. Zkonstolujte si ho prosím.") + raise ValidationError("K tomuto číslu šifry nemáme nápovědu. Zkontrolujte si ho prosím.") return sifra From d09a08f53fc5c9c028ac4295f0908fe7e4a9441e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Mon, 22 Apr 2024 23:27:29 +0200 Subject: [PATCH 10/10] =?UTF-8?q?fix:=20P=C5=99eskakov=C3=A1n=C3=AD=20v=20?= =?UTF-8?q?=C5=A1ifrova=C4=8Dce=20(je=20tam=20faaaaakt=20hodn=C4=9B=20sn?= =?UTF-8?q?=C4=9Bhu)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sifrovacka/templates/sifrovacka/napoveda.html | 4 +- .../templates/sifrovacka/preskoceni.html | 54 +++++++++++++++++++ .../templates/sifrovacka/sifrovacka.html | 4 +- sifrovacka/urls.py | 7 ++- sifrovacka/views.py | 16 ++++++ 5 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 sifrovacka/templates/sifrovacka/preskoceni.html diff --git a/sifrovacka/templates/sifrovacka/napoveda.html b/sifrovacka/templates/sifrovacka/napoveda.html index 88944216..cce48ed8 100644 --- a/sifrovacka/templates/sifrovacka/napoveda.html +++ b/sifrovacka/templates/sifrovacka/napoveda.html @@ -43,6 +43,8 @@ - Nechceme nápovědu, známe řešení! +

Nechceme nápovědu, známe řešení!

+ +

Přeskoč šifru

{% endblock content %} diff --git a/sifrovacka/templates/sifrovacka/preskoceni.html b/sifrovacka/templates/sifrovacka/preskoceni.html new file mode 100644 index 00000000..64e777ea --- /dev/null +++ b/sifrovacka/templates/sifrovacka/preskoceni.html @@ -0,0 +1,54 @@ +{% extends "base.html" %} + +{% block content %} + +
+ +

{% block nadpis1a %}M&Mí šifrovačka{% endblock nadpis1a %}

+ +
+ +

Přeskočit šifru:

+ +
+ + {{form.non_field_errors}} + {% for field in form %} + {% if field.id_for_label != "id_odpoved" %} + + + + + + + + + {% if field.errors %} + + + + {% endif %} + {% else %} + {{ field.as_hidden }} + {% endif %} + {% endfor %} +
+ + + + {{ field }} + {{ field.help_text|safe }} +
{{ field.errors }}
+ + {% csrf_token %} + + +
+ +

Nechceme přeskočit, známe řešení!

+ +

Nechceme přeskakovat, ale nápověda by se šikla.

+ +{% endblock content %} diff --git a/sifrovacka/templates/sifrovacka/sifrovacka.html b/sifrovacka/templates/sifrovacka/sifrovacka.html index 74943406..1ce95454 100644 --- a/sifrovacka/templates/sifrovacka/sifrovacka.html +++ b/sifrovacka/templates/sifrovacka/sifrovacka.html @@ -43,6 +43,8 @@ - Získat nápovědu +

Získat nápovědu

+ +

Přeskoč šifru

{% endblock content %} diff --git a/sifrovacka/urls.py b/sifrovacka/urls.py index 916d73ec..85f9c4cc 100644 --- a/sifrovacka/urls.py +++ b/sifrovacka/urls.py @@ -1,7 +1,7 @@ from django.urls import path from seminar.utils import org_required, resitel_or_org_required -from .views import SifrovackaView, SifrovackaListView, NapovedaView, NapovedaListView +from .views import SifrovackaView, SifrovackaListView, NapovedaView, NapovedaListView, PreskoceniView urlpatterns = [ path( @@ -24,4 +24,9 @@ urlpatterns = [ org_required(NapovedaListView.as_view()), name='sifrovacka_napovedy' ), + path( + 'preskoceni/', + resitel_or_org_required(PreskoceniView.as_view()), + name='sifrovacka_preskoceni' + ), ] diff --git a/sifrovacka/views.py b/sifrovacka/views.py index 5537344b..59f3deec 100644 --- a/sifrovacka/views.py +++ b/sifrovacka/views.py @@ -52,3 +52,19 @@ class NapovedaView(FormView): class NapovedaListView(ListView): template_name = 'sifrovacka/napovedy_list.html' model = NapovezenoUcastnikovi + + +class PreskoceniView(FormView): + template_name = 'sifrovacka/preskoceni.html' + form_class = SifrovackaForm + initial = {"odpoved": "=======PŘESKOČENO======="} + + def form_valid(self, form): + instance = form.save(commit=False) + instance.odpoved = "=======PŘESKOČENO=======" + resitel = Resitel.objects.get(osoba__user=self.request.user) + instance.resitel = resitel + instance.save() + sifra = SpravnaOdpoved.objects.filter(sifra=instance.sifra).first() # FIXME co když je více "správných" odpovědí? + + return formularOKView(self.request, f'

{sifra.skryty_text}

Zpět na odevzdávátko.




')