Návrh na webappku na šifrovačku (na Sklené)
This commit is contained in:
parent
aff9a39262
commit
1aa389414d
13 changed files with 199 additions and 0 deletions
|
@ -154,6 +154,7 @@ INSTALLED_APPS = (
|
|||
'soustredeni',
|
||||
'treenode',
|
||||
'vyroci',
|
||||
'sifrovacka',
|
||||
|
||||
# Admin upravy:
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
0
sifrovacka/__init__.py
Normal file
0
sifrovacka/__init__.py
Normal file
8
sifrovacka/admin.py
Normal file
8
sifrovacka/admin.py
Normal file
|
@ -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)
|
5
sifrovacka/apps.py
Normal file
5
sifrovacka/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class SifrovackaConfig(AppConfig):
|
||||
name = 'sifrovacka'
|
15
sifrovacka/forms.py
Normal file
15
sifrovacka/forms.py
Normal file
|
@ -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
|
34
sifrovacka/migrations/0001_initial.py
Normal file
34
sifrovacka/migrations/0001_initial.py
Normal file
|
@ -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
sifrovacka/migrations/__init__.py
Normal file
0
sifrovacka/migrations/__init__.py
Normal file
18
sifrovacka/models.py
Normal file
18
sifrovacka/models.py
Normal file
|
@ -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,)
|
23
sifrovacka/templates/sifrovacka/odpovedi_list.html
Normal file
23
sifrovacka/templates/sifrovacka/odpovedi_list.html
Normal file
|
@ -0,0 +1,23 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h1>{% block nadpis1a %}Šifrovačka odpovědi{% endblock nadpis1a %}</h1>
|
||||
|
||||
<table class="dosla_reseni">
|
||||
<tr>
|
||||
<th>Řešitel</th>
|
||||
<th>Šifra</th>
|
||||
<th>Odpověď</th>
|
||||
</tr>
|
||||
|
||||
{% for u in object_list %}
|
||||
<tr>
|
||||
<td>{{ u.resitel }}</td>
|
||||
<td>{{ u.sifra }}</td>
|
||||
<td>{{ u.odpoved }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
{% endblock content %}
|
46
sifrovacka/templates/sifrovacka/sifrovacka.html
Normal file
46
sifrovacka/templates/sifrovacka/sifrovacka.html
Normal file
|
@ -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>
|
||||
</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 %}
|
17
sifrovacka/urls.py
Normal file
17
sifrovacka/urls.py
Normal file
|
@ -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'
|
||||
),
|
||||
]
|
30
sifrovacka/views.py
Normal file
30
sifrovacka/views.py
Normal file
|
@ -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'<p>Bohužel vám hvězdy nebyly nakloněny.</p> <p><a href="{reverse("sifrovacka")}">Zkusit znovu.</a></p><br><br><br>')
|
||||
|
||||
return formularOKView(self.request, f'<p>{sifra.skryty_text}</p> <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 a new issue