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')) )
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']
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."