gestioCOF/gestioncof/widgets.py
Aurélien Delobelle dfb9ccb0af Fix use of Widget.build_attrs in TriStateCheckbox
Signature changed in Django 1.11.
2018-01-19 18:41:06 +01:00

26 lines
940 B
Python

# -*- coding: utf-8 -*-
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from django.forms.widgets import Widget
from django.forms.utils import flatatt
from django.utils.safestring import mark_safe
class TriStateCheckbox(Widget):
def __init__(self, attrs=None, choices=()):
super(TriStateCheckbox, self).__init__(attrs)
# choices can be any iterable, but we may need to render this widget
# multiple times. Thus, collapse it into a list so it can be consumed
# more than once.
self.choices = list(choices)
def render(self, name, value, attrs=None, choices=()):
if value is None:
value = 'none'
attrs['value'] = value
final_attrs = self.build_attrs(self.attrs, attrs)
output = ["<span class=\"tristate\"%s></span>" % flatatt(final_attrs)]
return mark_safe('\n'.join(output))