From e72dc51a7469815f0c0047a0eba8046a02d327db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 8 Sep 2020 10:21:47 +0200 Subject: [PATCH] misc: add django widget type as css class (#46440) --- gadjo/templates/gadjo/widget.html | 3 ++- gadjo/templatetags/gadjo.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/gadjo/templates/gadjo/widget.html b/gadjo/templates/gadjo/widget.html index a937698..899cf3e 100644 --- a/gadjo/templates/gadjo/widget.html +++ b/gadjo/templates/gadjo/widget.html @@ -1,6 +1,7 @@ -{% load i18n %} +{% load gadjo i18n %}
diff --git a/gadjo/templatetags/gadjo.py b/gadjo/templatetags/gadjo.py index 685de2d..4e551c4 100644 --- a/gadjo/templatetags/gadjo.py +++ b/gadjo/templatetags/gadjo.py @@ -7,6 +7,7 @@ from xstatic.main import XStatic from django import template from django.conf import settings from django.core.exceptions import ImproperlyConfigured +from django.forms import BoundField from django.utils.html import escape from django.utils.http import urlencode @@ -122,3 +123,15 @@ def querystring(parser, token): def with_template(form): form_template = template.loader.get_template('gadjo/form.html') return form_template.render({'form': form}) + + +# pattern to transform Django camel case class names to CSS class names with +# dashes. (CheckboxInput -> checkbox-input) +class_name_pattern = re.compile(r'(?