diff --git a/app/web/forms.py b/app/web/forms.py index d8f8225..c4a615d 100644 --- a/app/web/forms.py +++ b/app/web/forms.py @@ -149,13 +149,12 @@ def validate_update_date(self, field): raise validators.StopValidation() elif ( self.update_status.data == "completed" - and naive_utcnow() > self._start_date + and naive_utcnow() < self._start_date ): raise validators.ValidationError( "The date cannot be earlier than the start date" ) - if field.data is None: - if self.update_status.data == "modified": + elif self.update_status.data == "modified": field.errors[:] = [] raise validators.StopValidation() if field.data is not None: @@ -163,26 +162,32 @@ def validate_update_date(self, field): self.update_date.data, self.timezone.data, ) - else: - upd_date_form = None - raise validators.ValidationError("Update date cannot be empty") - - if field.data is not None and self.update_status.data == "completed": - if upd_date_form < self._start_date: + if ( + self.update_status.data == "completed" + and upd_date_form < self._start_date + ): raise validators.ValidationError( "The date cannot be earlier than the start date" ) - if self.update_status.data == "in progress": - if upd_date_form > naive_utcnow(): + elif ( + self.update_status.data == "in progress" + and upd_date_form > naive_utcnow() + ): raise validators.ValidationError( "Update date cannot be in the future" ) - if self._updates_ts: + elif ( + self.update_status.data == "in progress" + and self._updates_ts + ): raise validators.ValidationError( "This maintenance already has a status update, " "no statuses should be present." ) - if upd_date_form > self._end_date: + elif ( + self.update_status.data == "in progress" + and upd_date_form > self._end_date + ): raise validators.ValidationError( "Update date cannot be later than the end date" ) diff --git a/app/web/routes.py b/app/web/routes.py index fa98502..b91818b 100644 --- a/app/web/routes.py +++ b/app/web/routes.py @@ -96,9 +96,13 @@ def form_submission(form, incident): "in progress": "/", } - if new_status in ["completed", "resolved"]: + if new_status == "resolved": new_impact = incident.impact incident.end_date = update_date or naive_utcnow() + elif new_status == "completed": + new_impact = incident.impact + update_date = naive_utcnow() + incident.end_date = update_date elif new_status == "reopened": update_date = naive_utcnow() incident.end_date = None diff --git a/app/web/templates/incident.html b/app/web/templates/incident.html index 569f220..f648870 100644 --- a/app/web/templates/incident.html +++ b/app/web/templates/incident.html @@ -212,7 +212,7 @@