mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-23 14:49:31 +00:00
Move the useful formfield tools out into a app to reuse elsewhere
This commit is contained in:
0
app/formtools/__init__.py
Normal file
0
app/formtools/__init__.py
Normal file
12
app/formtools/templates/formtools/formfield.html
Normal file
12
app/formtools/templates/formtools/formfield.html
Normal file
@@ -0,0 +1,12 @@
|
||||
{% load add_class %}
|
||||
|
||||
<div class="clearfix">
|
||||
{{ field.label_tag }}
|
||||
<div class="input">
|
||||
{% if class %}{{ field|add_class:class }}{% else %}{{ field }}{% endif %}
|
||||
{% if field.help_text %}
|
||||
<span class="help-block">{{ field.help_text }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
0
app/formtools/templatetags/__init__.py
Normal file
0
app/formtools/templatetags/__init__.py
Normal file
21
app/formtools/templatetags/add_class.py
Normal file
21
app/formtools/templatetags/add_class.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import re
|
||||
from django.utils.safestring import mark_safe
|
||||
from django import template
|
||||
register = template.Library()
|
||||
|
||||
class_re = re.compile(r'(?<=class=["\'])(.*)(?=["\'])')
|
||||
@register.filter
|
||||
def add_class(value, css_class):
|
||||
string = unicode(value)
|
||||
match = class_re.search(string)
|
||||
if match:
|
||||
m = re.search(r'^%s$|^%s\s|\s%s\s|\s%s$' % (css_class, css_class,
|
||||
css_class, css_class),
|
||||
match.group(1))
|
||||
print match.group(1)
|
||||
if not m:
|
||||
return mark_safe(class_re.sub(match.group(1) + " " + css_class,
|
||||
string))
|
||||
else:
|
||||
return mark_safe(string.replace('>', ' class="%s">' % css_class))
|
||||
return value
|
||||
Reference in New Issue
Block a user