Merge branch 'master' into view-refactor
[redakcja.git] / apps / api / forms.py
1 # -*- encoding: utf-8 -*-
2
3 __author__= "Ɓukasz Rekucki"
4 __date__ = "$2009-09-20 21:34:52$"
5 __doc__ = "Micro-forms for the API."
6
7
8 from django import forms
9
10 class DocumentEntryRequest(forms.Form):
11     revision = forms.RegexField(regex='latest|[0-9a-f]{40}')
12
13 class DocumentUploadForm(forms.Form):
14     ocr_file = forms.FileField(label='Source OCR file', required=False)
15     ocr_data = forms.CharField(widget=forms.HiddenInput(), required=False)
16     
17     bookname = forms.RegexField(regex=r'[0-9\.\w_-]+',  \
18         label='Publication name', help_text='Example: slowacki-beniowski')
19     
20     generate_dc = forms.BooleanField(required=False, \
21         initial=True, label=u"Generate DublinCore template")
22
23
24     def clean(self):
25         clean_data = self.cleaned_data
26
27         ocr_file = clean_data['ocr_file']
28         ocr_data = clean_data['ocr_data']
29
30         if not ocr_file and not ocr_data:
31             raise forms.ValidationError(
32                 "You must either provide file descriptor or raw data." )
33
34         return clean_data