-class SearchForm(forms.Form):
- q = JQueryAutoCompleteField('/katalog/tags/', {'minChars': 2, 'selectFirst': True, 'cacheLength': 50})
- tags = forms.CharField(widget=forms.HiddenInput, required=False)
-
- def __init__(self, *args, **kwargs):
- tags = kwargs.pop('tags', [])
- super(SearchForm, self).__init__(*args, **kwargs)
- self.fields['q'].widget.attrs['title'] = u'tytuł utworu, kategoria lub motyw literacki'
- self.fields['tags'].initial = '/'.join(tag.slug for tag in Tag.get_tag_list(tags))
-
-
-class UserSetsForm(forms.Form):
- def __init__(self, book, user, *args, **kwargs):
- super(UserSetsForm, self).__init__(*args, **kwargs)
- self.fields['set_ids'] = forms.ChoiceField(
- choices=[(tag.id, tag.name) for tag in Tag.objects.filter(category='set', user=user)],
- )
-
-
-class ObjectSetsForm(forms.Form):
- def __init__(self, obj, user, *args, **kwargs):
- super(ObjectSetsForm, self).__init__(*args, **kwargs)
- self.fields['set_ids'] = forms.MultipleChoiceField(
- label=u'Półki',
- required=False,
- choices=[(tag.id, tag.name) for tag in Tag.objects.filter(category='set', user=user)],
- initial=[tag.id for tag in obj.tags.filter(category='set', user=user)],
- widget=forms.CheckboxSelectMultiple
- )
-
+class BookImportForm(forms.Form):
+ book_xml_file = forms.FileField(required=False)
+ book_xml = forms.CharField(required=False)
+
+ def clean(self):
+ from django.core.files.base import ContentFile
+
+ if not self.cleaned_data['book_xml_file']:
+ if self.cleaned_data['book_xml']:
+ self.cleaned_data['book_xml_file'] = \
+ ContentFile(self.cleaned_data['book_xml'].encode('utf-8'))
+ else:
+ raise forms.ValidationError(_("Please supply an XML."))
+ return super(BookImportForm, self).clean()
+
+ def save(self, commit=True, **kwargs):
+ return Book.from_xml_file(self.cleaned_data['book_xml_file'], overwrite=True, **kwargs)
+
+
+FORMATS = [(f, f.upper()) for f in Book.ebook_formats]
+
+
+class DownloadFormatsForm(forms.Form):
+ formats = forms.MultipleChoiceField(required=False, choices=FORMATS,
+ widget=forms.CheckboxSelectMultiple)