Browse Source

Update and finish admin autocompletes

remotes/origin/feincms
Tomas Gavenciak 10 years ago
parent
commit
09a11bdcea
  1. 22
      seminar/admin.py
  2. 98
      seminar/autocomplete_light_registry.py

22
seminar/admin.py

@ -29,7 +29,7 @@ admin.site.register(Skola, SkolaAdmin)
### Resitel
class ResitelAdmin(reversion.VersionAdmin):
form = autocomplete_light.modelform_factory(Resitel)
form = autocomplete_light.modelform_factory(Resitel, autocomplete_fields=['skola'], fields=['skola'])
fieldsets = [
(None, {'fields': ['jmeno', 'prijmeni', 'user']}),
(u'Škola', {'fields': ['skola', 'rok_maturity']}),
@ -59,6 +59,8 @@ admin.site.register(Cislo, CisloAdmin)
class CisloInline(admin.StackedInline):
model = Cislo
fields = ['cislo', 'datum_vydani', 'datum_deadline', 'verejne']
readonly_fields = ['cislo']
extra = 0
@ -78,7 +80,7 @@ admin.site.register(Rocnik, RocnikAdmin)
### PrilohaReseni
class PrilohaReseniAdmin(reversion.VersionAdmin):
readonly_fields = ['timestamp']
readonly_fields = ['timestamp', 'reseni']
fieldsets = [
(None, {'fields': ['reseni', 'soubor', 'timestamp']}),
(u'Poznámky', {'fields': ['poznamka']}),
@ -91,17 +93,20 @@ admin.site.register(PrilohaReseni, PrilohaReseniAdmin)
class PrilohaReseniInline(admin.StackedInline):
model = PrilohaReseni
fields = ['timestamp', 'soubor', 'poznamka']
readonly_fields = ['timestamp']
extra = 1
### Reseni
class ReseniAdmin(reversion.VersionAdmin):
readonly_fields = ['timestamp']
form = autocomplete_light.modelform_factory(Reseni, autocomplete_fields=['problem'], fields=['problem'])
fieldsets = [
(None, {'fields': ['problem', 'resitel', 'forma', 'body', 'cislo_body', 'timestamp']}),
(u'Poznámky', {'fields': ['poznamka']}),
]
readonly_fields = ['timestamp']
list_display = ['problem', 'resitel', 'forma', 'body', 'timestamp']
list_filter = ['body', 'timestamp', 'forma']
search_fields = []
@ -111,12 +116,14 @@ admin.site.register(Reseni, ReseniAdmin)
class ReseniInline(admin.TabularInline):
model = Reseni
readonly_fields = ['poznamka']
fields = ['resitel', 'forma', 'body', 'cislo_body', 'timestamp', 'poznamka']
readonly_fields = ['poznamka', 'resitel', 'timestamp', 'cislo_body', 'resitel', 'forma']
extra = 0
### Problem
#TODO: Autocomplete autor/opravovatel
class ProblemAdminForm(forms.ModelForm):
text_problemu = forms.CharField(widget=CKEditorWidget())
text_problemu_org = forms.CharField(widget=CKEditorWidget())
@ -126,15 +133,15 @@ class ProblemAdminForm(forms.ModelForm):
class ProblemAdmin(reversion.VersionAdmin):
form = ProblemAdminForm
# readonly_fields = ['autor']
fieldsets = [
(None, {'fields': ['nazev', 'typ', 'stav', 'autor', 'body']}),
(None, {'fields': ['nazev', 'typ', 'stav', 'autor', 'zamereni', 'body', 'timestamp']}),
(u'Vydání', {'fields': ['cislo_zadani', 'kod', 'cislo_reseni', 'opravovatel']}),
(u'Texty', {'fields': ['text_problemu', 'text_problemu_org']}),
]
readonly_fields = ['timestamp']
list_display = ['nazev', 'typ', 'kod', 'stav', 'autor', 'opravovatel', 'verejne', 'cislo_zadani']
list_select_related = True
list_filter = ['typ', 'stav', 'autor', 'opravovatel']
list_filter = ['typ', 'stav', 'timestamp']
search_fields = ['nazev', 'kod', 'text_problemu_org', 'text_problemu']
inlines = [ReseniInline]
view_on_site = Problem.verejne_url
@ -152,5 +159,6 @@ class SoustredeniAdmin(reversion.VersionAdmin):
list_display = ['rocnik', 'misto', 'datum_zacatku', 'verejne']
list_filter = ['rocnik']
view_on_site = Soustredeni.verejne_url
# TODO: UcastNaSoustredeni jako inline
admin.site.register(Soustredeni, SoustredeniAdmin)

98
seminar/autocomplete_light_registry.py

@ -1,24 +1,96 @@
# -*- coding: utf-8 -*-
import autocomplete_light
from models import Skola
# This will generate a PersonAutocomplete class
autocomplete_light.register(Skola,
# Just like in ModelAdmin.search_fields
search_fields=['nazev', 'mesto', 'ulice'],
from models import Skola, Resitel, Problem
class SkolaAutocomplete(autocomplete_light.AutocompleteModelBase):
model = Skola
search_fields=['nazev', 'mesto', 'ulice']
split_words = True
limit_choices = 15
attrs={
# This will set the input placeholder attribute:
'placeholder': u'Škola',
# This will set the yourlabs.Autocomplete.minimumCharacters
# options, the naming conversion is handled by jQuery
'data-autocomplete-minimum-characters': 1,
}
widget_attrs={
'data-widget-maximum-values': 15,
'class': 'modern-style',
}
autocomplete_light.register(SkolaAutocomplete)
class ResitelAutocomplete(autocomplete_light.AutocompleteModelBase):
model = Resitel
search_fields=['jmeno', 'prijmeni']
split_words = False
limit_choices = 15
def choice_label(self, resitel):
return u"%s, %s (%s)" % (resitel.plne_jmeno(), resitel.mesto, resitel.rok_maturity)
attrs={
# This will set the input placeholder attribute:
'placeholder': 'Skola',
'placeholder': u'Řešitel',
# This will set the yourlabs.Autocomplete.minimumCharacters
# options, the naming conversion is handled by jQuery
'data-autocomplete-minimum-characters': 1,
},
# This will set the data-widget-maximum-values attribute on the
# widget container element, and will be set to
# yourlabs.Widget.maximumValues (jQuery handles the naming
# conversion).
}
widget_attrs={
'data-widget-maximum-values': 15,
# Enable modern-style widget !
'class': 'modern-style',
},
)
}
autocomplete_light.register(ResitelAutocomplete)
class ProblemAutocomplete(autocomplete_light.AutocompleteModelBase):
model = Problem
search_fields=['nazev']
split_words = False
limit_choices = 10
def choice_label(self, p):
if p.stav == Problem.STAV_ZADANY:
return u"%s (%s, %s.%s)" % (p.nazev, p.typ, p.cislo_zadani.rocnik.rocnik, p.kod_v_rocniku())
else:
return u"%s (%s, %s)" % (p.nazev, p.typ, p.stav)
attrs={
# This will set the input placeholder attribute:
'placeholder': u'Řešitel',
# This will set the yourlabs.Autocomplete.minimumCharacters
# options, the naming conversion is handled by jQuery
'data-autocomplete-minimum-characters': 1,
}
widget_attrs={
'data-widget-maximum-values': 10,
# Enable modern-style widget !
'class': 'modern-style',
}
autocomplete_light.register(ProblemAutocomplete)

Loading…
Cancel
Save