From 1aa389414d47e81280157d77e558e6f432f1985e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Sat, 14 Oct 2023 11:26:38 +0200 Subject: [PATCH 1/6] =?UTF-8?q?N=C3=A1vrh=20na=20webappku=20na=20=C5=A1ifr?= =?UTF-8?q?ova=C4=8Dku=20(na=20Sklen=C3=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mamweb/settings_common.py | 1 + mamweb/urls.py | 2 + sifrovacka/__init__.py | 0 sifrovacka/admin.py | 8 ++++ sifrovacka/apps.py | 5 ++ sifrovacka/forms.py | 15 ++++++ sifrovacka/migrations/0001_initial.py | 34 ++++++++++++++ sifrovacka/migrations/__init__.py | 0 sifrovacka/models.py | 18 ++++++++ .../templates/sifrovacka/odpovedi_list.html | 23 ++++++++++ .../templates/sifrovacka/sifrovacka.html | 46 +++++++++++++++++++ sifrovacka/urls.py | 17 +++++++ sifrovacka/views.py | 30 ++++++++++++ 13 files changed, 199 insertions(+) create mode 100644 sifrovacka/__init__.py create mode 100644 sifrovacka/admin.py create mode 100644 sifrovacka/apps.py create mode 100644 sifrovacka/forms.py create mode 100644 sifrovacka/migrations/0001_initial.py create mode 100644 sifrovacka/migrations/__init__.py create mode 100644 sifrovacka/models.py create mode 100644 sifrovacka/templates/sifrovacka/odpovedi_list.html create mode 100644 sifrovacka/templates/sifrovacka/sifrovacka.html create mode 100644 sifrovacka/urls.py create mode 100644 sifrovacka/views.py diff --git a/mamweb/settings_common.py b/mamweb/settings_common.py index 36b39296..71bae132 100644 --- a/mamweb/settings_common.py +++ b/mamweb/settings_common.py @@ -154,6 +154,7 @@ INSTALLED_APPS = ( 'soustredeni', 'treenode', 'vyroci', + 'sifrovacka', # Admin upravy: diff --git a/mamweb/urls.py b/mamweb/urls.py index 0855b6b6..9ef2750a 100644 --- a/mamweb/urls.py +++ b/mamweb/urls.py @@ -71,6 +71,8 @@ urlpatterns = [ # Výroční sraz path('sraz/30-let/', include('vyroci.urls')), + # Miniapka na šifrovačku + path('sifrovacka/', include('sifrovacka.urls')), ] # This is only needed when using runserver. diff --git a/sifrovacka/__init__.py b/sifrovacka/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/sifrovacka/admin.py b/sifrovacka/admin.py new file mode 100644 index 00000000..71d191d4 --- /dev/null +++ b/sifrovacka/admin.py @@ -0,0 +1,8 @@ +from django.contrib import admin + +from .models import OdpovedUcastnika, SpravnaOdpoved + +# Register your models here. + +admin.site.register(OdpovedUcastnika) +admin.site.register(SpravnaOdpoved) diff --git a/sifrovacka/apps.py b/sifrovacka/apps.py new file mode 100644 index 00000000..e9f34de6 --- /dev/null +++ b/sifrovacka/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class SifrovackaConfig(AppConfig): + name = 'sifrovacka' diff --git a/sifrovacka/forms.py b/sifrovacka/forms.py new file mode 100644 index 00000000..ac547894 --- /dev/null +++ b/sifrovacka/forms.py @@ -0,0 +1,15 @@ +from django.core.exceptions import ValidationError +from django.forms import ModelForm +from .models import OdpovedUcastnika, SpravnaOdpoved + + +class SifrovackaForm(ModelForm): + class Meta: + model = OdpovedUcastnika + fields = ["sifra", "odpoved", ] + + def clean_sifra(self): + sifra = self.cleaned_data.get('sifra') + if SpravnaOdpoved.objects.filter(sifra=sifra).count() == 0: + raise ValidationError("Špatné číslo šifry") + return sifra diff --git a/sifrovacka/migrations/0001_initial.py b/sifrovacka/migrations/0001_initial.py new file mode 100644 index 00000000..742461ef --- /dev/null +++ b/sifrovacka/migrations/0001_initial.py @@ -0,0 +1,34 @@ +# Generated by Django 3.2.22 on 2023-10-14 09:20 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('seminar', '0113_resitel_zasilat_cislo_papirove'), + ] + + operations = [ + migrations.CreateModel( + name='SpravnaOdpoved', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('odpoved', models.TextField()), + ('sifra', models.IntegerField()), + ('skryty_text', models.TextField()), + ], + ), + migrations.CreateModel( + name='OdpovedUcastnika', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('odpoved', models.TextField(verbose_name='Tajenka')), + ('sifra', models.IntegerField(verbose_name='Číslo šifry')), + ('resitel', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='seminar.resitel')), + ], + ), + ] diff --git a/sifrovacka/migrations/__init__.py b/sifrovacka/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/sifrovacka/models.py b/sifrovacka/models.py new file mode 100644 index 00000000..0e2dc78e --- /dev/null +++ b/sifrovacka/models.py @@ -0,0 +1,18 @@ +from django.db import models + +from seminar.models.personalni import Resitel + + +# Create your models here. + + +class OdpovedUcastnika(models.Model): + resitel = models.ForeignKey(Resitel, blank=False, null=False, on_delete=models.CASCADE) + odpoved = models.TextField("Tajenka", blank=False, null=False,) + sifra = models.IntegerField("Číslo šifry", blank=False, null=False,) + + +class SpravnaOdpoved(models.Model): + odpoved = models.TextField(blank=False, null=False,) + sifra = models.IntegerField(blank=False, null=False,) + skryty_text = models.TextField(blank=False, null=False,) diff --git a/sifrovacka/templates/sifrovacka/odpovedi_list.html b/sifrovacka/templates/sifrovacka/odpovedi_list.html new file mode 100644 index 00000000..8e122558 --- /dev/null +++ b/sifrovacka/templates/sifrovacka/odpovedi_list.html @@ -0,0 +1,23 @@ +{% extends "base.html" %} + +{% block content %} + +

{% block nadpis1a %}Šifrovačka odpovědi{% endblock nadpis1a %}

+ + + + + + + + + {% for u in object_list %} + + + + + + {% endfor %} +
ŘešitelŠifraOdpověď
{{ u.resitel }}{{ u.sifra }}{{ u.odpoved }}
+ +{% endblock content %} diff --git a/sifrovacka/templates/sifrovacka/sifrovacka.html b/sifrovacka/templates/sifrovacka/sifrovacka.html new file mode 100644 index 00000000..4e0cc15a --- /dev/null +++ b/sifrovacka/templates/sifrovacka/sifrovacka.html @@ -0,0 +1,46 @@ +{% extends "base.html" %} + +{% block content %} + +
+ +

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

+ +
+ +

Zadat tajenku šifry:

+ +
+ + {{form.non_field_errors}} + {% for field in form %} + + + + + + + + + {% if field.errors %} + + + + {% endif %} + {% endfor %} +
+ + + + {{ field }} + {{ field.help_text|safe }} +
{{ field.errors }}
+ + {% csrf_token %} + + +
+ +{% endblock content %} diff --git a/sifrovacka/urls.py b/sifrovacka/urls.py new file mode 100644 index 00000000..0f3eb669 --- /dev/null +++ b/sifrovacka/urls.py @@ -0,0 +1,17 @@ +from django.urls import path + +from seminar.utils import org_required, resitel_required +from .views import SifrovackaView, SifrovackaListView + +urlpatterns = [ + path( + '', + resitel_required(SifrovackaView.as_view()), + name='sifrovacka' + ), + path( + 'odpovedi/', + org_required(SifrovackaListView.as_view()), + name='sifrovacka_odpovedi' + ), +] diff --git a/sifrovacka/views.py b/sifrovacka/views.py new file mode 100644 index 00000000..a83e6c17 --- /dev/null +++ b/sifrovacka/views.py @@ -0,0 +1,30 @@ +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 seminar.models.personalni import Resitel + + +# Create your views here. + +class SifrovackaView(FormView): + template_name = 'sifrovacka/sifrovacka.html' + form_class = SifrovackaForm + + def form_valid(self, form): + instance = form.save(commit=False) + resitel = Resitel.objects.get(osoba__user=self.request.user) + instance.resitel = resitel + instance.save() + sifra = SpravnaOdpoved.objects.filter(sifra=instance.sifra, odpoved__iexact=instance.odpoved.strip()).first() + if sifra is None: + return formularOKView(self.request, f'

Bohužel vám hvězdy nebyly nakloněny.

Zkusit znovu.




') + + return formularOKView(self.request, f'

{sifra.skryty_text}

Odevzdat další.




') + + +class SifrovackaListView(ListView): + template_name = 'sifrovacka/odpovedi_list.html' + model = OdpovedUcastnika -- 2.39.5 From c635b0a2802cedafce0d95bd34361cf54dd595b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Sat, 14 Oct 2023 12:09:14 +0200 Subject: [PATCH 2/6] =?UTF-8?q?K=20formul=C3=A1=C5=99i=20maj=C3=AD=20m?= =?UTF-8?q?=C3=ADt=20p=C5=99=C3=ADstup=20i=20orgov=C3=A9=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sifrovacka/urls.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sifrovacka/urls.py b/sifrovacka/urls.py index 0f3eb669..a7af5e54 100644 --- a/sifrovacka/urls.py +++ b/sifrovacka/urls.py @@ -1,12 +1,12 @@ from django.urls import path -from seminar.utils import org_required, resitel_required +from seminar.utils import org_required, resitel_or_org_required from .views import SifrovackaView, SifrovackaListView urlpatterns = [ path( '', - resitel_required(SifrovackaView.as_view()), + resitel_or_org_required(SifrovackaView.as_view()), name='sifrovacka' ), path( -- 2.39.5 From dca7a7beddc0b0e546466c6ca3adfa8a6743699a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Borek=20Po=C5=BE=C3=A1r?= Date: Sat, 14 Oct 2023 12:28:22 +0200 Subject: [PATCH 3/6] =?UTF-8?q?Trochu=20p=C5=99eps=C3=A1ny=20text=C3=ADky.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sifrovacka/forms.py | 2 +- sifrovacka/views.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sifrovacka/forms.py b/sifrovacka/forms.py index ac547894..06edaba6 100644 --- a/sifrovacka/forms.py +++ b/sifrovacka/forms.py @@ -11,5 +11,5 @@ class SifrovackaForm(ModelForm): def clean_sifra(self): sifra = self.cleaned_data.get('sifra') if SpravnaOdpoved.objects.filter(sifra=sifra).count() == 0: - raise ValidationError("Špatné číslo šifry") + raise ValidationError("Tohle číslo šifry v databázi nemáme. Zkontrolujte si ho prosím.") return sifra diff --git a/sifrovacka/views.py b/sifrovacka/views.py index a83e6c17..20dcf49a 100644 --- a/sifrovacka/views.py +++ b/sifrovacka/views.py @@ -20,9 +20,9 @@ class SifrovackaView(FormView): instance.save() sifra = SpravnaOdpoved.objects.filter(sifra=instance.sifra, odpoved__iexact=instance.odpoved.strip()).first() if sifra is None: - return formularOKView(self.request, f'

Bohužel vám hvězdy nebyly nakloněny.

Zkusit znovu.




') + return formularOKView(self.request, f'

Bohužel vám hvězdy nebyly nakloněny. Rozumějte máte to blbě.

Zkusit znovu.




') - return formularOKView(self.request, f'

{sifra.skryty_text}

Odevzdat další.




') + return formularOKView(self.request, f'

{sifra.skryty_text}

Odevzdat další.




') class SifrovackaListView(ListView): -- 2.39.5 From b8eee44ed05c5c01bd0e75ac54ee07d709f41939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Borek=20Po=C5=BE=C3=A1r?= Date: Sat, 14 Oct 2023 12:37:23 +0200 Subject: [PATCH 4/6] Hrajeme si se styly. --- sifrovacka/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sifrovacka/views.py b/sifrovacka/views.py index 20dcf49a..91100e53 100644 --- a/sifrovacka/views.py +++ b/sifrovacka/views.py @@ -20,9 +20,9 @@ class SifrovackaView(FormView): instance.save() sifra = SpravnaOdpoved.objects.filter(sifra=instance.sifra, odpoved__iexact=instance.odpoved.strip()).first() if sifra is None: - return formularOKView(self.request, f'

Bohužel vám hvězdy nebyly nakloněny. Rozumějte máte to blbě.

Zkusit znovu.




') + return formularOKView(self.request, f'

Bohužel vám hvězdy nebyly nakloněny. Rozumějte máte to blbě.

Zkusit znovu.




') - return formularOKView(self.request, f'

{sifra.skryty_text}

Odevzdat další.




') + return formularOKView(self.request, f'

{sifra.skryty_text}

Odevzdat další.




') class SifrovackaListView(ListView): -- 2.39.5 From 1f7b770a5c8b71593dead68d3c9beca49243e3ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Sun, 15 Oct 2023 19:52:11 +0200 Subject: [PATCH 5/6] =?UTF-8?q?Odpov=C4=9Bdi=20od=20=C3=BA=C4=8Dastn=C3=AD?= =?UTF-8?q?k=C5=AF=20maj=C3=AD=20nov=C4=9B=20i=20timestamp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0002_auto_20231015_1944.py | 28 +++++++++++++++++++ sifrovacka/models.py | 7 ++++- .../templates/sifrovacka/odpovedi_list.html | 2 ++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 sifrovacka/migrations/0002_auto_20231015_1944.py diff --git a/sifrovacka/migrations/0002_auto_20231015_1944.py b/sifrovacka/migrations/0002_auto_20231015_1944.py new file mode 100644 index 00000000..dea42891 --- /dev/null +++ b/sifrovacka/migrations/0002_auto_20231015_1944.py @@ -0,0 +1,28 @@ +# Generated by Django 3.2.22 on 2023-10-15 17:44 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('sifrovacka', '0001_initial'), + ] + + operations = [ + migrations.AlterModelOptions( + name='odpoveducastnika', + options={'ordering': ['-timestamp']}, + ), + migrations.AddField( + model_name='odpoveducastnika', + name='timestamp', + field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='Timestamp'), + ), + migrations.AlterField( + model_name='odpoveducastnika', + name='odpoved', + field=models.TextField(verbose_name='Tajenka bez diakritiky'), + ), + ] diff --git a/sifrovacka/models.py b/sifrovacka/models.py index 0e2dc78e..05dd6e4c 100644 --- a/sifrovacka/models.py +++ b/sifrovacka/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.utils import timezone from seminar.models.personalni import Resitel @@ -7,9 +8,13 @@ from seminar.models.personalni import Resitel class OdpovedUcastnika(models.Model): + class Meta: + ordering = ["-timestamp"] + resitel = models.ForeignKey(Resitel, blank=False, null=False, on_delete=models.CASCADE) - odpoved = models.TextField("Tajenka", blank=False, null=False,) + odpoved = models.TextField("Tajenka bez diakritiky", blank=False, null=False,) sifra = models.IntegerField("Číslo šifry", blank=False, null=False,) + timestamp = models.DateTimeField("Timestamp", blank=False, null=False, default=timezone.now) class SpravnaOdpoved(models.Model): diff --git a/sifrovacka/templates/sifrovacka/odpovedi_list.html b/sifrovacka/templates/sifrovacka/odpovedi_list.html index 8e122558..cc52a584 100644 --- a/sifrovacka/templates/sifrovacka/odpovedi_list.html +++ b/sifrovacka/templates/sifrovacka/odpovedi_list.html @@ -6,6 +6,7 @@ + @@ -13,6 +14,7 @@ {% for u in object_list %} + -- 2.39.5 From 04e2007c3a76ff36882b2835dc5a3ed3e423fec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Sun, 15 Oct 2023 19:55:23 +0200 Subject: [PATCH 6/6] =?UTF-8?q?(sifrovacka)=20M=C3=A9n=C4=9B=20=C5=99?= =?UTF-8?q?=C3=A1dk=C5=AF=20v=20tajence=20v=20=C3=BA=C4=8Dastnick=C3=A9m?= =?UTF-8?q?=20formul=C3=A1=C5=99i=20(bez=20diakritiky=20bylo=20p=C5=99id?= =?UTF-8?q?=C3=A1no=20u=C5=BE=20v=20p=C5=99edchoz=C3=ADm=20commitu)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sifrovacka/forms.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sifrovacka/forms.py b/sifrovacka/forms.py index 06edaba6..e3eba7c7 100644 --- a/sifrovacka/forms.py +++ b/sifrovacka/forms.py @@ -1,5 +1,5 @@ from django.core.exceptions import ValidationError -from django.forms import ModelForm +from django.forms import ModelForm, Textarea from .models import OdpovedUcastnika, SpravnaOdpoved @@ -7,6 +7,9 @@ class SifrovackaForm(ModelForm): class Meta: model = OdpovedUcastnika fields = ["sifra", "odpoved", ] + widgets = { + "odpoved": Textarea(attrs={'rows': 1, 'cols': 30}), + } def clean_sifra(self): sifra = self.cleaned_data.get('sifra') -- 2.39.5
Timestamp Řešitel Šifra Odpověď
{{ u.timestamp }} {{ u.resitel }} {{ u.sifra }} {{ u.odpoved }}