mirror of
https://github.com/pinry/pinry.git
synced 2026-01-29 18:49:27 +01:00
Use Django's standard field rendering. Create filter for custom attrs.
This commit is contained in:
committed by
Isaac Bythewood
parent
e216e5a6f2
commit
a6569cb8ff
@@ -1,10 +1,10 @@
|
||||
from django.template import loader, Context, Library
|
||||
|
||||
|
||||
from django.template import Library
|
||||
|
||||
register = Library()
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def bootstrap_field(field):
|
||||
template = loader.get_template('core/templatetags/bootstrap_field.html')
|
||||
return template.render(Context({'field': field}))
|
||||
|
||||
@register.filter(name='bootstrap_field')
|
||||
def bootstrap_field(field, class_attr):
|
||||
return field.as_widget(attrs={
|
||||
'placeholder': field.label,
|
||||
'class': class_attr
|
||||
})
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
{% load bootstrap_field %}
|
||||
|
||||
<div class="form-group{% if field.errors %} has-error{% endif %}">
|
||||
<input type="{% if field.html_name == "password" %}password{% else %}text{% endif %}" id="id_{{ field.html_name }}" name="{{ field.html_name }}" class="form-control input-lg" placeholder="{{ field.label }}"/>
|
||||
{{ field|bootstrap_field:"form-control input-lg" }}
|
||||
{% if field.errors %}
|
||||
<span class="help-block">
|
||||
{% if field.errors %}
|
||||
|
||||
Reference in New Issue
Block a user