Snadne vyrabitko admin akci (viz Soustredeni admin)
This commit is contained in:
parent
7bd2945dc3
commit
0a49ace38c
1 changed files with 24 additions and 13 deletions
|
@ -1,4 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.forms import widgets
|
from django.forms import widgets
|
||||||
|
@ -12,6 +13,23 @@ from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, Prilo
|
||||||
import autocomplete_light
|
import autocomplete_light
|
||||||
|
|
||||||
|
|
||||||
|
def make_set_action(atribut, hodnota, nazev):
|
||||||
|
u"""
|
||||||
|
Pomocnik pro rychle vytvareni hromadnych admin akci ktere jen nastavuji
|
||||||
|
atribut (dany jako string) na danou hodnotu.
|
||||||
|
nazev je krátký popis akce pro admin rozhraní."""
|
||||||
|
def action_f(modeladmin, request, queryset):
|
||||||
|
for obj in queryset:
|
||||||
|
assert atribut in obj.__dict__
|
||||||
|
obj.__setattr__(atribut, hodnota)
|
||||||
|
obj.save()
|
||||||
|
action_f.short_description = nazev
|
||||||
|
# Trik: je potřeba, aby se funkce různě (ale libovolně) jmenovaly,
|
||||||
|
# jinak je Django v seznamu akcí splácne do jedné
|
||||||
|
action_f.__name__ = 'action_f_%d_%d_%d' % (id(atribut), id(hodnota), id(nazev), )
|
||||||
|
return action_f
|
||||||
|
|
||||||
|
|
||||||
### Globální nastavení
|
### Globální nastavení
|
||||||
|
|
||||||
admin.site.register(Nastaveni, SingletonModelAdmin)
|
admin.site.register(Nastaveni, SingletonModelAdmin)
|
||||||
|
@ -297,18 +315,6 @@ create_modeladmin(ProblemZadanyAdmin, Problem, 'ProblemZadany', verbose_name=u'P
|
||||||
|
|
||||||
### Soustredeni
|
### Soustredeni
|
||||||
|
|
||||||
def zverejnit_soustredeni(modeladmin, request, queryset):
|
|
||||||
for soustredeni in queryset:
|
|
||||||
soustredeni.verejne_db = True
|
|
||||||
soustredeni.save()
|
|
||||||
zverejnit_soustredeni.short_description = 'Zveřejnit soustředění'
|
|
||||||
|
|
||||||
def skryt_soustredeni(modeladmin, request, queryset):
|
|
||||||
for soustredeni in queryset:
|
|
||||||
soustredeni.verejne_db = False
|
|
||||||
soustredeni.save()
|
|
||||||
skryt_soustredeni.short_description = 'Skrýt soustředění (Zneveřjnit)'
|
|
||||||
|
|
||||||
class SoustredeniAdminForm(forms.ModelForm):
|
class SoustredeniAdminForm(forms.ModelForm):
|
||||||
text = forms.CharField(widget=CKEditorWidget(), required=False, **field_labels(Soustredeni, 'text'))
|
text = forms.CharField(widget=CKEditorWidget(), required=False, **field_labels(Soustredeni, 'text'))
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -325,7 +331,12 @@ class SoustredeniAdmin(reversion.VersionAdmin):
|
||||||
inlines = [Soustredeni_UcastniciInline]
|
inlines = [Soustredeni_UcastniciInline]
|
||||||
list_filter = ['typ', 'rocnik']
|
list_filter = ['typ', 'rocnik']
|
||||||
view_on_site = Soustredeni.verejne_url
|
view_on_site = Soustredeni.verejne_url
|
||||||
actions = [zverejnit_soustredeni, skryt_soustredeni, ]
|
actions = [
|
||||||
|
make_set_action('verejne_db', True, u'Zveřejnit soustředění'),
|
||||||
|
make_set_action('verejne_db', False, u'Skrýt (zneveřejnit) soustředění'),
|
||||||
|
make_set_action('exportovat', True, u'Nastavit pro AESOP export'),
|
||||||
|
make_set_action('exportovat', False, u'Skrýt pro AESOP export'),
|
||||||
|
]
|
||||||
|
|
||||||
admin.site.register(Soustredeni, SoustredeniAdmin)
|
admin.site.register(Soustredeni, SoustredeniAdmin)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue