mamweb/seminar/autocomplete_light_registry.py

140 lines
3.7 KiB
Python
Raw Normal View History

2015-05-17 14:39:57 +02:00
# -*- coding: utf-8 -*-
from autocomplete_light import shortcuts as autocomplete_light
2019-04-16 22:18:49 +02:00
from .models import Skola, Resitel, Problem, Organizator
from taggit.models import Tag
autocomplete_light.register(Tag)
2015-05-17 14:39:57 +02:00
class SkolaAutocomplete(autocomplete_light.AutocompleteModelBase):
model = Skola
2019-04-23 21:46:29 +02:00
search_fields = ['nazev', 'mesto', 'ulice']
2015-05-17 14:39:57 +02:00
split_words = True
limit_choices = 15
2019-04-23 21:46:29 +02:00
attrs = {
2015-05-17 14:39:57 +02:00
# This will set the input placeholder attribute:
2019-04-23 21:46:29 +02:00
'placeholder': 'Škola',
2015-05-17 14:39:57 +02:00
# This will set the yourlabs.Autocomplete.minimumCharacters
# options, the naming conversion is handled by jQuery
'data-autocomplete-minimum-characters': 1,
}
2019-04-23 21:46:29 +02:00
widget_attrs = {
2015-05-17 14:39:57 +02:00
'data-widget-maximum-values': 15,
'class': 'modern-style',
}
autocomplete_light.register(SkolaAutocomplete)
class ResitelAutocomplete(autocomplete_light.AutocompleteModelBase):
model = Resitel
2019-04-23 21:46:29 +02:00
search_fields = ['jmeno', 'prijmeni']
2015-05-17 14:39:57 +02:00
split_words = False
limit_choices = 15
def choice_label(self, resitel):
2019-04-23 21:46:29 +02:00
return "%s, %s (%s)" % (resitel.plne_jmeno(), resitel.mesto, resitel.rok_maturity)
2015-05-17 14:39:57 +02:00
2019-04-23 21:46:29 +02:00
attrs= {
# This will set the input placeholder attribute:
2019-04-23 21:46:29 +02:00
'placeholder': 'Řešitel',
# This will set the yourlabs.Autocomplete.minimumCharacters
# options, the naming conversion is handled by jQuery
'data-autocomplete-minimum-characters': 1,
2015-05-17 14:39:57 +02:00
}
2019-04-23 21:46:29 +02:00
widget_attrs = {
'data-widget-maximum-values': 15,
# Enable modern-style widget !
'class': 'modern-style',
2015-05-17 14:39:57 +02:00
}
autocomplete_light.register(ResitelAutocomplete)
class OrganizatorAutocomplete(autocomplete_light.AutocompleteModelBase):
model = Organizator
2019-04-23 21:46:29 +02:00
search_fields = ['user__first_name', 'user__last_name', 'prezdivka']
split_words = False
limit_choices = 15
def choice_label(self, organizator):
2019-04-23 21:46:29 +02:00
return "%s '%s' %s" % (organizator.user.first_name,
organizator.prezdivka,
organizator.user.last_name)
2019-04-23 21:46:29 +02:00
attrs = {
# This will set the input placeholder attribute:
2019-04-23 21:46:29 +02:00
'placeholder': 'Organizátor',
# This will set the yourlabs.Autocomplete.minimumCharacters
# options, the naming conversion is handled by jQuery
'data-autocomplete-minimum-characters': 1,
}
2019-04-23 21:46:29 +02:00
widget_attrs = {
'data-widget-maximum-values': 15,
# Enable modern-style widget !
'class': 'modern-style',
}
autocomplete_light.register(OrganizatorAutocomplete)
2015-05-17 14:39:57 +02:00
class ProblemAutocomplete(autocomplete_light.AutocompleteModelBase):
model = Problem
2019-04-23 21:46:29 +02:00
search_fields = ['nazev']
2015-05-17 14:39:57 +02:00
split_words = False
limit_choices = 10
def choice_label(self, p):
if p.stav == Problem.STAV_ZADANY:
2015-09-19 21:08:41 +02:00
popisek = ""
try:
2019-04-23 21:46:29 +02:00
popisek = "%s (%s, %s.%s)".format(p.nazev, p.typ, p.cislo_zadani.rocnik.rocnik, p.kod_v_rocniku())
2015-09-19 21:08:41 +02:00
except:
2019-04-23 21:46:29 +02:00
#popisek = "%s (%s, %s.%s)".format(p.nazev, p.typ, p.stav)
popisek = "CHYBA"
2015-09-19 21:08:41 +02:00
return popisek
2015-05-17 14:39:57 +02:00
else:
2019-04-23 21:46:29 +02:00
return "%s (%s, %s)".format(p.nazev, p.typ, p.stav)
2015-05-17 14:39:57 +02:00
2019-04-23 21:46:29 +02:00
attrs = {
2015-05-17 14:39:57 +02:00
# This will set the input placeholder attribute:
2019-04-23 21:46:29 +02:00
'placeholder': 'Problém',
2015-05-17 14:39:57 +02:00
# This will set the yourlabs.Autocomplete.minimumCharacters
# options, the naming conversion is handled by jQuery
'data-autocomplete-minimum-characters': 1,
}
2019-04-23 21:46:29 +02:00
widget_attrs = {
2015-05-17 14:39:57 +02:00
'data-widget-maximum-values': 10,
# Enable modern-style widget !
'class': 'modern-style',
}
2019-04-23 22:25:18 +02:00
#FIXME Nefunguje, nevime proc
#autocomplete_light.register(ProblemAutocomplete)
2015-05-17 14:39:57 +02:00