|
@ -13,6 +13,23 @@ from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, Prilo |
|
|
import autocomplete_light |
|
|
import autocomplete_light |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def predvypln_prihlaseneho(*pole): |
|
|
|
|
|
u"""Dekorátor pro Adminy. Předvyplní do *polí přihlášeného uživatele. |
|
|
|
|
|
""" |
|
|
|
|
|
def formfield_for_foreignkey(self, db_field, request, **kwargs): |
|
|
|
|
|
if db_field.name in pole: |
|
|
|
|
|
kwargs['initial'] = request.user.id |
|
|
|
|
|
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): |
|
|
u""" |
|
|
u""" |
|
|
Pomocnik pro rychle vytvareni hromadnych admin akci ktere jen nastavuji |
|
|
Pomocnik pro rychle vytvareni hromadnych admin akci ktere jen nastavuji |
|
@ -301,6 +318,7 @@ 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'] |
|
@ -311,6 +329,7 @@ class ProblemNavrhAdmin(ProblemAdmin): |
|
|
|
|
|
|
|
|
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'] |
|
@ -375,19 +394,12 @@ 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] |
|
|
|
|
|
|
|
|
# předvyplnění přihlášeného uživatele jako autora novinky |
|
|
|
|
|
def formfield_for_foreignkey(self, db_field, request, **kwargs): |
|
|
|
|
|
if db_field.name == 'autor': |
|
|
|
|
|
kwargs['initial'] = request.user.id |
|
|
|
|
|
return super(NovinkyAdmin, self).formfield_for_foreignkey( |
|
|
|
|
|
db_field, request, **kwargs |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
admin.site.register(Novinky, NovinkyAdmin) |
|
|
admin.site.register(Novinky, NovinkyAdmin) |
|
|
|
|
|
|
|
|