1616)
1717
1818
19- class MastectomyOrLumpectomyHistoryBaseForm (FormWithConditionalFields ):
19+ class MastectomyOrLumpectomyHistoryForm (FormWithConditionalFields ):
2020 right_breast_procedure = ChoiceField (
2121 label = "Right breast" ,
2222 visually_hidden_label_prefix = "What procedure have they had in their " ,
@@ -91,6 +91,20 @@ class MastectomyOrLumpectomyHistoryBaseForm(FormWithConditionalFields):
9191 )
9292
9393 def __init__ (self , * args , ** kwargs ):
94+ self .instance = kwargs .pop ("instance" , None )
95+
96+ if self .instance :
97+ kwargs ["initial" ] = {
98+ "left_breast_procedure" : self .instance .left_breast_procedure ,
99+ "right_breast_procedure" : self .instance .right_breast_procedure ,
100+ "left_breast_other_surgery" : self .instance .left_breast_other_surgery ,
101+ "right_breast_other_surgery" : self .instance .right_breast_other_surgery ,
102+ "year_of_surgery" : self .instance .year_of_surgery ,
103+ "surgery_reason" : self .instance .surgery_reason ,
104+ "surgery_other_reason_details" : self .instance .surgery_other_reason_details ,
105+ "additional_details" : self .instance .additional_details ,
106+ }
107+
94108 super ().__init__ (* args , ** kwargs )
95109
96110 self .given_field_value (
@@ -118,8 +132,6 @@ def model_values(self):
118132 additional_details = self .cleaned_data .get ("additional_details" , "" ),
119133 )
120134
121-
122- class MastectomyOrLumpectomyHistoryForm (MastectomyOrLumpectomyHistoryBaseForm ):
123135 def create (self , appointment , request ):
124136 auditor = Auditor .from_request (request )
125137 field_values = self .model_values ()
@@ -135,24 +147,6 @@ def create(self, appointment, request):
135147
136148 return mastectomy_or_lumpectomy_history
137149
138-
139- class MastectomyOrLumpectomyHistoryUpdateForm (MastectomyOrLumpectomyHistoryBaseForm ):
140- def __init__ (self , instance , * args , ** kwargs ):
141- self .instance = instance
142-
143- kwargs ["initial" ] = {
144- "left_breast_procedure" : instance .left_breast_procedure ,
145- "right_breast_procedure" : instance .right_breast_procedure ,
146- "left_breast_other_surgery" : instance .left_breast_other_surgery ,
147- "right_breast_other_surgery" : instance .right_breast_other_surgery ,
148- "year_of_surgery" : instance .year_of_surgery ,
149- "surgery_reason" : instance .surgery_reason ,
150- "surgery_other_reason_details" : instance .surgery_other_reason_details ,
151- "additional_details" : instance .additional_details ,
152- }
153-
154- super ().__init__ (* args , ** kwargs )
155-
156150 def update (self , request ):
157151 self .instance .left_breast_procedure = self .cleaned_data ["left_breast_procedure" ]
158152 self .instance .right_breast_procedure = self .cleaned_data [
0 commit comments