Uporządkowanie importów.
[redakcja.git] / apps / explorer / forms.py
1 from django import forms
2
3 from lxml import etree
4 from librarian import dcparser
5
6
7 from explorer import models
8
9
10 class BookForm(forms.Form):
11     content = forms.CharField(widget=forms.Textarea)
12     commit_message = forms.CharField(required=False)
13
14 class BookUploadForm(forms.Form):
15     file = forms.FileField()
16
17 class ImageFoldersForm(forms.Form):
18     folders = forms.ChoiceField(required=False)
19     
20     def __init__(self, *args, **kwargs):
21         super(ImageFoldersForm, self).__init__(*args, **kwargs)
22         self.fields['folders'].choices = [('', '-- Wybierz folder z obrazkami --')] + [(fn, fn) for fn in models.get_image_folders()]
23
24
25 class DublinCoreForm(forms.Form):
26     wiki_url = forms.URLField(verify_exists=False)
27     author = forms.CharField()
28     title = forms.CharField()
29     epoch = forms.CharField()
30     kind = forms.CharField()
31     genre = forms.CharField()
32     created_at = forms.DateField()
33     released_to_public_domain_at = forms.DateField()
34     translator = forms.CharField(required=False)
35     technical_editor = forms.CharField(required=False)
36     publisher = forms.CharField()
37     source_name = forms.CharField(widget=forms.Textarea)
38     source_url = forms.URLField(verify_exists=False)
39     url = forms.URLField(verify_exists=False)
40     parts = forms.CharField(widget=forms.Textarea, required=False)
41     license = forms.CharField(required=False)
42     license_description = forms.CharField(widget=forms.Textarea, required=False)
43     
44     commit_message = forms.CharField(required=False)
45     
46     def __init__(self, *args, **kwargs):
47         text = None
48         if 'text' in kwargs:
49             text = kwargs.pop('text')
50         
51         super(DublinCoreForm, self).__init__(*args, **kwargs)
52         
53         if text is not None:
54             book_info = dcparser.BookInfo.from_string(text)
55             for name, value in book_info.to_dict().items():
56                 self.fields[name].initial = value