33from ...nhsuk_forms .integer_field import IntegerField
44from ..models .smoked_amount_response import SmokedAmountResponse
55
6+ from .mixins .smoking_form_presenter import SmokingFormPresenter
67
7- class SmokedAmountForm (forms .ModelForm ):
8+
9+ class SmokedAmountForm (SmokingFormPresenter , forms .ModelForm ):
810
911 def __init__ (self , tobacco_smoking_history , normal_tobacco_smoking_history = None , * args , ** kwargs ):
1012 self .tobacco_smoking_history = tobacco_smoking_history
@@ -13,83 +15,77 @@ def __init__(self, tobacco_smoking_history, normal_tobacco_smoking_history = Non
1315 super ().__init__ (* args , ** kwargs )
1416
1517 self .fields ["value" ] = IntegerField (
16- label = self ._type_label (),
18+ label = self .label (),
1719 label_classes = "nhsuk-label--m" if self .tobacco_smoking_history .is_normal () else "nhsuk-label--l" ,
1820 label_is_page_heading = not self .tobacco_smoking_history .is_normal (),
1921 classes = "nhsuk-input--width-4" ,
2022 hint = "Give an estimate if you are not sure" ,
2123 suffix = self .suffix (),
2224 required = True ,
2325 error_messages = {
24- "required" : self ._type_required_error_message (),
25- "min_value" : self ._type_min_value_error_message ()
26+ "required" : self .required_error_message (),
27+ "min_value" : self .min_value_error_message ()
2628 },
2729 )
2830
2931
30- def type_string (self ):
31- return self .tobacco_smoking_history .human_type ().lower ()
32-
33- def more_or_fewer_text (self ):
34- if self .tobacco_smoking_history .is_increased ():
35- return "more"
36- elif self .tobacco_smoking_history .is_decreased ():
37- return "fewer"
38-
39- def amount_prefix (self ):
40- return "grams of " if self .tobacco_smoking_history .is_rolling_tobacco () else ""
41-
4232 def suffix (self ):
43- return "grams" if self .tobacco_smoking_history .is_rolling_tobacco () else self .tobacco_smoking_history .unit ()
33+ return "grams" if self .tobacco_smoking_history .is_rolling_tobacco () else self .presenter .unit ()
4434
4535
46- def _normal_type_label (self ):
47- return f"Roughly how many { self .tobacco_smoking_history .unit ()} do you { self ._currently_or_previously_text ()} smoke in a normal { self .tobacco_smoking_history .frequency_singular ()} ?"
36+ def normal_label (self ):
37+ return (
38+ f"Roughly how many { self .presenter .unit ()} "
39+ f"{ self .presenter .do_or_did ()} you "
40+ f"{ self .presenter .currently_or_previously ()} smoke in a normal "
41+ f"{ self .presenter .frequency ()} ?"
42+ )
4843
4944
50- def _changed_type_label (self ):
45+ def changed_label (self ):
5146 return (
52- f"When you smoked { self .more_or_fewer_text ()} than "
53- f"{ self .normal_tobacco_smoking_history .amount ()} { self .tobacco_smoking_history .unit ()} "
54- f"a { self .normal_tobacco_smoking_history .frequency_singular ()} , "
55- f"roughly how many { self .tobacco_smoking_history .unit ()} "
56- f"did you normally smoke a { self .tobacco_smoking_history .frequency_singular ()} ?"
47+ f"When you smoked { self .presenter .more_or_fewer ()} than "
48+ f"{ self .normal_presenter .to_sentence ()} , "
49+ f"roughly how many { self .presenter .unit ()} "
50+ f"did you normally smoke a { self .presenter .frequency ()} ?"
5751 )
5852
5953
60- def _type_label (self ):
61- if self .normal_tobacco_smoking_history :
62- return self ._changed_type_label ()
54+ def label (self ):
55+ if self .tobacco_smoking_history . is_normal () :
56+ return self .normal_label ()
6357 else :
64- return self ._normal_type_label ()
58+ return self .changed_label ()
6559
6660
67- def _currently_or_previously_text (self ):
68- return "currently" if self .tobacco_smoking_history .smoking_current_response .value else "previously"
69-
70-
71- def _normal_type_required_error_message (self ):
72- return f"Enter how many { self .amount_prefix ()} { self .type_string ()} you { self ._currently_or_previously_text ()} smoke in a normal { self .tobacco_smoking_history .frequency_singular ()} "
73-
61+ def normal_required_error_message (self ):
62+ return (
63+ f"Enter how many { self .presenter .unit ()} you "
64+ f"{ self .presenter .currently_or_previously ()} { self .presenter .smoke_or_smoked ()} "
65+ f"in a normal { self .presenter .frequency ()} "
66+ )
7467
75- def _changed_type_required_error_message (self ):
68+ def changed_required_error_message (self ):
7669 return (
77- f"Enter the number of { self .amount_prefix ()} { self .type_string ()} "
78- f"you smoked when you smoked { self .more_or_fewer_text ()} than "
79- f"{ self .normal_tobacco_smoking_history .amount ()} { self .amount_prefix ()} { self .type_string ()} "
80- f"a { self .normal_tobacco_smoking_history .frequency_singular ()} "
70+ f"Enter the number of { self .presenter .unit ()} "
71+ f"you smoked when you smoked { self .presenter .more_or_fewer ()} than "
72+ f"{ self .normal_presenter .to_sentence ()} "
8173 )
8274
8375
84- def _type_required_error_message (self ):
76+ def required_error_message (self ):
8577 if self .normal_tobacco_smoking_history :
86- return self ._changed_type_required_error_message ()
78+ return self .changed_required_error_message ()
8779 else :
88- return self ._normal_type_required_error_message ()
80+ return self .normal_required_error_message ()
8981
9082
91- def _type_min_value_error_message (self ):
92- return f"The number of { self .type_string ()} you smoke must be at least 1"
83+ def min_value_error_message (self ):
84+ return (
85+ f"The number of { self .presenter .unit ()} you "
86+ f"{ self .presenter .smoke_or_smoked ()} a { self .presenter .frequency ()} "
87+ "must be at least 1"
88+ )
9389
9490 class Meta :
9591 model = SmokedAmountResponse
0 commit comments