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..e3eba7c7 --- /dev/null +++ b/sifrovacka/forms.py @@ -0,0 +1,18 @@ +from django.core.exceptions import ValidationError +from django.forms import ModelForm, Textarea +from .models import OdpovedUcastnika, SpravnaOdpoved + + +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') + 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 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/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/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..05dd6e4c --- /dev/null +++ b/sifrovacka/models.py @@ -0,0 +1,23 @@ +from django.db import models +from django.utils import timezone + +from seminar.models.personalni import Resitel + + +# Create your models here. + + +class OdpovedUcastnika(models.Model): + class Meta: + ordering = ["-timestamp"] + + resitel = models.ForeignKey(Resitel, blank=False, null=False, on_delete=models.CASCADE) + 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): + 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..cc52a584 --- /dev/null +++ b/sifrovacka/templates/sifrovacka/odpovedi_list.html @@ -0,0 +1,25 @@ +{% extends "base.html" %} + +{% block content %} + +
Timestamp | +Řešitel | +Šifra | +Odpověď | +
---|---|---|---|
{{ u.timestamp }} | +{{ u.resitel }} | +{{ u.sifra }} | +{{ u.odpoved }} | +