diff MoinMoin/items/__init__.py @ 1625:6748d609a242

forms.py: Create JSON widget
author Cheer Xiao <xiaqqaix@gmail.com>
date Wed, 01 Aug 2012 23:32:42 +0800
parents c6974ba2e2b2
children 346c52c9c1e5
line wrap: on
line diff
--- a/MoinMoin/items/__init__.py	Wed Aug 01 23:31:14 2012 +0800
+++ b/MoinMoin/items/__init__.py	Wed Aug 01 23:32:42 2012 +0800
@@ -28,7 +28,7 @@
 
 from whoosh.query import Term, And, Prefix
 
-from MoinMoin.forms import RequiredText, OptionalText, OptionalMultilineText, Tags, Submit
+from MoinMoin.forms import RequiredText, OptionalText, JSON, Tags, Submit
 
 from MoinMoin.security.textcha import TextCha, TextChaizedForm
 from MoinMoin.signalling import item_modified
@@ -114,19 +114,6 @@
         return True
 
 
-class ValidJSON(Validator):
-    """Validator for JSON
-    """
-    invalid_json_msg = L_('Invalid JSON.')
-
-    def validate(self, element, state):
-        try:
-            json.loads(element.value)
-        except:
-            return self.note_error(element, state, 'invalid_json_msg')
-        return True
-
-
 class BaseChangeForm(TextChaizedForm):
     comment = OptionalText.using(label=L_('Comment')).with_properties(placeholder=L_("Comment about your change"))
     submit = Submit
@@ -317,7 +304,7 @@
     class _ModifyForm(BaseChangeForm):
         """Base class for ModifyForm of Item subclasses."""
         meta_form = BaseMetaForm
-        extra_meta_text = OptionalMultilineText.using(label=L_("Extra MetaData (JSON)")).with_properties(rows=ROWS_META, cols=COLS).validated_by(ValidJSON())
+        extra_meta_text = JSON.using(label=L_("Extra MetaData (JSON)")).with_properties(rows=ROWS_META, cols=COLS)
         meta_template = 'modify_meta.html'
 
         def _load(self, item):