|
|
@ -21,6 +21,7 @@ class ResitelInline(admin.TabularInline): |
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
@ -29,6 +30,7 @@ class CisloInline(admin.TabularInline): |
|
|
|
fields = ['cislo', 'datum_vydani', 'datum_deadline', 'verejne_db', 'poznamka'] |
|
|
|
readonly_fields = ['cislo'] |
|
|
|
extra = 0 |
|
|
|
|
|
|
|
def has_add_permission(self, req): return False |
|
|
|
|
|
|
|
|
|
|
@ -36,6 +38,7 @@ class PrilohaReseniInline(admin.StackedInline): |
|
|
|
model = PrilohaReseni |
|
|
|
fields = ['timestamp', 'soubor', 'poznamka'] |
|
|
|
readonly_fields = ['timestamp'] |
|
|
|
|
|
|
|
extra = 0 |
|
|
|
|
|
|
|
|
|
|
@ -46,14 +49,39 @@ class ReseniKProblemuInline(admin.TabularInline): |
|
|
|
readonly_fields = ['timestamp'] |
|
|
|
extra = 0 |
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
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']) |
|
|
@ -78,6 +106,10 @@ class ResitelAdmin(reversion.VersionAdmin): |
|
|
|
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') |
|
|
|
|
|
|
|
admin.site.register(Resitel, ResitelAdmin) |
|
|
|
|
|
|
|
|
|
|
@ -108,6 +140,9 @@ class CisloAdmin(reversion.VersionAdmin): |
|
|
|
list_display = ['kod', 'rocnik', 'cislo', 'datum_vydani', 'datum_deadline', 'verejne'] |
|
|
|
list_filter = ['rocnik'] |
|
|
|
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) |
|
|
|
|
|
|
@ -149,20 +184,27 @@ class ReseniAdmin(reversion.VersionAdmin): |
|
|
|
(u'Poznámky', {'fields': ['poznamka']}), |
|
|
|
] |
|
|
|
readonly_fields = ['timestamp'] |
|
|
|
list_display = ['problem', 'resitel', 'forma', 'body', 'timestamp'] |
|
|
|
list_display = ['problem', 'resitel', 'forma', 'body', 'timestamp', 'cislo_body'] |
|
|
|
list_filter = ['body', 'timestamp', 'forma'] |
|
|
|
search_fields = [] |
|
|
|
inlines = [PrilohaReseniInline] |
|
|
|
|
|
|
|
def get_queryset(self, request): |
|
|
|
qs = super(ReseniAdmin, self).get_queryset(request) |
|
|
|
return qs.select_related('resitel', 'problem', 'cislo_body') |
|
|
|
|
|
|
|
admin.site.register(Reseni, ReseniAdmin) |
|
|
|
|
|
|
|
|
|
|
|
### Problem |
|
|
|
|
|
|
|
from autocomplete_light.contrib.taggit_field import TaggitField, TaggitWidget |
|
|
|
|
|
|
|
#TODO: Autocomplete autor/opravovatel |
|
|
|
class ProblemAdminForm(forms.ModelForm): |
|
|
|
text_problemu = forms.CharField(widget=CKEditorWidget()) |
|
|
|
text_problemu_org = forms.CharField(widget=CKEditorWidget()) |
|
|
|
zamereni = TaggitField(widget=TaggitWidget('TagAutocomplete')) |
|
|
|
class Meta: |
|
|
|
model = Problem |
|
|
|
exclude = [] |
|
|
@ -182,6 +224,11 @@ class ProblemAdmin(reversion.VersionAdmin): |
|
|
|
inlines = [ReseniKProblemuInline] |
|
|
|
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') |
|
|
|
|
|
|
|
|
|
|
|
admin.site.register(Problem, ProblemAdmin) |
|
|
|
|
|
|
|
|
|
|
|