14 changed files with 237 additions and 0 deletions
@ -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) |
@ -0,0 +1,5 @@ |
|||
from django.apps import AppConfig |
|||
|
|||
|
|||
class SifrovackaConfig(AppConfig): |
|||
name = 'sifrovacka' |
@ -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 |
@ -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')), |
|||
], |
|||
), |
|||
] |
@ -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'), |
|||
), |
|||
] |
@ -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) |
|||
ledoian marked this conversation as resolved
|
|||
|
|||
|
|||
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,) |
@ -0,0 +1,25 @@ |
|||
{% extends "base.html" %} |
|||
|
|||
{% block content %} |
|||
|
|||
<h1>{% block nadpis1a %}Šifrovačka odpovědi{% endblock nadpis1a %}</h1> |
|||
|
|||
<table class="dosla_reseni"> |
|||
<tr> |
|||
<th>Timestamp</th> |
|||
<th>Řešitel</th> |
|||
<th>Šifra</th> |
|||
<th>Odpověď</th> |
|||
</tr> |
|||
|
|||
{% for u in object_list %} |
|||
<tr> |
|||
<td>{{ u.timestamp }}</td> |
|||
<td>{{ u.resitel }}</td> |
|||
<td>{{ u.sifra }}</td> |
|||
<td>{{ u.odpoved }}</td> |
|||
</tr> |
|||
{% endfor %} |
|||
</table> |
|||
|
|||
{% endblock content %} |
@ -0,0 +1,46 @@ |
|||
{% extends "base.html" %} |
|||
|
|||
{% block content %} |
|||
|
|||
<br> |
|||
|
|||
<h1>{% block nadpis1a %}M&Mí šifrovačka{% endblock nadpis1a %}</h1> |
|||
|
|||
<br> |
|||
|
|||
<h2>Zadat tajenku šifry:</h2> |
|||
|
|||
<form action="{% url 'sifrovacka' %}" method="post"> |
|||
<table class="form"> |
|||
{{form.non_field_errors}} |
|||
{% for field in form %} |
|||
<tr> |
|||
<td> |
|||
<label class="field-label{% if field.field.required %} field-required{% endif %}" for="{{ field.id_for_label }}"> |
|||
{{ field.label }} |
|||
</label> |
|||
|
|||
</td> |
|||
|
|||
<td {% if field.help_text %} class="field-with-comment"{% endif %}> |
|||
{{ field }} |
|||
<span class="field-comment">{{ field.help_text|safe }}</span> |
|||
ledoian
commented 1 year ago
Review
To
zelvuska
commented 1 year ago
Review
To jsem myslím zkopíroval z výročí :D A určitě to není potřeba. |
|||
</td> |
|||
|
|||
</tr> |
|||
|
|||
|
|||
{% if field.errors %} |
|||
<tr> |
|||
<td colspan="2"><span class="field-error">{{ field.errors }}</span></td> |
|||
</tr> |
|||
{% endif %} |
|||
{% endfor %} |
|||
</table> |
|||
|
|||
{% csrf_token %} |
|||
|
|||
<input type="submit" value="Tak pravím!"> |
|||
</form> |
|||
|
|||
{% endblock content %} |
@ -0,0 +1,17 @@ |
|||
from django.urls import path |
|||
|
|||
from seminar.utils import org_required, resitel_or_org_required |
|||
from .views import SifrovackaView, SifrovackaListView |
|||
|
|||
urlpatterns = [ |
|||
path( |
|||
'', |
|||
resitel_or_org_required(SifrovackaView.as_view()), |
|||
name='sifrovacka' |
|||
), |
|||
path( |
|||
'odpovedi/', |
|||
org_required(SifrovackaListView.as_view()), |
|||
name='sifrovacka_odpovedi' |
|||
), |
|||
] |
@ -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'<h1>Bohužel vám hvězdy nebyly nakloněny. Rozumějte <i>máte to blbě</i>.</h1> <p><a href="{reverse("sifrovacka")}">Zkusit znovu.</a></p><br><br><br>') |
|||
|
|||
return formularOKView(self.request, f'<h1>{sifra.skryty_text}</h1> <p><a href="{reverse("sifrovacka")}">Odevzdat další.</a></p><br><br><br>') |
|||
|
|||
|
|||
class SifrovackaListView(ListView): |
|||
template_name = 'sifrovacka/odpovedi_list.html' |
|||
model = OdpovedUcastnika |
Loading…
Reference in new issue
django.utils.timezone.now()
mi na testwebu dává čas v UTC…Ale v https://mam-test.ks.matfyz.cz/sifrovacka/odpovedi/ a https://mam-test.ks.matfyz.cz/sifrovacka/ se to chová správně
OK what the hell. If it ain't broke…