From abbb1fd1db2c758b001a2264b22a6e9879ef311e Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Wed, 21 Dec 2016 13:47:13 +0100 Subject: [PATCH] validate document text on save --- apps/wiki/forms.py | 10 ++++++++++ apps/wiki/static/wiki/editor | 2 +- lib/librarian | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/wiki/forms.py b/apps/wiki/forms.py index 7ef02e15..3ea36a32 100644 --- a/apps/wiki/forms.py +++ b/apps/wiki/forms.py @@ -4,9 +4,11 @@ # 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 librarian.document import Document class DocumentTextSaveForm(forms.Form): @@ -55,6 +57,14 @@ class DocumentTextSaveForm(forms.Form): 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): """ diff --git a/apps/wiki/static/wiki/editor b/apps/wiki/static/wiki/editor index 695d1a00..b44285e3 160000 --- a/apps/wiki/static/wiki/editor +++ b/apps/wiki/static/wiki/editor @@ -1 +1 @@ -Subproject commit 695d1a0067346347cf36bedab8fdce7ae39d5270 +Subproject commit b44285e326c9c90633a038e90bd6f794425b5632 diff --git a/lib/librarian b/lib/librarian index 3f24ff6b..5671d33a 160000 --- a/lib/librarian +++ b/lib/librarian @@ -1 +1 @@ -Subproject commit 3f24ff6b4246a5206555952f6e6c53f6ed5231d8 +Subproject commit 5671d33ab05838c3532ed84cfff7a954b6af9f7f -- 2.20.1