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

1""" 

2The core application: Helper form widgets. 

3""" 

4 

5import copy 

6from django.forms import widgets 

7 

8 

9class FormControlTextInput(widgets.TextInput): 

10 """A styled text input.""" 

11 

12 def __init__(self, pattern=None, placeholder=None, **kwargs): 

13 super().__init__(**kwargs) 

14 

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}) 

20 

21 

22class FlowRadioSelect(widgets.RadioSelect): 

23 """A radio select input styled for the Enrollment Flow.""" 

24 

25 template_name = "core/widgets/flow-radio-select.html" 

26 option_template_name = "core/widgets/flow-radio-select-option.html" 

27 

28 def __init__(self, selection_label_templates=(), *args, **kwargs): 

29 super().__init__(*args, **kwargs) 

30 self.selection_label_templates = list(selection_label_templates) 

31 

32 def __deepcopy__(self, memo): 

33 obj = super().__deepcopy__(memo) 

34 obj.selection_label_templates = copy.copy(self.selection_label_templates) 

35 return obj 

36 

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]}) 

42 

43 return option