X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/39d26aa0f2cb893f19282657b2fddd2a494f2263..747e1708decfe38a56f6fa512ba91e9d7c5349f8:/apps/api/forms.py diff --git a/apps/api/forms.py b/apps/api/forms.py index 2c9ae66a..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,18 +88,39 @@ 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'] if value: - return u"$USER$ " + request.POST['message'] + return u"$USER$ " + value else: return u"$AUTO$ XML content update."