|
@ -1,31 +1,115 @@ |
|
|
# -*- coding: utf-8 -*- |
|
|
# -*- coding: utf-8 -*- |
|
|
from django.contrib import admin |
|
|
from django.contrib import admin |
|
|
from django import forms |
|
|
from django import forms |
|
|
|
|
|
from django.forms import widgets |
|
|
import reversion |
|
|
import reversion |
|
|
from solo.admin import SingletonModelAdmin |
|
|
from solo.admin import SingletonModelAdmin |
|
|
from ckeditor.widgets import CKEditorWidget |
|
|
from ckeditor.widgets import CKEditorWidget |
|
|
|
|
|
from django.db.models import Count |
|
|
|
|
|
from django.db import models |
|
|
|
|
|
|
|
|
from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni, Soustredeni |
|
|
from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni, Soustredeni, Soustredeni_Ucastnici |
|
|
import autocomplete_light |
|
|
import autocomplete_light |
|
|
### Nastaveni |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Globální nastavení |
|
|
|
|
|
|
|
|
admin.site.register(Nastaveni, SingletonModelAdmin) |
|
|
admin.site.register(Nastaveni, SingletonModelAdmin) |
|
|
|
|
|
|
|
|
### Skola |
|
|
|
|
|
|
|
|
|
|
|
class SkolaAdmin(reversion.VersionAdmin): |
|
|
### INLINES |
|
|
fieldsets = [ |
|
|
|
|
|
(None, {'fields': ['nazev', 'kratky_nazev', 'je_zs', 'je_ss']}), |
|
|
|
|
|
(u'Interní ID', {'fields': ['aesop_id', 'izo'], 'classes': ['collapse']}), |
|
|
|
|
|
(u'Adresa', {'fields': ['ulice', 'mesto', 'psc', 'stat']}), |
|
|
|
|
|
] |
|
|
|
|
|
list_display = ['nazev', 'aesop_id', 'mesto', 'ulice', 'stat', 'je_zs', 'je_ss'] |
|
|
|
|
|
list_filter = ['stat', 'je_zs', 'je_ss'] |
|
|
|
|
|
search_fields = ['nazev', 'mesto', 'ulice'] |
|
|
|
|
|
|
|
|
|
|
|
admin.site.register(Skola, SkolaAdmin) |
|
|
class ResitelInline(admin.TabularInline): |
|
|
|
|
|
model = Resitel |
|
|
|
|
|
fields = ['jmeno', 'prijmeni', 'skola', 'mesto', 'rok_maturity', ] |
|
|
|
|
|
readonly_fields = ['jmeno', 'prijmeni', 'skola', 'mesto', 'rok_maturity', ] |
|
|
|
|
|
extra = 0 |
|
|
|
|
|
|
|
|
|
|
|
def has_add_permission(self, req): return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CisloInline(admin.TabularInline): |
|
|
|
|
|
model = Cislo |
|
|
|
|
|
fields = ['cislo', 'datum_vydani', 'datum_deadline', 'verejne_db', 'poznamka'] |
|
|
|
|
|
readonly_fields = ['cislo'] |
|
|
|
|
|
extra = 0 |
|
|
|
|
|
formfield_overrides = { |
|
|
|
|
|
models.TextField: {'widget': forms.TextInput}, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def has_add_permission(self, req): return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PrilohaReseniInline(admin.StackedInline): |
|
|
|
|
|
model = PrilohaReseni |
|
|
|
|
|
fields = ['timestamp', 'soubor', 'poznamka'] |
|
|
|
|
|
readonly_fields = ['timestamp'] |
|
|
|
|
|
formfield_overrides = { |
|
|
|
|
|
models.TextField: {'widget': forms.TextInput}, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
extra = 0 |
|
|
|
|
|
|
|
|
|
|
|
class ReseniKProblemuInline(admin.TabularInline): |
|
|
|
|
|
form = autocomplete_light.modelform_factory(Reseni, autocomplete_fields=['resitel'], fields=['resitel']) |
|
|
|
|
|
model = Reseni |
|
|
|
|
|
fields = ['resitel', 'forma', 'body', 'cislo_body', 'timestamp', 'poznamka'] |
|
|
|
|
|
readonly_fields = ['timestamp'] |
|
|
|
|
|
extra = 0 |
|
|
|
|
|
formfield_overrides = { |
|
|
|
|
|
models.TextField: {'widget': forms.TextInput}, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def get_queryset(self, request): |
|
|
|
|
|
qs = super(ReseniKProblemuInline, self).get_queryset(request) |
|
|
|
|
|
return qs.select_related('problem', 'cislo_body', 'resitel') |
|
|
|
|
|
|
|
|
|
|
|
# Potenciální DB HOG (cislo_body se dotazovalo na cisla pri kazdem zobrazeni jejich selectu ...) |
|
|
|
|
|
def formfield_for_dbfield(self, db_field, **kwargs): |
|
|
|
|
|
formfield = super(ReseniKProblemuInline, self).formfield_for_dbfield(db_field, **kwargs) |
|
|
|
|
|
if db_field.name == 'cislo_body': |
|
|
|
|
|
# dirty trick so queryset is evaluated and cached in .choices |
|
|
|
|
|
formfield.choices = formfield.choices |
|
|
|
|
|
return formfield |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ReseniKResiteliInline(admin.TabularInline): |
|
|
|
|
|
model = Reseni |
|
|
|
|
|
fields = ['problem', 'forma', 'body', 'cislo_body', 'timestamp', 'poznamka'] |
|
|
|
|
|
readonly_fields = ['timestamp', 'problem'] |
|
|
|
|
|
extra = 0 |
|
|
|
|
|
formfield_overrides = { |
|
|
|
|
|
models.TextField: {'widget': forms.TextInput}, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def has_add_permission(self, req): return False |
|
|
|
|
|
|
|
|
|
|
|
def get_queryset(self, request): |
|
|
|
|
|
qs = super(ReseniKResiteliInline, self).get_queryset(request) |
|
|
|
|
|
return qs.select_related('problem', 'cislo_body', 'resitel') |
|
|
|
|
|
|
|
|
|
|
|
# Potenciální DB HOG (cislo_body se dotazovalo na cisla pri kazdem zobrazeni jejich selectu ...) |
|
|
|
|
|
def formfield_for_dbfield(self, db_field, **kwargs): |
|
|
|
|
|
formfield = super(ReseniKResiteliInline, self).formfield_for_dbfield(db_field, **kwargs) |
|
|
|
|
|
if db_field.name == 'cislo_body': |
|
|
|
|
|
# dirty trick so queryset is evaluated and cached in .choices |
|
|
|
|
|
formfield.choices = formfield.choices |
|
|
|
|
|
return formfield |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Soustredeni_UcastniciInline(admin.TabularInline): |
|
|
|
|
|
form = autocomplete_light.modelform_factory(Soustredeni_Ucastnici, autocomplete_fields=['resitel'], fields=['resitel']) |
|
|
|
|
|
model = Soustredeni_Ucastnici |
|
|
|
|
|
fields = ['resitel', 'poznamka', ] |
|
|
|
|
|
extra = 0 |
|
|
|
|
|
formfield_overrides = { |
|
|
|
|
|
models.TextField: {'widget': forms.TextInput}, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def get_queryset(self, request): |
|
|
|
|
|
qs = super(Soustredeni_UcastniciInline, self).get_queryset(request) |
|
|
|
|
|
return qs.select_related('resitel', 'soustredeni') |
|
|
|
|
|
|
|
|
### Resitel |
|
|
### Resitel |
|
|
|
|
|
|
|
|
class ResitelAdmin(reversion.VersionAdmin): |
|
|
class ResitelAdmin(reversion.VersionAdmin): |
|
@ -37,33 +121,55 @@ class ResitelAdmin(reversion.VersionAdmin): |
|
|
(u'Osobní údaje', {'fields': ['pohlavi_muz', 'datum_narozeni', 'email', 'telefon']}), |
|
|
(u'Osobní údaje', {'fields': ['pohlavi_muz', 'datum_narozeni', 'email', 'telefon']}), |
|
|
(u'Adresa', {'fields': ['ulice', 'mesto', 'psc', 'stat']}), |
|
|
(u'Adresa', {'fields': ['ulice', 'mesto', 'psc', 'stat']}), |
|
|
] |
|
|
] |
|
|
list_display = ['jmeno', 'prijmeni', 'user', 'pohlavi_muz', 'skola', 'rok_maturity'] |
|
|
list_display = ['jmeno', 'prijmeni', 'user', 'pohlavi_muz', 'skola', 'rok_maturity', 'pocet_reseni'] |
|
|
list_filter = ['pohlavi_muz', 'rok_maturity', 'zasilat'] |
|
|
list_filter = ['pohlavi_muz', 'rok_maturity', 'zasilat'] |
|
|
search_fields = ['jmeno', 'prijmeni', 'ulice', 'user', 'mesto', 'email'] |
|
|
search_fields = ['jmeno', 'prijmeni', 'ulice', 'user', 'mesto', 'email'] |
|
|
|
|
|
inlines = [ReseniKResiteliInline] |
|
|
|
|
|
|
|
|
|
|
|
def get_queryset(self, request): |
|
|
|
|
|
qs = super(ResitelAdmin, self).get_queryset(request) |
|
|
|
|
|
return qs.select_related('skola', 'user').annotate(pocet_reseni=Count('reseni')) |
|
|
|
|
|
|
|
|
|
|
|
def pocet_reseni(self, obj): |
|
|
|
|
|
return obj.pocet_reseni |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
admin.site.register(Resitel, ResitelAdmin) |
|
|
admin.site.register(Resitel, ResitelAdmin) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Skola |
|
|
|
|
|
|
|
|
|
|
|
class SkolaAdmin(reversion.VersionAdmin): |
|
|
|
|
|
fieldsets = [ |
|
|
|
|
|
(None, {'fields': ['nazev', 'kratky_nazev', 'je_zs', 'je_ss']}), |
|
|
|
|
|
(u'Interní ID', {'fields': ['aesop_id', 'izo'], 'classes': ['collapse']}), |
|
|
|
|
|
(u'Adresa', {'fields': ['ulice', 'mesto', 'psc', 'stat']}), |
|
|
|
|
|
(None, {'fields': ['poznamka']}), |
|
|
|
|
|
] |
|
|
|
|
|
list_display = ['nazev', 'aesop_id', 'mesto', 'ulice', 'stat', 'je_zs', 'je_ss'] |
|
|
|
|
|
list_filter = ['stat', 'je_zs', 'je_ss'] |
|
|
|
|
|
search_fields = ['nazev', 'mesto', 'ulice'] |
|
|
|
|
|
inlines = [ResitelInline] |
|
|
|
|
|
|
|
|
|
|
|
admin.site.register(Skola, SkolaAdmin) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Cislo |
|
|
### Cislo |
|
|
|
|
|
|
|
|
class CisloAdmin(reversion.VersionAdmin): |
|
|
class CisloAdmin(reversion.VersionAdmin): |
|
|
fieldsets = [ |
|
|
fieldsets = [ |
|
|
(None, {'fields': ['cislo', 'rocnik', 'verejne_db']}), |
|
|
(None, {'fields': ['cislo', 'rocnik', 'verejne_db', 'poznamka']}), |
|
|
(u'Data', {'fields': ['datum_vydani', 'datum_deadline']}), |
|
|
(u'Data', {'fields': ['datum_vydani', 'datum_deadline']}), |
|
|
] |
|
|
] |
|
|
list_display = ['kod', 'rocnik', 'cislo', 'datum_vydani', 'datum_deadline', 'verejne'] |
|
|
list_display = ['kod', 'rocnik', 'cislo', 'datum_vydani', 'datum_deadline', 'verejne'] |
|
|
list_filter = ['rocnik'] |
|
|
list_filter = ['rocnik'] |
|
|
view_on_site = Cislo.verejne_url |
|
|
view_on_site = Cislo.verejne_url |
|
|
|
|
|
def get_queryset(self, request): |
|
|
|
|
|
qs = super(CisloAdmin, self).get_queryset(request) |
|
|
|
|
|
return qs.select_related('rocnik') |
|
|
|
|
|
|
|
|
admin.site.register(Cislo, CisloAdmin) |
|
|
admin.site.register(Cislo, CisloAdmin) |
|
|
|
|
|
|
|
|
class CisloInline(admin.StackedInline): |
|
|
|
|
|
model = Cislo |
|
|
|
|
|
fields = ['cislo', 'datum_vydani', 'datum_deadline', 'verejne_db'] |
|
|
|
|
|
readonly_fields = ['cislo'] |
|
|
|
|
|
extra = 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Rocnik |
|
|
### Rocnik |
|
|
|
|
|
|
|
|
class RocnikAdmin(reversion.VersionAdmin): |
|
|
class RocnikAdmin(reversion.VersionAdmin): |
|
@ -78,55 +184,50 @@ admin.site.register(Rocnik, RocnikAdmin) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### PrilohaReseni |
|
|
### PrilohaReseni |
|
|
|
|
|
# NOTE: Nemá pravděpodobně smysl používat |
|
|
class PrilohaReseniAdmin(reversion.VersionAdmin): |
|
|
# class PrilohaReseniAdmin(reversion.VersionAdmin): |
|
|
readonly_fields = ['timestamp', 'reseni'] |
|
|
# readonly_fields = ['timestamp', 'reseni'] |
|
|
fieldsets = [ |
|
|
# fieldsets = [ |
|
|
(None, {'fields': ['reseni', 'soubor', 'timestamp']}), |
|
|
# (None, {'fields': ['reseni', 'soubor', 'timestamp']}), |
|
|
(u'Poznámky', {'fields': ['poznamka']}), |
|
|
# (u'Poznámky', {'fields': ['poznamka']}), |
|
|
] |
|
|
# ] |
|
|
list_display = ['reseni', 'soubor', 'timestamp'] |
|
|
# list_display = ['reseni', 'soubor', 'timestamp'] |
|
|
list_filter = ['reseni', 'timestamp'] |
|
|
# list_filter = ['reseni', 'timestamp'] |
|
|
search_fields = [] |
|
|
# search_fields = [] |
|
|
|
|
|
# |
|
|
admin.site.register(PrilohaReseni, PrilohaReseniAdmin) |
|
|
# admin.site.register(PrilohaReseni, PrilohaReseniAdmin) |
|
|
|
|
|
|
|
|
class PrilohaReseniInline(admin.StackedInline): |
|
|
|
|
|
model = PrilohaReseni |
|
|
|
|
|
fields = ['timestamp', 'soubor', 'poznamka'] |
|
|
|
|
|
readonly_fields = ['timestamp'] |
|
|
|
|
|
extra = 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Reseni |
|
|
### Reseni |
|
|
|
|
|
|
|
|
class ReseniAdmin(reversion.VersionAdmin): |
|
|
class ReseniAdmin(reversion.VersionAdmin): |
|
|
form = autocomplete_light.modelform_factory(Reseni, autocomplete_fields=['problem'], fields=['problem']) |
|
|
form = autocomplete_light.modelform_factory(Reseni, autocomplete_fields=['problem', 'resitel'], fields=['problem', 'resitel']) |
|
|
fieldsets = [ |
|
|
fieldsets = [ |
|
|
(None, {'fields': ['problem', 'resitel', 'forma', 'body', 'cislo_body', 'timestamp']}), |
|
|
(None, {'fields': ['problem', 'resitel', 'forma', 'body', 'cislo_body', 'timestamp']}), |
|
|
(u'Poznámky', {'fields': ['poznamka']}), |
|
|
(u'Poznámky', {'fields': ['poznamka']}), |
|
|
] |
|
|
] |
|
|
readonly_fields = ['timestamp'] |
|
|
readonly_fields = ['timestamp'] |
|
|
list_display = ['problem', 'resitel', 'forma', 'body', 'timestamp'] |
|
|
list_display = ['problem', 'resitel', 'forma', 'body', 'timestamp', 'cislo_body'] |
|
|
list_filter = ['body', 'timestamp', 'forma'] |
|
|
list_filter = ['body', 'timestamp', 'forma'] |
|
|
search_fields = [] |
|
|
search_fields = [] |
|
|
inlines = [PrilohaReseniInline] |
|
|
inlines = [PrilohaReseniInline] |
|
|
|
|
|
|
|
|
admin.site.register(Reseni, ReseniAdmin) |
|
|
def get_queryset(self, request): |
|
|
|
|
|
qs = super(ReseniAdmin, self).get_queryset(request) |
|
|
|
|
|
return qs.select_related('resitel', 'problem', 'cislo_body') |
|
|
|
|
|
|
|
|
class ReseniInline(admin.TabularInline): |
|
|
admin.site.register(Reseni, ReseniAdmin) |
|
|
model = Reseni |
|
|
|
|
|
fields = ['resitel', 'forma', 'body', 'cislo_body', 'timestamp', 'poznamka'] |
|
|
|
|
|
readonly_fields = ['poznamka', 'resitel', 'timestamp', 'cislo_body', 'resitel', 'forma'] |
|
|
|
|
|
extra = 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Problem |
|
|
### Problem |
|
|
|
|
|
|
|
|
|
|
|
from autocomplete_light.contrib.taggit_field import TaggitField, TaggitWidget |
|
|
|
|
|
|
|
|
#TODO: Autocomplete autor/opravovatel |
|
|
#TODO: Autocomplete autor/opravovatel |
|
|
class ProblemAdminForm(forms.ModelForm): |
|
|
class ProblemAdminForm(forms.ModelForm): |
|
|
text_problemu = forms.CharField(widget=CKEditorWidget()) |
|
|
text_problemu = forms.CharField(widget=CKEditorWidget()) |
|
|
text_problemu_org = forms.CharField(widget=CKEditorWidget()) |
|
|
text_problemu_org = forms.CharField(widget=CKEditorWidget()) |
|
|
|
|
|
zamereni = TaggitField(widget=TaggitWidget('TagAutocomplete')) |
|
|
class Meta: |
|
|
class Meta: |
|
|
model = Problem |
|
|
model = Problem |
|
|
exclude = [] |
|
|
exclude = [] |
|
@ -135,17 +236,24 @@ class ProblemAdmin(reversion.VersionAdmin): |
|
|
form = ProblemAdminForm |
|
|
form = ProblemAdminForm |
|
|
fieldsets = [ |
|
|
fieldsets = [ |
|
|
(None, {'fields': ['nazev', 'typ', 'stav', 'autor', 'zamereni', 'body', 'timestamp']}), |
|
|
(None, {'fields': ['nazev', 'typ', 'stav', 'autor', 'zamereni', 'body', 'timestamp']}), |
|
|
(u'Vydání', {'fields': ['cislo_zadani', 'kod', 'cislo_reseni', 'opravovatel']}), |
|
|
(u'Vydání', {'fields': ['cislo_zadani', 'kod', 'cislo_reseni', 'opravovatel', 'text_problemu']}), |
|
|
(u'Texty', {'fields': ['text_problemu', 'text_problemu_org']}), |
|
|
(None, {'fields': ['text_problemu_org']}), |
|
|
] |
|
|
] |
|
|
readonly_fields = ['timestamp'] |
|
|
readonly_fields = ['timestamp'] |
|
|
list_display = ['nazev', 'typ', 'kod', 'stav', 'autor', 'opravovatel', 'verejne', 'cislo_zadani'] |
|
|
list_display = ['nazev', 'typ', 'kod', 'stav', 'autor', 'opravovatel', 'verejne', 'cislo_zadani', 'pocet_reseni'] |
|
|
list_select_related = True |
|
|
list_select_related = True |
|
|
list_filter = ['typ', 'stav', 'timestamp'] |
|
|
list_filter = ['typ', 'stav', 'timestamp'] |
|
|
search_fields = ['nazev', 'kod', 'text_problemu_org', 'text_problemu'] |
|
|
search_fields = ['nazev', 'kod', 'text_problemu_org', 'text_problemu'] |
|
|
inlines = [ReseniInline] |
|
|
inlines = [ReseniKProblemuInline] |
|
|
view_on_site = Problem.verejne_url |
|
|
view_on_site = Problem.verejne_url |
|
|
|
|
|
|
|
|
|
|
|
def get_queryset(self, request): |
|
|
|
|
|
qs = super(ProblemAdmin, self).get_queryset(request) |
|
|
|
|
|
return qs.select_related('autor', 'opravovatel', 'cislo_zadani', 'cislo_reseni').annotate(pocet_reseni=Count('reseni')) |
|
|
|
|
|
|
|
|
|
|
|
def pocet_reseni(self, obj): |
|
|
|
|
|
return obj.pocet_reseni |
|
|
|
|
|
|
|
|
admin.site.register(Problem, ProblemAdmin) |
|
|
admin.site.register(Problem, ProblemAdmin) |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -157,8 +265,9 @@ class SoustredeniAdmin(reversion.VersionAdmin): |
|
|
(u'Data', {'fields': ['datum_zacatku', 'datum_konce']}), |
|
|
(u'Data', {'fields': ['datum_zacatku', 'datum_konce']}), |
|
|
] |
|
|
] |
|
|
list_display = ['rocnik', 'misto', 'datum_zacatku', 'verejne'] |
|
|
list_display = ['rocnik', 'misto', 'datum_zacatku', 'verejne'] |
|
|
|
|
|
inlines = [Soustredeni_UcastniciInline] |
|
|
list_filter = ['rocnik'] |
|
|
list_filter = ['rocnik'] |
|
|
view_on_site = Soustredeni.verejne_url |
|
|
view_on_site = Soustredeni.verejne_url |
|
|
# TODO: UcastNaSoustredeni jako inline |
|
|
|
|
|
|
|
|
|
|
|
admin.site.register(Soustredeni, SoustredeniAdmin) |
|
|
admin.site.register(Soustredeni, SoustredeniAdmin) |
|
|
|
|
|
|
|
|