Browse Source

Model pro deadline

pull/3/head
Jonas Havelka 2 years ago
parent
commit
342c791700
  1. 15
      deploy_v2/admin_org_prava.json
  2. 9
      seminar/admin.py
  3. 72
      seminar/migrations/0103_deadline.py
  4. 39
      seminar/models/tvorba.py

15
deploy_v2/admin_org_prava.json

@ -633,5 +633,20 @@
"codename": "view_fotkaurlvazba", "codename": "view_fotkaurlvazba",
"ct_app_label": "header_fotky", "ct_app_label": "header_fotky",
"ct_model": "fotkaurlvazba" "ct_model": "fotkaurlvazba"
},
{
"codename": "add_deadline",
"ct_app_label": "seminar",
"ct_model": "deadline"
},
{
"codename": "change_deadline",
"ct_app_label": "seminar",
"ct_model": "deadline"
},
{
"codename": "view_deadline",
"ct_app_label": "seminar",
"ct_model": "deadline"
} }
] ]

9
seminar/admin.py

@ -15,6 +15,14 @@ import seminar.models as m
admin.site.register(m.Rocnik) admin.site.register(m.Rocnik)
admin.site.register(m.Deadline)
class DeadlineAdminInline(admin.TabularInline):
model = m.Deadline
extra = 0
class CisloForm(ModelForm): class CisloForm(ModelForm):
class Meta: class Meta:
model = m.Cislo model = m.Cislo
@ -65,6 +73,7 @@ class CisloForm(ModelForm):
class CisloAdmin(admin.ModelAdmin): class CisloAdmin(admin.ModelAdmin):
form = CisloForm form = CisloForm
actions = ['force_publish'] actions = ['force_publish']
inlines = (DeadlineAdminInline,)
def force_publish(self,request,queryset): def force_publish(self,request,queryset):
for cislo in queryset: for cislo in queryset:

72
seminar/migrations/0103_deadline.py

@ -0,0 +1,72 @@
# Generated by Django 3.2.15 on 2022-10-01 08:44
import datetime
from django.db import migrations, models
import django.db.models.deletion
from django.utils import timezone
import seminar.models as m
def vytvor_deadliny(apps, schema_editor):
Cislo = apps.get_model('seminar', 'Cislo')
Deadline = apps.get_model('seminar', 'Deadline')
for cislo in Cislo.objects.all():
if cislo.datum_deadline_soustredeni and cislo.datum_deadline_soustredeni == cislo.datum_preddeadline:
d = Deadline()
d.cislo = cislo
d.typ = m.Deadline.TYP_PRVNI_A_SOUS
d.deadline = timezone.make_aware(datetime.datetime.combine(cislo.datum_deadline_soustredeni, datetime.time.max))
d.verejna_vysledkovka = cislo.verejna_vysledkovka
d.save()
else:
if cislo.datum_deadline_soustredeni:
d = Deadline()
d.cislo = cislo
d.typ = m.Deadline.TYP_SOUS
d.deadline = timezone.make_aware(datetime.datetime.combine(cislo.datum_deadline_soustredeni, datetime.time.max))
d.verejna_vysledkovka = cislo.verejna_vysledkovka
d.save()
if cislo.datum_preddeadline:
d = Deadline()
d.cislo = cislo
d.typ = m.Deadline.TYP_PRVNI
d.deadline = timezone.make_aware(datetime.datetime.combine(cislo.datum_preddeadline, datetime.time.max))
d.verejna_vysledkovka = cislo.verejna_vysledkovka
d.save()
if cislo.datum_deadline:
d = Deadline()
d.cislo = cislo
d.typ = m.Deadline.TYP_CISLA
d.deadline = timezone.make_aware(datetime.datetime.combine(cislo.datum_deadline, datetime.time.max))
d.verejna_vysledkovka = cislo.verejna_vysledkovka
d.save()
class Migration(migrations.Migration):
dependencies = [
('seminar', '0102_osoba_jak_se_dozvedeli'),
]
operations = [
migrations.CreateModel(
name='Deadline',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('deadline', models.DateTimeField(default=timezone.make_aware(datetime.datetime.combine(timezone.now(), datetime.time.max)))),
('typ', models.CharField(choices=[('cisla', 'Deadline celého čísla'), ('prvni', 'První deadline'), ('prvniasous', 'Sousový a první deadline'), ('sous', 'Sousový deadline')], max_length=32, verbose_name='typ deadlinu')),
('verejna_vysledkovka', models.BooleanField(db_column='verejna_vysledkovka', default=False, verbose_name='veřejná výsledkovka')),
('cislo', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='deadline_v_cisle', to='seminar.cislo', verbose_name='deadline v čísle')),
],
options={
'verbose_name': 'Deadline',
'verbose_name_plural': 'Deadliny',
'db_table': 'seminar_deadliny',
'ordering': ['deadline'],
},
),
migrations.RunPython(vytvor_deadliny, migrations.RunPython.noop),
]

39
seminar/models/tvorba.py

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import datetime
import os import os
import subprocess import subprocess
import pathlib import pathlib
@ -328,6 +329,44 @@ class Cislo(SeminarModelBase):
raise ValidationError({'datum_deadline_soustredeni': "Soustřeďkový deadline musí předcházet finálnímu deadlinu"}) raise ValidationError({'datum_deadline_soustredeni': "Soustřeďkový deadline musí předcházet finálnímu deadlinu"})
class Deadline(SeminarModelBase):
class Meta:
db_table = 'seminar_deadliny'
verbose_name = 'Deadline'
verbose_name_plural = 'Deadliny'
ordering = ['deadline']
id = models.AutoField(primary_key=True)
deadline = models.DateTimeField(blank=False, default=timezone.make_aware(datetime.datetime.combine(timezone.now(), datetime.time.max)))
cislo = models.ForeignKey(Cislo, verbose_name='deadline v čísle',
related_name='deadline_v_cisle', blank=False,
on_delete=models.CASCADE)
TYP_CISLA = 'cisla'
TYP_PRVNI_A_SOUS = 'prvniasous'
TYP_PRVNI = 'prvni'
TYP_SOUS = 'sous'
TYP_CHOICES = [
(TYP_CISLA, 'Deadline celého čísla'),
(TYP_PRVNI, 'První deadline'),
(TYP_PRVNI_A_SOUS, 'Sousový a první deadline'),
(TYP_SOUS, 'Sousový deadline'),
]
CHOICES_MAP = dict(TYP_CHOICES)
typ = models.CharField('typ deadlinu', max_length=32,
choices=TYP_CHOICES, blank=False)
verejna_vysledkovka = models.BooleanField('veřejná výsledkovka',
db_column='verejna_vysledkovka',
default=False)
def __str__(self):
return self.CHOICES_MAP[self.typ] + " " + str(self.cislo)
@reversion.register(ignore_duplicates=True) @reversion.register(ignore_duplicates=True)
# Pozor na následující řádek. *Nekrmit, asi kouše!* # Pozor na následující řádek. *Nekrmit, asi kouše!*
class Problem(SeminarModelBase,PolymorphicModel): class Problem(SeminarModelBase,PolymorphicModel):

Loading…
Cancel
Save