This repository has been archived by the owner on Sep 5, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Uses shared common code from onegov.form for HTML fields.
- Loading branch information
Showing
3 changed files
with
8 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters