@@ -509,6 +509,61 @@ def action_plan_condition(self):
509
509
return None
510
510
return condition
511
511
512
+ def save_data (self , reply ):
513
+ old_values = {}
514
+ for prop , default in self .monitored_properties .items ():
515
+ val = getattr (self .context , prop , default )
516
+ old_values [prop ] = val
517
+
518
+ self .set_answer_data (reply )
519
+
520
+ session = Session ()
521
+ changed = self .set_measure_data (reply , session )
522
+
523
+ if reply .get ("answer" , None ):
524
+ # If answer is not present in the request, do not attempt to set
525
+ # any action-related data, since the request might have come
526
+ # from a sub-form.
527
+ if self .webhelpers .integrated_action_plan :
528
+ new_plans , changes = self .extract_plans_from_request ()
529
+ for plan in (
530
+ self .context .standard_measures + self .context .custom_measures
531
+ ):
532
+ session .delete (plan )
533
+ self .context .action_plans .extend (new_plans )
534
+ changed = changes or changed
535
+
536
+ # This only happens on custom risks
537
+ if reply .get ("handle_custom_description" ):
538
+ self .context .custom_description = self .webhelpers .check_markup (
539
+ reply .get ("custom_description" )
540
+ )
541
+
542
+ if reply .get ("title" ):
543
+ self .context .title = reply .get ("title" )
544
+
545
+ if not changed :
546
+ for prop , default in self .monitored_properties .items ():
547
+ val = getattr (self .context , prop , None )
548
+ if val and val != old_values [prop ]:
549
+ changed = True
550
+ break
551
+ if changed :
552
+ self .session .touch ()
553
+
554
+ def post (self ):
555
+ reply = self .request .form
556
+ if not self .webhelpers .can_edit_session :
557
+ return self .proceed_to_next (reply )
558
+ _next = self ._get_next (reply )
559
+ # Don't persist anything if the user skipped the question
560
+ if _next == "skip" :
561
+ return self .proceed_to_next (reply )
562
+
563
+ self .save_data (reply )
564
+
565
+ return self .proceed_to_next (reply )
566
+
512
567
def __call__ (self ):
513
568
# Render the page only if the user has inspection rights,
514
569
# otherwise redirect to the start page of the session.
@@ -523,64 +578,15 @@ def __call__(self):
523
578
self .set_parameter_values ()
524
579
525
580
if self .request .method == "POST" :
526
- reply = self .request .form
527
- if not self .webhelpers .can_edit_session :
528
- return self .proceed_to_next (reply )
529
- _next = self ._get_next (reply )
530
- # Don't persist anything if the user skipped the question
531
- if _next == "skip" :
532
- return self .proceed_to_next (reply )
533
- old_values = {}
534
- for prop , default in self .monitored_properties .items ():
535
- val = getattr (self .context , prop , default )
536
- old_values [prop ] = val
537
-
538
- self .set_answer_data (reply )
539
-
540
- session = Session ()
541
- changed = self .set_measure_data (reply , session )
542
-
543
- if reply .get ("answer" , None ):
544
- # If answer is not present in the request, do not attempt to set
545
- # any action-related data, since the request might have come
546
- # from a sub-form.
547
- if self .webhelpers .integrated_action_plan :
548
- new_plans , changes = self .extract_plans_from_request ()
549
- for plan in (
550
- self .context .standard_measures + self .context .custom_measures
551
- ):
552
- session .delete (plan )
553
- self .context .action_plans .extend (new_plans )
554
- changed = changes or changed
555
-
556
- # This only happens on custom risks
557
- if reply .get ("handle_custom_description" ):
558
- self .context .custom_description = self .webhelpers .check_markup (
559
- reply .get ("custom_description" )
560
- )
561
-
562
- if reply .get ("title" ):
563
- self .context .title = reply .get ("title" )
581
+ return self .post ()
564
582
565
- if not changed :
566
- for prop , default in self .monitored_properties .items ():
567
- val = getattr (self .context , prop , None )
568
- if val and val != old_values [prop ]:
569
- changed = True
570
- break
571
- if changed :
572
- self .session .touch ()
573
-
574
- return self .proceed_to_next (reply )
575
-
576
- else :
577
- self ._prepare_risk ()
578
- if self .is_custom_risk :
579
- next = FindNextQuestion (
580
- self .context , self .context .session , filter = self .question_filter
581
- )
582
- self .has_next_risk = next or False
583
- return self .template ()
583
+ self ._prepare_risk ()
584
+ if self .is_custom_risk :
585
+ next = FindNextQuestion (
586
+ self .context , self .context .session , filter = self .question_filter
587
+ )
588
+ self .has_next_risk = next or False
589
+ return self .template ()
584
590
585
591
@property
586
592
def template (self ):
0 commit comments