validate document text on save
authorJan Szejko <janek37@gmail.com>
Wed, 21 Dec 2016 12:47:13 +0000 (13:47 +0100)
committerJan Szejko <janek37@gmail.com>
Wed, 21 Dec 2016 12:47:13 +0000 (13:47 +0100)
apps/wiki/forms.py
apps/wiki/static/wiki/editor
lib/librarian

index 7ef02e1..3ea36a3 100644 (file)
@@ -4,9 +4,11 @@
 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
 #
 from django import forms
 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
 #
 from django import forms
+from django.core.exceptions import ValidationError
 from django.utils.translation import ugettext_lazy as _
 
 from catalogue.constants import STAGES
 from django.utils.translation import ugettext_lazy as _
 
 from catalogue.constants import STAGES
+from librarian.document import Document
 
 
 class DocumentTextSaveForm(forms.Form):
 
 
 class DocumentTextSaveForm(forms.Form):
@@ -55,6 +57,14 @@ class DocumentTextSaveForm(forms.Form):
             self.fields['author_name'].required = False
             self.fields['author_email'].required = False
 
             self.fields['author_name'].required = False
             self.fields['author_email'].required = False
 
+    def clean_text(self):
+        text = self.cleaned_data['text']
+        try:
+            Document.from_string(text)
+        except ValueError as e:
+            raise ValidationError(e.message)
+        return text
+
 
 class DocumentTextRevertForm(forms.Form):
     """
 
 class DocumentTextRevertForm(forms.Form):
     """
index 695d1a0..b44285e 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 695d1a0067346347cf36bedab8fdce7ae39d5270
+Subproject commit b44285e326c9c90633a038e90bd6f794425b5632
index 3f24ff6..5671d33 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 3f24ff6b4246a5206555952f6e6c53f6ed5231d8
+Subproject commit 5671d33ab05838c3532ed84cfff7a954b6af9f7f