mirror of
https://github.com/Hopiu/django-fobi.git
synced 2026-05-18 09:31:07 +00:00
widgets.py pep8
This commit is contained in:
parent
450a4a2a85
commit
c81f0d99f1
1 changed files with 18 additions and 11 deletions
|
|
@ -1,9 +1,3 @@
|
|||
__title__ = 'fobi.widgets'
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = 'Copyright (c) 2014-2015 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('NumberInput', 'BooleanRadioSelect',)
|
||||
|
||||
from django.forms.widgets import RadioSelect
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
|
@ -12,31 +6,44 @@ try:
|
|||
from django.forms.widgets import NumberInput
|
||||
except ImportError:
|
||||
from django.forms.widgets import TextInput
|
||||
|
||||
class NumberInput(TextInput):
|
||||
"""Number input."""
|
||||
|
||||
input_type = 'number'
|
||||
|
||||
__title__ = 'fobi.widgets'
|
||||
__author__ = 'Artur Barseghyan <artur.barseghyan@gmail.com>'
|
||||
__copyright__ = '2014-2016 Artur Barseghyan'
|
||||
__license__ = 'GPL 2.0/LGPL 2.1'
|
||||
__all__ = ('NumberInput', 'BooleanRadioSelect',)
|
||||
|
||||
|
||||
BOOLEAN_CHOICES = (
|
||||
(True, _("Yes")),
|
||||
(False, _("No"))
|
||||
)
|
||||
|
||||
|
||||
class BooleanRadioSelect(RadioSelect):
|
||||
"""
|
||||
Boolean radio select for Django.
|
||||
"""Boolean radio select for Django.
|
||||
|
||||
:example:
|
||||
|
||||
|
||||
>>> class DummyForm(forms.Form):
|
||||
>>> agree = forms.BooleanField(label=_("Agree?"), required=False, widget=BooleanRadioSelect)
|
||||
>>> agree = forms.BooleanField(label=_("Agree?"),
|
||||
>>> required=False,
|
||||
>>> widget=BooleanRadioSelect)
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Constructor."""
|
||||
# Override the default renderer if we were passed one.
|
||||
renderer = kwargs.pop('renderer', None)
|
||||
if renderer:
|
||||
self.renderer = renderer
|
||||
|
||||
if not 'choices' in kwargs:
|
||||
if 'choices' not in kwargs:
|
||||
kwargs['choices'] = BOOLEAN_CHOICES
|
||||
|
||||
super(BooleanRadioSelect, self).__init__(*args, **kwargs)
|
||||
|
|
|
|||
Loading…
Reference in a new issue