Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Commit

Permalink
Uses shared common code from onegov.form for HTML fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
msom committed Jul 11, 2017
1 parent 7101e9b commit 4d4ed1c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
3 changes: 3 additions & 0 deletions HISTORY.rst
@@ -1,6 +1,9 @@
Changelog
---------

- Uses shared common code from onegov.form for HTML fields.
[msom]

0.14.0 (2017-07-10)
~~~~~~~~~~~~~~~~~~~

Expand Down
17 changes: 4 additions & 13 deletions onegov/org/forms/fields.py
@@ -1,23 +1,14 @@
from onegov.core.html import sanitize_html
from onegov.org.utils import annotate_html
from wtforms.fields import TextAreaField
from onegov.form.fields import HtmlField as HtmlFieldBase


class HtmlField(TextAreaField):
class HtmlField(HtmlFieldBase):
""" A textfield with html with integrated sanitation and annotation,
cleaning the html and adding extra information including setting the
image size by querying the database.
"""

def __init__(self, *args, **kwargs):
self.form = kwargs.get('_form')

if 'render_kw' not in kwargs or not kwargs['render_kw'].get('class_'):
kwargs['render_kw'] = kwargs.get('render_kw', {})
kwargs['render_kw']['class_'] = 'editor'

super().__init__(*args, **kwargs)

def pre_validate(self, form):
self.data = annotate_html(sanitize_html(self.data), form.request)
super(HtmlField, self).pre_validate(form)
self.data = annotate_html(self.data, form.request)
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -41,7 +41,7 @@ def get_long_description():
'onegov.core>=0.41.0',
'onegov.event>=0.5.0',
'onegov.file>=0.2.1',
'onegov.form>=0.17.1',
'onegov.form>=0.18.0',
'onegov.foundation>=0.0.7',
'onegov.gis',
'onegov.newsletter>=0.1.0',
Expand Down

0 comments on commit 4d4ed1c

Please sign in to comment.