259973dd06
Horizon checkboxes were using a standard checkbox. Unfortunately, this type of checkbox is only customizable through Chrome, and even then, its not completely flexible. The default checkboxes have now been altered to allow for a highly customized experience through the use of CSS pseudo elements and Icon Fonts. This allows the color, size and unselected and selected states of the checkbox to be customized. The 'default' theme uses the standard Font Awesome checked and unchecked icons. The 'material' now uses the Material Design checkbox design. It was also noticed (and fixed) that the help-icon on the forms were not the same color as its corresponding text. Partially-Implements: blueprint horizon-theme-css-reorg Change-Id: I52602357d831a5e978fe6916b37b0cde9edb2b9b
72 lines
2.0 KiB
Python
72 lines
2.0 KiB
Python
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
import django.forms
|
|
from django import template as django_template
|
|
|
|
|
|
register = django_template.Library()
|
|
|
|
|
|
@register.filter
|
|
def add_bootstrap_class(field):
|
|
"""Add a "form-control" CSS class to the field's widget.
|
|
|
|
This is so that Bootstrap styles it properly.
|
|
"""
|
|
if not isinstance(field.field.widget, (
|
|
django.forms.widgets.CheckboxInput,
|
|
django.forms.widgets.CheckboxSelectMultiple,
|
|
django.forms.widgets.RadioSelect,
|
|
django.forms.widgets.FileInput,
|
|
str,
|
|
)):
|
|
field_classes = set(field.field.widget.attrs.get('class', '').split())
|
|
field_classes.add('form-control')
|
|
field.field.widget.attrs['class'] = ' '.join(field_classes)
|
|
return field
|
|
|
|
|
|
@register.filter
|
|
def is_checkbox(field):
|
|
return isinstance(field.field.widget, django.forms.CheckboxInput)
|
|
|
|
|
|
@register.filter
|
|
def is_multiple_checkbox(field):
|
|
return isinstance(field.field.widget, django.forms.CheckboxSelectMultiple)
|
|
|
|
|
|
@register.filter
|
|
def is_radio(field):
|
|
return isinstance(field.field.widget, django.forms.RadioSelect)
|
|
|
|
|
|
@register.filter
|
|
def is_file(field):
|
|
return isinstance(field.field.widget, django.forms.FileInput)
|
|
|
|
|
|
@register.filter
|
|
def add_item_url(field):
|
|
if hasattr(field.field.widget, 'get_add_item_url'):
|
|
return field.field.widget.get_add_item_url()
|
|
return None
|
|
|
|
|
|
@register.filter
|
|
def wrapper_classes(field):
|
|
classes = []
|
|
if is_multiple_checkbox(field):
|
|
classes.append('multiple-checkbox')
|
|
return ' '.join(classes)
|