TextileField 0.2.6
authorJan Szejko <janek37@gmail.com>
Tue, 25 Jul 2017 09:49:06 +0000 (11:49 +0200)
committerJan Szejko <janek37@gmail.com>
Tue, 25 Jul 2017 09:49:06 +0000 (11:49 +0200)
fnpdjango/utils/fields.py [new file with mode: 0644]
setup.py

diff --git a/fnpdjango/utils/fields.py b/fnpdjango/utils/fields.py
new file mode 100644 (file)
index 0000000..e638db5
--- /dev/null
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+from django.forms import CharField, ValidationError
+from .text.textilepl import textile_pl
+
+try:
+    from markupfield.fields import MarkupField
+except ImportError:
+    MarkupField = None
+else:
+    def validate_textile(value):
+        try:
+            textile_pl(value)
+        except Exception:
+            raise ValidationError('Syntax error in markup.')
+
+
+    class TextileFormField(CharField):
+        default_validators = [validate_textile]
+
+
+    class TextileField(MarkupField):
+        def formfield(self, **kwargs):
+            defaults = {'form_class': TextileFormField}
+            defaults.update(kwargs)
+            return super(MarkupField, self).formfield(**defaults)
index 0190709..2f9babe 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -23,7 +23,7 @@ def whole_trees(package_dir, paths):
 
 setup(
     name='fnpdjango',
 
 setup(
     name='fnpdjango',
-    version='0.2.4',
+    version='0.2.6',
     author='Radek Czajka',
     author_email='radekczajka@nowoczesnapolska.org.pl',
     url='',
     author='Radek Czajka',
     author_email='radekczajka@nowoczesnapolska.org.pl',
     url='',