„Cachování“ výsledkovek čísla
This commit is contained in:
parent
f720bf15e0
commit
b06642e4ba
4 changed files with 71 additions and 1 deletions
|
@ -14,6 +14,7 @@ import seminar.models as m
|
||||||
admin.site.register(m.Rocnik)
|
admin.site.register(m.Rocnik)
|
||||||
|
|
||||||
admin.site.register(m.Deadline)
|
admin.site.register(m.Deadline)
|
||||||
|
admin.site.register(m.ZmrazenaVysledkovka)
|
||||||
|
|
||||||
|
|
||||||
class DeadlineAdminInline(admin.TabularInline):
|
class DeadlineAdminInline(admin.TabularInline):
|
||||||
|
|
26
seminar/migrations/0107_zmrazenavysledkovka.py
Normal file
26
seminar/migrations/0107_zmrazenavysledkovka.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
# Generated by Django 3.2.15 on 2022-10-10 07:23
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('seminar', '0106_remove_cislo_verejna_vysledkovka'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='ZmrazenaVysledkovka',
|
||||||
|
fields=[
|
||||||
|
('deadline', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, related_name='vysledkovka_v_deadlinu', serialize=False, to='seminar.deadline')),
|
||||||
|
('html', models.TextField()),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'Zmražená výsledkovka',
|
||||||
|
'verbose_name_plural': 'Zmražené výsledkovky',
|
||||||
|
'db_table': 'seminar_vysledkovky',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
|
@ -9,6 +9,7 @@ import logging
|
||||||
from django.contrib.sites.shortcuts import get_current_site
|
from django.contrib.sites.shortcuts import get_current_site
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
from django.template.loader import render_to_string
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
@ -321,6 +322,10 @@ class Deadline(SeminarModelBase):
|
||||||
verbose_name_plural = 'Deadliny'
|
verbose_name_plural = 'Deadliny'
|
||||||
ordering = ['deadline']
|
ordering = ['deadline']
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.__original_verejna_vysledkovka = self.verejna_vysledkovka
|
||||||
|
|
||||||
id = models.AutoField(primary_key=True)
|
id = models.AutoField(primary_key=True)
|
||||||
|
|
||||||
deadline = models.DateTimeField(blank=False, default=timezone.make_aware(datetime.datetime.combine(timezone.now(), datetime.time.max)))
|
deadline = models.DateTimeField(blank=False, default=timezone.make_aware(datetime.datetime.combine(timezone.now(), datetime.time.max)))
|
||||||
|
@ -350,6 +355,40 @@ class Deadline(SeminarModelBase):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.CHOICES_MAP[self.typ] + " " + str(self.cislo)
|
return self.CHOICES_MAP[self.typ] + " " + str(self.cislo)
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
super().save(*args, **kwargs)
|
||||||
|
if self.verejna_vysledkovka and not self.__original_verejna_vysledkovka:
|
||||||
|
self.vygeneruj_vysledkovku()
|
||||||
|
|
||||||
|
def vygeneruj_vysledkovku(self):
|
||||||
|
from vysledkovky.utils import VysledkovkaCisla
|
||||||
|
if hasattr(self, "vysledkovka_v_deadlinu"):
|
||||||
|
self.vysledkovka_v_deadlinu.delete()
|
||||||
|
vysledkovka = VysledkovkaCisla(self.cislo, jen_verejne=True, do_deadlinu=self)
|
||||||
|
if len(vysledkovka.radky_vysledkovky) != 0:
|
||||||
|
ZmrazenaVysledkovka.objects.create(
|
||||||
|
deadline=self,
|
||||||
|
html=render_to_string(
|
||||||
|
"vysledkovky/vysledkovka_cisla.html",
|
||||||
|
context={"vysledkovka": vysledkovka, "oznaceni_vysledkovky": self.id}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ZmrazenaVysledkovka(SeminarModelBase):
|
||||||
|
class Meta:
|
||||||
|
db_table = 'seminar_vysledkovky'
|
||||||
|
verbose_name = 'Zmražená výsledkovka'
|
||||||
|
verbose_name_plural = 'Zmražené výsledkovky'
|
||||||
|
|
||||||
|
deadline = models.OneToOneField(
|
||||||
|
Deadline,
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
primary_key=True,
|
||||||
|
related_name="vysledkovka_v_deadlinu"
|
||||||
|
)
|
||||||
|
|
||||||
|
html = models.TextField(null=False, blank=False)
|
||||||
|
|
||||||
|
|
||||||
@reversion.register(ignore_duplicates=True)
|
@reversion.register(ignore_duplicates=True)
|
||||||
|
|
|
@ -69,7 +69,7 @@
|
||||||
|
|
||||||
|
|
||||||
{% for deadline, nadpis, vysledkovka in deadliny_s_vysledkovkami %}
|
{% for deadline, nadpis, vysledkovka in deadliny_s_vysledkovkami %}
|
||||||
{% if vysledkovka.radky_vysledkovky %}
|
{% if deadline.vysledkovka_v_deadlinu or vysledkovka.radky_vysledkovky %}
|
||||||
|
|
||||||
{% if not deadline.verejna_vysledkovka %}
|
{% if not deadline.verejna_vysledkovka %}
|
||||||
<div class='mam-org-only'>
|
<div class='mam-org-only'>
|
||||||
|
@ -78,7 +78,11 @@
|
||||||
<h2>{{ nadpis }}</h2>
|
<h2>{{ nadpis }}</h2>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if deadline.vysledkovka_v_deadlinu %}
|
||||||
|
{{ deadline.vysledkovka_v_deadlinu.html | safe }}
|
||||||
|
{% else %}
|
||||||
{% include "vysledkovky/vysledkovka_cisla.html" with oznaceni_vysledkovky=forloop.counter %}
|
{% include "vysledkovky/vysledkovka_cisla.html" with oznaceni_vysledkovky=forloop.counter %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if not deadline.verejna_vysledkovka %}
|
{% if not deadline.verejna_vysledkovka %}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue