From 3b009e3e675620c33423c624985726ee8db94e86 Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Tue, 25 Jul 2017 11:49:06 +0200 Subject: [PATCH] TextileField --- fnpdjango/utils/fields.py | 25 +++++++++++++++++++++++++ setup.py | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 fnpdjango/utils/fields.py diff --git a/fnpdjango/utils/fields.py b/fnpdjango/utils/fields.py new file mode 100644 index 0000000..e638db5 --- /dev/null +++ b/fnpdjango/utils/fields.py @@ -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) diff --git a/setup.py b/setup.py index 0190709..2f9babe 100755 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ def whole_trees(package_dir, paths): setup( name='fnpdjango', - version='0.2.4', + version='0.2.6', author='Radek Czajka', author_email='radekczajka@nowoczesnapolska.org.pl', url='', -- 2.20.1