Coverage for benefits/core/widgets.py: 87%
25 statements
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-22 18:00 +0000
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-22 18:00 +0000
1"""
2The core application: Helper form widgets.
3"""
5import copy
6from django.forms import widgets
9class FormControlTextInput(widgets.TextInput):
10 """A styled text input."""
12 def __init__(self, pattern=None, placeholder=None, **kwargs):
13 super().__init__(**kwargs)
15 self.attrs.update({"class": "form-control"})
16 if pattern: 16 ↛ 17line 16 didn't jump to line 17 because the condition on line 16 was never true
17 self.attrs.update({"pattern": pattern})
18 if placeholder: 18 ↛ exitline 18 didn't return from function '__init__' because the condition on line 18 was always true
19 self.attrs.update({"placeholder": placeholder})
22class FlowRadioSelect(widgets.RadioSelect):
23 """A radio select input styled for the Enrollment Flow."""
25 template_name = "core/widgets/flow-radio-select.html"
26 option_template_name = "core/widgets/flow-radio-select-option.html"
28 def __init__(self, selection_label_templates=(), *args, **kwargs):
29 super().__init__(*args, **kwargs)
30 self.selection_label_templates = list(selection_label_templates)
32 def __deepcopy__(self, memo):
33 obj = super().__deepcopy__(memo)
34 obj.selection_label_templates = copy.copy(self.selection_label_templates)
35 return obj
37 def create_option(self, name, value, label, selected, index, subindex, attrs):
38 option = super().create_option(name, value, label, selected, index, subindex, attrs)
39 # this implementation does not support groups from ChoiceWidget.optgroups
40 if value in self.selection_label_templates: 40 ↛ 43line 40 didn't jump to line 43 because the condition on line 40 was always true
41 option.update({"selection_label_template": self.selection_label_templates[value]})
43 return option