2015-12-04 20:09:42 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2016-01-09 17:03:40 +01:00
|
|
|
from autocomplete_light import shortcuts as autocomplete_light
|
2015-12-04 20:09:42 +01:00
|
|
|
|
2019-04-23 22:27:20 +02:00
|
|
|
from .models import Obrazek, Galerie
|
|
|
|
from .views import cesta_od_korene
|
2015-12-04 20:09:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ObrazekAutocomplete(autocomplete_light.AutocompleteModelBase):
|
|
|
|
|
|
|
|
model = Obrazek
|
|
|
|
search_fields = ['nazev', 'popis']
|
|
|
|
split_words = True
|
|
|
|
limit_choices = 15
|
|
|
|
attrs = {
|
|
|
|
# This will set the input placeholder attribute:
|
|
|
|
'placeholder': u'Obrázek',
|
|
|
|
# This will set the yourlabs.Autocomplete.minimumCharacters
|
|
|
|
# options, the naming conversion is handled by jQuery
|
|
|
|
'data-autocomplete-minimum-characters': 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
choice_html_format = '''
|
|
|
|
<span class="block" data-value="{}">
|
|
|
|
<span class="block">
|
|
|
|
{}
|
|
|
|
<span class="block">{}</span>
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
'''
|
|
|
|
|
|
|
|
def choice_label(self, obrazek):
|
|
|
|
cesta = "/".join(g.nazev for g in cesta_od_korene(obrazek.galerie))
|
|
|
|
popis = "{}<br>".format(obrazek.popis) if obrazek.popis else ""
|
|
|
|
return '{}<br>{}{}'.format(obrazek.nazev, popis, cesta)
|
|
|
|
|
|
|
|
def choice_html(self, obrazek):
|
|
|
|
"""Vrátí kus html i s obrázkem, které se pak ukazuje v nabídce"""
|
|
|
|
return self.choice_html_format.format(self.choice_value(obrazek),
|
|
|
|
obrazek.obrazek_maly_tag(), self.choice_label(obrazek))
|
|
|
|
|
|
|
|
widget_attrs={
|
|
|
|
'data-widget-maximum-values': 15,
|
|
|
|
'class': 'modern-style',
|
|
|
|
}
|
|
|
|
|
|
|
|
autocomplete_light.register(ObrazekAutocomplete)
|