|
@ -14,28 +14,19 @@ from django.contrib.auth.models import User |
|
|
from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni, Soustredeni, Soustredeni_Ucastnici, Novinky, Organizator |
|
|
from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni, Soustredeni, Soustredeni_Ucastnici, Novinky, Organizator |
|
|
import autocomplete_light |
|
|
import autocomplete_light |
|
|
|
|
|
|
|
|
uzivatele = [(user, u"{} ()".format(1)) for user in User.objects.filter(is_staff=True)] |
|
|
|
|
|
print(uzivatele) |
|
|
|
|
|
|
|
|
|
|
|
class UserModelChoiceField(forms.ModelChoiceField): |
|
|
class UserModelChoiceField(forms.ModelChoiceField): |
|
|
|
|
|
u"""Vlastní ModelChoiceField pro uživatele. Zobrazí kromě loginu i jméno. |
|
|
|
|
|
""" |
|
|
def label_from_instance(self, obj): |
|
|
def label_from_instance(self, obj): |
|
|
return u"{} ({})".format(obj.get_full_name(), obj.username) |
|
|
return u"{} ({})".format(obj.get_full_name(), obj.username) |
|
|
|
|
|
|
|
|
def predvypln_prihlaseneho(*pole): |
|
|
def get_form_predvypln_autora(self, request, obj=None, *args, **kwargs): |
|
|
u"""Dekorátor pro Adminy. Předvyplní do *polí přihlášeného uživatele. |
|
|
u"""get_form fce pro Adminy. Předvyplňí přihlášeného uživatele jako autora. |
|
|
""" |
|
|
""" |
|
|
def formfield_for_foreignkey(self, db_field, request, **kwargs): |
|
|
form = super(self.__class__, self).get_form(request, *args, **kwargs) |
|
|
if db_field.name in pole: |
|
|
form.base_fields['autor'].initial = request.user.id |
|
|
kwargs['initial'] = request.user.id |
|
|
return form |
|
|
return super(self.__class__, self).formfield_for_foreignkey( |
|
|
|
|
|
db_field, request, **kwargs |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
def decorator(orig_class): |
|
|
|
|
|
orig_class.formfield_for_foreignkey = formfield_for_foreignkey |
|
|
|
|
|
return orig_class |
|
|
|
|
|
|
|
|
|
|
|
return decorator |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def make_set_action(atribut, hodnota, nazev): |
|
|
def make_set_action(atribut, hodnota, nazev): |
|
@ -303,7 +294,7 @@ class ProblemAdminForm(forms.ModelForm): |
|
|
text_org = forms.CharField(widget=CKEditorWidget(), required=False, **field_labels(Problem, 'text_org')) |
|
|
text_org = forms.CharField(widget=CKEditorWidget(), required=False, **field_labels(Problem, 'text_org')) |
|
|
zamereni = TaggitField(widget=TaggitWidget('TagAutocomplete'), required=False) |
|
|
zamereni = TaggitField(widget=TaggitWidget('TagAutocomplete'), required=False) |
|
|
autor = UserModelChoiceField(User.objects.filter(is_staff=True)) |
|
|
autor = UserModelChoiceField(User.objects.filter(is_staff=True)) |
|
|
opravovatel = UserModelChoiceField(User.objects.filter(is_staff=True)) |
|
|
opravovatel = UserModelChoiceField(User.objects.filter(is_staff=True), required=False) |
|
|
class Meta: |
|
|
class Meta: |
|
|
model = Problem |
|
|
model = Problem |
|
|
exclude = [] |
|
|
exclude = [] |
|
@ -327,7 +318,6 @@ class ProblemAdmin(reversion.VersionAdmin): |
|
|
def pocet_reseni(self, obj): |
|
|
def pocet_reseni(self, obj): |
|
|
return obj.pocet_reseni |
|
|
return obj.pocet_reseni |
|
|
|
|
|
|
|
|
@predvypln_prihlaseneho('autor') |
|
|
|
|
|
class ProblemNavrhAdmin(ProblemAdmin): |
|
|
class ProblemNavrhAdmin(ProblemAdmin): |
|
|
list_display = ['nazev', 'typ', 'zamereni', 'stav', 'autor', 'timestamp'] |
|
|
list_display = ['nazev', 'typ', 'zamereni', 'stav', 'autor', 'timestamp'] |
|
|
list_filter = ['typ', 'zamereni', 'timestamp', 'stav'] |
|
|
list_filter = ['typ', 'zamereni', 'timestamp', 'stav'] |
|
@ -336,9 +326,11 @@ class ProblemNavrhAdmin(ProblemAdmin): |
|
|
qs = super(ProblemNavrhAdmin, self).get_queryset(request) |
|
|
qs = super(ProblemNavrhAdmin, self).get_queryset(request) |
|
|
return qs.filter(stav__in=[Problem.STAV_NAVRH, Problem.STAV_SMAZANY]) |
|
|
return qs.filter(stav__in=[Problem.STAV_NAVRH, Problem.STAV_SMAZANY]) |
|
|
|
|
|
|
|
|
|
|
|
get_form = get_form_predvypln_autora |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
create_modeladmin(ProblemNavrhAdmin, Problem, 'ProblemNavrh', verbose_name=u'Problém (návrh)', verbose_name_plural=u'Problémy (návrhy)') |
|
|
create_modeladmin(ProblemNavrhAdmin, Problem, 'ProblemNavrh', verbose_name=u'Problém (návrh)', verbose_name_plural=u'Problémy (návrhy)') |
|
|
|
|
|
|
|
|
@predvypln_prihlaseneho('autor') |
|
|
|
|
|
class ProblemZadanyAdmin(ProblemAdmin): |
|
|
class ProblemZadanyAdmin(ProblemAdmin): |
|
|
list_display = ['nazev', 'typ', 'autor', 'opravovatel', 'kod', 'cislo_zadani', 'pocet_reseni', 'verejne'] |
|
|
list_display = ['nazev', 'typ', 'autor', 'opravovatel', 'kod', 'cislo_zadani', 'pocet_reseni', 'verejne'] |
|
|
list_filter = ['typ', 'cislo_zadani__cislo', 'cislo_zadani__rocnik'] |
|
|
list_filter = ['typ', 'cislo_zadani__cislo', 'cislo_zadani__rocnik'] |
|
@ -348,6 +340,8 @@ class ProblemZadanyAdmin(ProblemAdmin): |
|
|
qs = super(ProblemZadanyAdmin, self).get_queryset(request) |
|
|
qs = super(ProblemZadanyAdmin, self).get_queryset(request) |
|
|
return qs.filter(stav=Problem.STAV_ZADANY).annotate(pocet_reseni=Count('reseni')) |
|
|
return qs.filter(stav=Problem.STAV_ZADANY).annotate(pocet_reseni=Count('reseni')) |
|
|
|
|
|
|
|
|
|
|
|
get_form = get_form_predvypln_autora |
|
|
|
|
|
|
|
|
create_modeladmin(ProblemZadanyAdmin, Problem, 'ProblemZadany', verbose_name=u'Problém (zadaný)', verbose_name_plural=u'Problémy (zadané)') |
|
|
create_modeladmin(ProblemZadanyAdmin, Problem, 'ProblemZadany', verbose_name=u'Problém (zadaný)', verbose_name_plural=u'Problémy (zadané)') |
|
|
|
|
|
|
|
|
#admin.site.register(Problem, ProblemAdmin) |
|
|
#admin.site.register(Problem, ProblemAdmin) |
|
@ -405,12 +399,13 @@ def zneverejnit_novinky(modeladmin, request, queryset): |
|
|
zneverejnit_novinky.short_description = 'Zneveřejnit vybrané novinky' |
|
|
zneverejnit_novinky.short_description = 'Zneveřejnit vybrané novinky' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@predvypln_prihlaseneho('autor') |
|
|
|
|
|
class NovinkyAdmin(admin.ModelAdmin): |
|
|
class NovinkyAdmin(admin.ModelAdmin): |
|
|
form = NovinkyAdminForm |
|
|
form = NovinkyAdminForm |
|
|
list_display = ['datum', 'autor', 'text', 'zverejneno', 'obrazek'] |
|
|
list_display = ['datum', 'autor', 'text', 'zverejneno', 'obrazek'] |
|
|
actions = [zverejnit_novinky, zneverejnit_novinky] |
|
|
actions = [zverejnit_novinky, zneverejnit_novinky] |
|
|
|
|
|
|
|
|
|
|
|
get_form = get_form_predvypln_autora |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
admin.site.register(Novinky, NovinkyAdmin) |
|
|
admin.site.register(Novinky, NovinkyAdmin) |
|
|
|
|
|
|
|
|