1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from django import forms
6 from django.utils.translation import ugettext_lazy as _
8 from catalogue.models import Book
11 class BookImportForm(forms.Form):
12 book_xml_file = forms.FileField(required=False)
13 book_xml = forms.CharField(required=False)
16 from django.core.files.base import ContentFile
18 if not self.cleaned_data['book_xml_file']:
19 if self.cleaned_data['book_xml']:
20 self.cleaned_data['book_xml_file'] = \
21 ContentFile(self.cleaned_data['book_xml'].encode('utf-8'))
23 raise forms.ValidationError(_("Please supply an XML."))
24 return super(BookImportForm, self).clean()
26 def save(self, commit=True, **kwargs):
27 return Book.from_xml_file(self.cleaned_data['book_xml_file'], overwrite=True, **kwargs)
30 FORMATS = [(f, f.upper()) for f in Book.ebook_formats]
33 class DownloadFormatsForm(forms.Form):
34 formats = forms.MultipleChoiceField(required=False, choices=FORMATS,
35 widget=forms.CheckboxSelectMultiple)
37 def __init__(self, *args, **kwargs):
38 super(DownloadFormatsForm, self).__init__(*args, **kwargs)
48 ('', _('Normal leading')),
49 ('onehalfleading', _('One and a half leading')),
50 ('doubleleading', _('Double leading')),
54 ('11pt', _('Default')),
59 class CustomPDFForm(forms.Form):
60 nofootnotes = forms.BooleanField(required=False, label=_("Don't show footnotes"))
61 nothemes = forms.BooleanField(required=False, label=_("Don't disply themes"))
62 nowlfont = forms.BooleanField(required=False, label=_("Don't use our custom font"))
63 ## pagesize = forms.ChoiceField(PDF_PAGE_SIZES, required=True, label=_("Paper size"))
64 leading = forms.ChoiceField(PDF_LEADINGS, required=False, label=_("Leading"))
65 fontsize = forms.ChoiceField(PDF_FONT_SIZES, required=True, label=_("Font size"))
68 def customizations(self):
70 if self.cleaned_data['nofootnotes']:
71 c.append('nofootnotes')
73 if self.cleaned_data['nothemes']:
76 if self.cleaned_data['nowlfont']:
79 ## c.append(self.cleaned_data['pagesize'])
80 c.append(self.cleaned_data['fontsize'])
82 if self.cleaned_data['leading']:
83 c.append(self.cleaned_data['leading'])