|
@ -23,6 +23,19 @@ def field_labels(model, fieldname): |
|
|
f = [i for i in model._meta.fields if i.name == fieldname][0] |
|
|
f = [i for i in model._meta.fields if i.name == fieldname][0] |
|
|
return {'label': f.verbose_name.capitalize(), 'help_text': f.help_text, } |
|
|
return {'label': f.verbose_name.capitalize(), 'help_text': f.help_text, } |
|
|
|
|
|
|
|
|
|
|
|
def create_modeladmin(modeladmin, model, name = None, verbose_name = None, verbose_name_plural = None): |
|
|
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
|
|
proxy = True |
|
|
|
|
|
app_label = model._meta.app_label |
|
|
|
|
|
Meta.verbose_name = verbose_name |
|
|
|
|
|
Meta.verbose_name_plural = verbose_name_plural |
|
|
|
|
|
|
|
|
|
|
|
attrs = {'__module__': '', 'Meta': Meta} |
|
|
|
|
|
newmodel = type(name, (model,), attrs) |
|
|
|
|
|
admin.site.register(newmodel, modeladmin) |
|
|
|
|
|
return modeladmin |
|
|
|
|
|
|
|
|
### INLINES |
|
|
### INLINES |
|
|
|
|
|
|
|
|
class ResitelInline(admin.TabularInline): |
|
|
class ResitelInline(admin.TabularInline): |
|
@ -231,6 +244,7 @@ admin.site.register(Reseni, ReseniAdmin) |
|
|
from autocomplete_light.contrib.taggit_field import TaggitField, TaggitWidget |
|
|
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_zadani = forms.CharField(widget=CKEditorWidget(), **field_labels(Problem, 'text_zadani')) |
|
|
text_zadani = forms.CharField(widget=CKEditorWidget(), **field_labels(Problem, 'text_zadani')) |
|
|
text_reseni = forms.CharField(widget=CKEditorWidget(), **field_labels(Problem, 'text_reseni')) |
|
|
text_reseni = forms.CharField(widget=CKEditorWidget(), **field_labels(Problem, 'text_reseni')) |
|
@ -248,22 +262,39 @@ class ProblemAdmin(reversion.VersionAdmin): |
|
|
(None, {'fields': ['text_zadani', 'text_reseni', 'text_org',]}), |
|
|
(None, {'fields': ['text_zadani', 'text_reseni', 'text_org',]}), |
|
|
] |
|
|
] |
|
|
readonly_fields = ['timestamp', 'import_dakos_id'] |
|
|
readonly_fields = ['timestamp', 'import_dakos_id'] |
|
|
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'] |
|
|
search_fields = ['nazev', 'text_zadani', 'text_reseni', 'text_org'] |
|
|
search_fields = ['nazev', 'kod', 'text_zadani', 'text_reseni', 'text_org'] |
|
|
|
|
|
inlines = [ReseniKProblemuInline] |
|
|
|
|
|
view_on_site = Problem.verejne_url |
|
|
view_on_site = Problem.verejne_url |
|
|
|
|
|
|
|
|
def get_queryset(self, request): |
|
|
def get_queryset(self, request): |
|
|
qs = super(ProblemAdmin, self).get_queryset(request) |
|
|
qs = super(ProblemAdmin, self).get_queryset(request) |
|
|
return qs.select_related('autor', 'opravovatel', 'cislo_zadani', 'cislo_reseni').annotate(pocet_reseni=Count('reseni')) |
|
|
return qs.select_related('autor', 'opravovatel', 'cislo_zadani', 'cislo_reseni') |
|
|
|
|
|
|
|
|
def pocet_reseni(self, obj): |
|
|
def pocet_reseni(self, obj): |
|
|
return obj.pocet_reseni |
|
|
return obj.pocet_reseni |
|
|
|
|
|
|
|
|
admin.site.register(Problem, ProblemAdmin) |
|
|
class ProblemNavrhAdmin(ProblemAdmin): |
|
|
|
|
|
list_display = ['nazev', 'typ', 'stav', 'autor', 'timestamp'] |
|
|
|
|
|
list_filter = ['typ', 'stav', 'timestamp'] |
|
|
|
|
|
|
|
|
|
|
|
def get_queryset(self, request): |
|
|
|
|
|
qs = super(ProblemNavrhAdmin, self).get_queryset(request) |
|
|
|
|
|
return qs.filter(stav__in=[Problem.STAV_NAVRH, Problem.STAV_SMAZANY]) |
|
|
|
|
|
|
|
|
|
|
|
create_modeladmin(ProblemNavrhAdmin, Problem, 'ProblemNavrh', verbose_name=u'Problém (návrh)', verbose_name_plural=u'Problémy (návrhy)') |
|
|
|
|
|
|
|
|
|
|
|
class ProblemZadanyAdmin(ProblemAdmin): |
|
|
|
|
|
list_display = ['nazev', 'typ', 'autor', 'opravovatel', 'kod', 'cislo_zadani', 'pocet_reseni', 'verejne'] |
|
|
|
|
|
list_filter = ['typ', 'cislo_zadani__rocnik'] |
|
|
|
|
|
inlines = [ReseniKProblemuInline] |
|
|
|
|
|
|
|
|
|
|
|
def get_queryset(self, request): |
|
|
|
|
|
qs = super(ProblemZadanyAdmin, self).get_queryset(request) |
|
|
|
|
|
return qs.filter(stav=Problem.STAV_ZADANY).annotate(pocet_reseni=Count('reseni')) |
|
|
|
|
|
|
|
|
|
|
|
create_modeladmin(ProblemZadanyAdmin, Problem, 'ProblemZadany', verbose_name=u'Problém (zadaný)', verbose_name_plural=u'Problémy (zadané)') |
|
|
|
|
|
|
|
|
|
|
|
#admin.site.register(Problem, ProblemAdmin) |
|
|
|
|
|
|
|
|
### Soustredeni |
|
|
### Soustredeni |
|
|
|
|
|
|
|
|