Admin | Nedovolit zverejnit cislo, kdyz nejou zverejnene problemy.
This commit is contained in:
parent
a6cf928471
commit
8b37035bf3
1 changed files with 35 additions and 2 deletions
|
@ -1,7 +1,8 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.auth.models import Group
|
from django.contrib.auth.models import Group
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.forms import widgets
|
from django.forms import widgets, ModelForm
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
from polymorphic.admin import PolymorphicParentModelAdmin, PolymorphicChildModelAdmin, PolymorphicChildModelFilter
|
from polymorphic.admin import PolymorphicParentModelAdmin, PolymorphicChildModelAdmin, PolymorphicChildModelFilter
|
||||||
from reversion.admin import VersionAdmin
|
from reversion.admin import VersionAdmin
|
||||||
|
@ -12,11 +13,43 @@ from solo.admin import SingletonModelAdmin
|
||||||
# Todo: reversion
|
# Todo: reversion
|
||||||
|
|
||||||
import seminar.models as m
|
import seminar.models as m
|
||||||
|
import seminar.treelib as tl
|
||||||
|
|
||||||
admin.site.register(m.Skola)
|
admin.site.register(m.Skola)
|
||||||
admin.site.register(m.Prijemce)
|
admin.site.register(m.Prijemce)
|
||||||
admin.site.register(m.Rocnik)
|
admin.site.register(m.Rocnik)
|
||||||
admin.site.register(m.Cislo)
|
|
||||||
|
class CisloForm(ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = m.Cislo
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
print("Cleaning...")
|
||||||
|
print(self.cleaned_data)
|
||||||
|
if self.cleaned_data.get('verejne_db') == False:
|
||||||
|
return self.cleaned_data
|
||||||
|
cn = m.CisloNode.objects.get(cislo=self.instance)
|
||||||
|
for ch in tl.all_children(cn):
|
||||||
|
if isinstance(ch, m.TemaVCisleNode):
|
||||||
|
if ch.tema.stav not in \
|
||||||
|
(m.Problem.STAV_ZADANY, m.Problem.STAV_VYRESENY):
|
||||||
|
raise ValidationError('Téma %(tema)s není zadané ani vyřešené', params={'tema':ch.tema})
|
||||||
|
|
||||||
|
if isinstance(ch, m.UlohaZadaniNode) or isinstance(ch, m.UlohaVzorakNode):
|
||||||
|
if ch.uloha.stav not in \
|
||||||
|
(m.Problem.STAV_ZADANY, m.Problem.STAV_VYRESENY):
|
||||||
|
raise ValidationError('Úloha %(uloha)s není zadaná ani vyřešená', params={'uloha':ch.uloha})
|
||||||
|
if isinstance(ch, m.ReseniNode):
|
||||||
|
for problem in ch.reseni.problem_set:
|
||||||
|
if problem not in \
|
||||||
|
(m.Problem.STAV_ZADANY, m.Problem.STAV_VYRESENY):
|
||||||
|
raise ValidationError('Problém %s není zadaný ani vyřešený', code=problem)
|
||||||
|
return self.cleaned_data
|
||||||
|
|
||||||
|
@admin.register(m.Cislo)
|
||||||
|
class CisloAdmin(admin.ModelAdmin):
|
||||||
|
form = CisloForm
|
||||||
|
|
||||||
@admin.register(m.Osoba)
|
@admin.register(m.Osoba)
|
||||||
class OsobaAdmin(admin.ModelAdmin):
|
class OsobaAdmin(admin.ModelAdmin):
|
||||||
|
|
Loading…
Reference in a new issue