Admin: předvyplnění autora u problémů
This commit is contained in:
parent
98c6f2053d
commit
4801b61705
1 changed files with 20 additions and 8 deletions
|
@ -13,6 +13,23 @@ from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, Prilo
|
|||
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):
|
||||
u"""
|
||||
Pomocnik pro rychle vytvareni hromadnych admin akci ktere jen nastavuji
|
||||
|
@ -301,6 +318,7 @@ class ProblemAdmin(reversion.VersionAdmin):
|
|||
def pocet_reseni(self, obj):
|
||||
return obj.pocet_reseni
|
||||
|
||||
@predvypln_prihlaseneho('autor')
|
||||
class ProblemNavrhAdmin(ProblemAdmin):
|
||||
list_display = ['nazev', 'typ', 'zamereni', 'stav', 'autor', 'timestamp']
|
||||
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)')
|
||||
|
||||
@predvypln_prihlaseneho('autor')
|
||||
class ProblemZadanyAdmin(ProblemAdmin):
|
||||
list_display = ['nazev', 'typ', 'autor', 'opravovatel', 'kod', 'cislo_zadani', 'pocet_reseni', 'verejne']
|
||||
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'
|
||||
|
||||
|
||||
@predvypln_prihlaseneho('autor')
|
||||
class NovinkyAdmin(admin.ModelAdmin):
|
||||
form = NovinkyAdminForm
|
||||
list_display = ['datum', 'autor', 'text', 'zverejneno', 'obrazek']
|
||||
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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue