X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/ddd5ce2848efb9d43ed14322b1a9fa1494711865..dbfc1841d5b6849463d527772781a3ba586fefa0:/apps/api/forms.py?ds=inline diff --git a/apps/api/forms.py b/apps/api/forms.py index c5e0b670..22cadb9e 100644 --- a/apps/api/forms.py +++ b/apps/api/forms.py @@ -11,7 +11,6 @@ from django.contrib.auth.models import User import re from django.utils import simplejson as json - class MergeRequestForm(forms.Form): # should the target document revision be updated or shared type = forms.ChoiceField(choices=(('update', 'Update'), ('share', 'Share')) ) @@ -63,9 +62,9 @@ PRQ_USER_RE = re.compile(r"^\$prq-(\d{1,10})$", re.UNICODE) class DocumentRetrieveForm(forms.Form): revision = forms.RegexField(regex=r'latest|[0-9a-z]{40}', required=False) user = forms.CharField(required=False) - + def clean_user(self): - # why, oh why does django doesn't implement this!!! + # why, oh why doesn't django implement this!!! # value = super(DocumentRetrieveForm, self).clean_user() value = self.cleaned_data['user'] @@ -89,13 +88,34 @@ class DocumentRetrieveForm(forms.Form): class TextRetrieveForm(DocumentRetrieveForm): - part = forms.CharField(required=False) + chunk = forms.CharField(required=False) + format = forms.CharField(required=False) + + def clean_format(self): + value = self.cleaned_data['format'] + if not value: + return 'raw' + + if value not in ('nl', 'raw'): + raise forms.ValidationError("Invalid text format") + return value class TextUpdateForm(DocumentRetrieveForm): message = forms.CharField(required=False) contents = forms.CharField(required=False) chunks = forms.CharField(required=False) + format = forms.CharField(required=False) + + def clean_format(self): + value = self.cleaned_data['format'] + if not value: + return 'raw' + + if value not in ('nl', 'raw'): + raise forms.ValidationError("Invalid text format") + return value + def clean_message(self): value = self.cleaned_data['message']