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