Browse Source

Rozdeleni problemu na navrhy a zadane

remotes/origin/feincms deploy-prod-2015-05-27-09-20-gavento
Tomas Gavenciak 10 years ago
parent
commit
234203c570
  1. 43
      seminar/admin.py
  2. 6
      seminar/models.py

43
seminar/admin.py

@ -23,6 +23,19 @@ def field_labels(model, fieldname):
f = [i for i in model._meta.fields if i.name == fieldname][0]
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
class ResitelInline(admin.TabularInline):
@ -231,6 +244,7 @@ admin.site.register(Reseni, ReseniAdmin)
from autocomplete_light.contrib.taggit_field import TaggitField, TaggitWidget
#TODO: Autocomplete autor/opravovatel
class ProblemAdminForm(forms.ModelForm):
text_zadani = forms.CharField(widget=CKEditorWidget(), **field_labels(Problem, 'text_zadani'))
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',]}),
]
readonly_fields = ['timestamp', 'import_dakos_id']
list_display = ['nazev', 'typ', 'kod', 'stav', 'autor', 'opravovatel', 'verejne', 'cislo_zadani', 'pocet_reseni']
list_select_related = True
list_filter = ['typ', 'stav', 'timestamp']
search_fields = ['nazev', 'kod', 'text_zadani', 'text_reseni', 'text_org']
inlines = [ReseniKProblemuInline]
search_fields = ['nazev', 'text_zadani', 'text_reseni', 'text_org']
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'))
return qs.select_related('autor', 'opravovatel', 'cislo_zadani', 'cislo_reseni')
def pocet_reseni(self, obj):
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

6
seminar/models.py

@ -396,6 +396,12 @@ class Problem(SeminarModelBase):
def verejne_url(self):
return reverse('seminar_problem', kwargs={'pk': self.id})
def admin_url(self):
if self.stav == Problem.STAV_ZADANY:
return reverse('admin:seminar_problemzadany_change', args=(self.id, ))
else:
return reverse('admin:seminar_problemnavrh_change', args=(self.id, ))
@reversion.register(ignore_duplicate_revisions=True)
@python_2_unicode_compatible

Loading…
Cancel
Save