1 # -*- coding: utf-8 -*-
2 from django import forms
4 from catalogue.models import Tag
5 from catalogue.fields import JQueryAutoCompleteField
6 from catalogue.lib.slughifi import slughifi
9 class SearchForm(forms.Form):
10 q = JQueryAutoCompleteField('/katalog/tags/', {'minChars': 2, 'selectFirst': True, 'cacheLength': 50})
12 def __init__(self, *args, **kwargs):
13 super(SearchForm, self).__init__(*args, **kwargs)
14 self.fields['q'].widget.attrs['title'] = u'tytuł utworu, motyw lub kategoria'
17 class BookSetsForm(forms.Form):
18 def __init__(self, book, user, *args, **kwargs):
19 super(BookSetsForm, self).__init__(*args, **kwargs)
20 self.fields['set_ids'] = forms.MultipleChoiceField(
23 choices=[(tag.id, tag.name) for tag in Tag.objects.filter(category='set', user=user)],
24 initial=[tag.id for tag in book.tags.filter(category='set', user=user)],
25 widget=forms.CheckboxSelectMultiple
29 class NewSetForm(forms.Form):
30 name = forms.CharField(max_length=50, required=True)
32 def save(self, user, commit=True):
33 name = self.cleaned_data['name']
34 new_set = Tag(name=name, slug=slughifi(name), sort_key=slughifi(name),
35 category='set', user=user)