Skip to content

Commit

Permalink
Issues 126/cet time (#130)
Browse files Browse the repository at this point in the history
Issues 126/cet time

Please provide the time for the next expected update (<small class="timezone-info"></small>).</div>
has been changed

Reviewed-by: Artem Sh.
  • Loading branch information
bakhterets authored Sep 4, 2024
1 parent dadc8a6 commit 2ee57f9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
31 changes: 18 additions & 13 deletions app/web/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,40 +149,45 @@ 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:
upd_date_form = naive_from_dttz(
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"
)
Expand Down
6 changes: 5 additions & 1 deletion app/web/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/web/templates/incident.html
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ <h6>{{ update.status }}</h6>
value="{{ form.update_date.data if form.update_date.data else '' }}"
aria-describedby="nextUpdateHelp"/>
<div id="nextUpdateHelp" class="form-text">
Please provide the time for the next expected update (<small class="timezone-info"></small>).</div>
Please provide the time for the update (<small class="timezone-info"></small>).</div>
{% if form.update_date.errors %}
<div class="invalid-feedback">
<ul class="errors">
Expand Down

0 comments on commit 2ee57f9

Please sign in to comment.