From 6eaf6e151e9f2fca1723e7e73eb106d868382de6 Mon Sep 17 00:00:00 2001 From: Raffaele Salmaso Date: Thu, 22 Feb 2018 23:29:54 +0100 Subject: [PATCH] Update MarkItUp widgets to template rendering. --- src/wiki/editors/markitup.py | 48 ++++--------------- .../templates/wiki/forms/markitup-admin.html | 1 + src/wiki/templates/wiki/forms/markitup.html | 1 + 3 files changed, 12 insertions(+), 38 deletions(-) create mode 100644 src/wiki/templates/wiki/forms/markitup-admin.html create mode 100644 src/wiki/templates/wiki/forms/markitup.html diff --git a/src/wiki/editors/markitup.py b/src/wiki/editors/markitup.py index 2e1336eb..d29e55d2 100644 --- a/src/wiki/editors/markitup.py +++ b/src/wiki/editors/markitup.py @@ -1,54 +1,26 @@ from django import forms -from django.forms.utils import flatatt -from django.utils.encoding import force_text -from django.utils.html import conditional_escape -from django.utils.safestring import mark_safe -from wiki.compat import BuildAttrsCompat from wiki.editors.base import BaseEditor -class MarkItUpAdminWidget(BuildAttrsCompat, forms.Widget): - - """A simplified more fail-safe widget for the backend""" +class MarkItUpWidget(forms.Widget): + template_name = "wiki/forms/markitup.html" def __init__(self, attrs=None): # The 'rows' and 'cols' attributes are required for HTML correctness. - default_attrs = {'class': 'markItUp', - 'rows': '10', 'cols': '40', } + default_attrs = { + 'class': 'markItUp', + 'rows': '10', + 'cols': '40', + } if attrs: default_attrs.update(attrs) super().__init__(default_attrs) - def render(self, name, value, attrs=None, renderer=None): - if value is None: - value = '' - final_attrs = self.build_attrs_compat(attrs, name=name) - return mark_safe( - '%s' % - (flatatt(final_attrs), - conditional_escape( - force_text(value)))) +class MarkItUpAdminWidget(MarkItUpWidget): + """A simplified more fail-safe widget for the backend""" -class MarkItUpWidget(BuildAttrsCompat, forms.Widget): - - def __init__(self, attrs=None): - # The 'rows' and 'cols' attributes are required for HTML correctness. - default_attrs = {'class': 'markItUp', - 'rows': '10', 'cols': '40', } - if attrs: - default_attrs.update(attrs) - super().__init__(default_attrs) - - def render(self, name, value, attrs=None, renderer=None): - if value is None: - value = '' - final_attrs = self.build_attrs_compat(attrs, name=name) - return mark_safe( - '
%s
' % - (flatatt(final_attrs), - conditional_escape( - force_text(value)))) + template_name = "wiki/forms/markitup-admin.html" class MarkItUp(BaseEditor): diff --git a/src/wiki/templates/wiki/forms/markitup-admin.html b/src/wiki/templates/wiki/forms/markitup-admin.html new file mode 100644 index 00000000..d35bedb5 --- /dev/null +++ b/src/wiki/templates/wiki/forms/markitup-admin.html @@ -0,0 +1 @@ + diff --git a/src/wiki/templates/wiki/forms/markitup.html b/src/wiki/templates/wiki/forms/markitup.html new file mode 100644 index 00000000..87337e67 --- /dev/null +++ b/src/wiki/templates/wiki/forms/markitup.html @@ -0,0 +1 @@ +
-- 2.45.2