Python django.forms.widgets.NumberInput() Examples
The following are 6
code examples of django.forms.widgets.NumberInput().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.forms.widgets
, or try the search function
.
Example #1
Source File: duration.py From richie with MIT License | 7 votes |
def __init__(self, attrs=None, choices=(), default_unit=None): """ Split the field in 2 widgets: - the first widget is a positive integer input, - the second widget is a select box to choose a pre-defined time unit (minutes, hours, days, weeks or months), e.g: 3 hours is split in: 3 (integer input) | hour (select) """ self.default_unit = default_unit super().__init__( ( widgets.NumberInput({**(attrs or {}), "min": 0}), widgets.Select(attrs, choices), ) )
Example #2
Source File: widgets.py From django-monthfield with BSD 3-Clause "New" or "Revised" License | 6 votes |
def __init__(self, attrs=None): # create choices for days, months, years _attrs = attrs or {} # default class _attrs['class'] = (_attrs.get('class', '') + ' w-month-year').strip() _widgets = [widgets.Select(attrs=_attrs, choices=MONTHS.items())] _attrs['class'] += " w-year" _widgets.append(widgets.NumberInput(attrs=_attrs)) super(MonthSelectorWidget, self).__init__(_widgets, attrs)
Example #3
Source File: effort.py From richie with MIT License | 5 votes |
def __init__( self, attrs=None, choices=(), default_effort_unit=None, default_reference_unit=None, ): """ Split the field in 3 widgets: - the first widget is a positive integer input, - the second widget is a select box to choose a pre-defined time unit (minutes, hours, days, weeks or months), - the third widget is a select box to choose the pre-defined time unit of reference. e.g: 3 hours/day is split in: 3 (integer input) | hour (select) | day (select) """ self.default_effort_unit = default_effort_unit self.default_reference_unit = default_reference_unit super().__init__( ( widgets.NumberInput({**(attrs or {}), "min": 0}), # Remove the last choice: it can never be chosen as it must be strictly smaller # than the reference time unit widgets.Select(attrs, choices[:-1]), # Remove the first choice: it can never be chosen as it must be strictly greater # than the effort time unit widgets.Select(attrs, choices[1:]), ) )
Example #4
Source File: test_numberinput.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_attrs_not_localized(self): widget = NumberInput(attrs={'max': 12345, 'min': 1234, 'step': 9999}) self.check_html( widget, 'name', 'value', '<input type="number" name="name" value="value" max="12345" min="1234" step="9999">' )
Example #5
Source File: test_numberinput.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_attrs_not_localized(self): widget = NumberInput(attrs={'max': 12345, 'min': 1234, 'step': 9999}) self.check_html( widget, 'name', 'value', '<input type="number" name="name" value="value" max="12345" min="1234" step="9999">' )
Example #6
Source File: filters.py From oldp with MIT License | 5 votes |
def __init__(self, **kwargs): super().__init__(**kwargs) # No fancy widgets self.filters.get('court__jurisdiction').field.widget = TextInput() self.filters.get('court__level_of_appeal').field.widget = TextInput() self.filters.get('has_reference_to_law').field.widget = NumberInput()