Admin | Vylepseno zverejnovani cisel.
Vsechny problematicke problemy se zobrazi naraz. Cislo lze zverejnit vcetne problemu pomoci akce z admina.
This commit is contained in:
parent
d257c1858a
commit
c6e6a54760
1 changed files with 34 additions and 6 deletions
|
@ -8,6 +8,7 @@ from polymorphic.admin import PolymorphicParentModelAdmin, PolymorphicChildModel
|
||||||
from reversion.admin import VersionAdmin
|
from reversion.admin import VersionAdmin
|
||||||
from django_reverse_admin import ReverseModelAdmin
|
from django_reverse_admin import ReverseModelAdmin
|
||||||
from solo.admin import SingletonModelAdmin
|
from solo.admin import SingletonModelAdmin
|
||||||
|
from django.utils.safestring import mark_safe
|
||||||
|
|
||||||
|
|
||||||
# Todo: reversion
|
# Todo: reversion
|
||||||
|
@ -23,33 +24,60 @@ class CisloForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = m.Cislo
|
model = m.Cislo
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
print("Cleaning...")
|
|
||||||
print(self.cleaned_data)
|
|
||||||
if self.cleaned_data.get('verejne_db') == False:
|
if self.cleaned_data.get('verejne_db') == False:
|
||||||
return self.cleaned_data
|
return self.cleaned_data
|
||||||
cn = m.CisloNode.objects.get(cislo=self.instance)
|
cn = m.CisloNode.objects.get(cislo=self.instance)
|
||||||
|
errors = []
|
||||||
for ch in tl.all_children(cn):
|
for ch in tl.all_children(cn):
|
||||||
if isinstance(ch, m.TemaVCisleNode):
|
if isinstance(ch, m.TemaVCisleNode):
|
||||||
if ch.tema.stav not in \
|
if ch.tema.stav not in \
|
||||||
(m.Problem.STAV_ZADANY, m.Problem.STAV_VYRESENY):
|
(m.Problem.STAV_ZADANY, m.Problem.STAV_VYRESENY):
|
||||||
raise ValidationError('Téma %(tema)s není zadané ani vyřešené', params={'tema':ch.tema})
|
errors.append(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 isinstance(ch, m.UlohaZadaniNode) or isinstance(ch, m.UlohaVzorakNode):
|
||||||
if ch.uloha.stav not in \
|
if ch.uloha.stav not in \
|
||||||
(m.Problem.STAV_ZADANY, m.Problem.STAV_VYRESENY):
|
(m.Problem.STAV_ZADANY, m.Problem.STAV_VYRESENY):
|
||||||
raise ValidationError('Úloha %(uloha)s není zadaná ani vyřešená', params={'uloha':ch.uloha})
|
errors.append(ValidationError('Úloha %(uloha)s není zadaná ani vyřešená', params={'uloha':ch.uloha}))
|
||||||
if isinstance(ch, m.ReseniNode):
|
if isinstance(ch, m.ReseniNode):
|
||||||
for problem in ch.reseni.problem_set:
|
for problem in ch.reseni.problem_set:
|
||||||
if problem not in \
|
if problem not in \
|
||||||
(m.Problem.STAV_ZADANY, m.Problem.STAV_VYRESENY):
|
(m.Problem.STAV_ZADANY, m.Problem.STAV_VYRESENY):
|
||||||
raise ValidationError('Problém %s není zadaný ani vyřešený', code=problem)
|
errors.append(ValidationError('Problém %s není zadaný ani vyřešený', code=problem))
|
||||||
|
if errors:
|
||||||
|
errors.append(ValidationError(mark_safe('<b>Pokud chceš učinit všechny problémy, co nejsou zadané ani vyřešené, zadanými a číslo zveřejnit, můžeš to udělat pomocí akce v <a href="/admin/seminar/cislo">seznamu čísel</a></b>')))
|
||||||
|
raise ValidationError(errors)
|
||||||
return self.cleaned_data
|
return self.cleaned_data
|
||||||
|
|
||||||
|
|
||||||
@admin.register(m.Cislo)
|
@admin.register(m.Cislo)
|
||||||
class CisloAdmin(admin.ModelAdmin):
|
class CisloAdmin(admin.ModelAdmin):
|
||||||
form = CisloForm
|
form = CisloForm
|
||||||
|
actions = ['force_publish']
|
||||||
|
|
||||||
|
def force_publish(self,request,queryset):
|
||||||
|
for cislo in queryset:
|
||||||
|
cn = m.CisloNode.objects.get(cislo=cislo)
|
||||||
|
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):
|
||||||
|
ch.tema.stav = m.Problem.STAV_ZADANY
|
||||||
|
ch.tema.save()
|
||||||
|
|
||||||
|
if isinstance(ch, m.UlohaZadaniNode) or isinstance(ch, m.UlohaVzorakNode):
|
||||||
|
if ch.uloha.stav not in (m.Problem.STAV_ZADANY, m.Problem.STAV_VYRESENY):
|
||||||
|
ch.uloha.stav = m.Problem.STAV_ZADANY
|
||||||
|
ch.uloha.save()
|
||||||
|
if isinstance(ch, m.ReseniNode):
|
||||||
|
for problem in ch.reseni.problem_set:
|
||||||
|
if problem not in (m.Problem.STAV_ZADANY, m.Problem.STAV_VYRESENY):
|
||||||
|
problem.stav = m.Problem.STAV_ZADANY
|
||||||
|
problem.save()
|
||||||
|
cislo.verejne_db = True
|
||||||
|
cislo.save()
|
||||||
|
|
||||||
|
force_publish.short_description = 'Zveřejnit vybraná čísla a všechny návrhy úloh v nich učinit zadanými'
|
||||||
|
|
||||||
@admin.register(m.Osoba)
|
@admin.register(m.Osoba)
|
||||||
class OsobaAdmin(admin.ModelAdmin):
|
class OsobaAdmin(admin.ModelAdmin):
|
||||||
|
|
Loading…
Reference in a new issue