Skip to content

Commit

Permalink
Fix KeyError 'changes_to_release_date' (#26)
Browse files Browse the repository at this point in the history
* Fix `KeyError 'changes_to_release_date'`
  Cannot quite reproduce in tests nor locally
* Fix typo in Analysis series help text
* Further tidy ups
  • Loading branch information
zerolab authored and nehakerung committed Nov 18, 2024
1 parent 68c8e24 commit 7bb1076
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cms/analysis/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AnalysisSeries(RoutablePageMixin, Page):
HelpPanel(
content=_(
"This is a container for Analysis series. It provides the <code>/latest</code>,"
"<code>/previous-release</code> evergreen paths, as well as the actual analysis pages. "
"<code>/previous-releases</code> evergreen paths, as well as the actual analysis pages. "
"Add a new Analysis page under this container."
)
),
Expand Down
23 changes: 12 additions & 11 deletions cms/release_calendar/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ def clean(self) -> dict:
"""Validate the submitted release calendar data."""
cleaned_data: dict = super().clean()

status = cleaned_data["status"]
status = cleaned_data.get("status")

if status == ReleaseStatus.CANCELLED and not cleaned_data["notice"]:
if status == ReleaseStatus.CANCELLED and not cleaned_data.get("notice"):
raise ValidationError({"notice": _("The notice field is required when the release is cancelled")})

if status in [ReleaseStatus.CONFIRMED, ReleaseStatus.PUBLISHED]:
if not cleaned_data["release_date"]:
if not cleaned_data.get("release_date"):
raise ValidationError(
{"release_date": _("The release date field is required when the release is confirmed")}
)

if (
self.instance.release_date
and self.instance.release_date != cleaned_data["release_date"]
and len(self.instance.changes_to_release_date) == len(cleaned_data["changes_to_release_date"])
and self.instance.release_date != cleaned_data.get("release_date")
and len(self.instance.changes_to_release_date) == len(cleaned_data.get("changes_to_release_date", []))
):
# A change in the release date requires updating changes_to_release_date
raise ValidationError(
Expand All @@ -53,23 +53,24 @@ def clean(self) -> dict:
)

if (
cleaned_data["release_date"]
and cleaned_data["next_release_date"]
cleaned_data.get("release_date")
and cleaned_data.get("next_release_date")
and cleaned_data["release_date"] >= cleaned_data["next_release_date"]
):
raise ValidationError({"next_release_date": _("The next release date must be after the release date.")})

if cleaned_data["release_date"] and cleaned_data["release_date_text"]:
release_date_text = cleaned_data.get("release_date_text")
if cleaned_data.get("release_date") and release_date_text:
error = _("Please enter the release date or the release date text, not both.")
raise ValidationError({"release_date": error, "release_date_text": error})

if cleaned_data["next_release_date"] and cleaned_data["next_release_text"]:
if cleaned_data.get("next_release_date") and cleaned_data.get("next_release_text"):
error = _("Please enter the next release date or the next release text, not both.")
raise ValidationError({"next_release_date": error, "next_release_text": error})

# TODO: expand to validate for non-English locales when adding multi-language.
if cleaned_data["release_date_text"] and self.instance.locale_id == Locale.get_default().pk:
self.validate_english_release_date_text_format(cleaned_data["release_date_text"])
if release_date_text and self.instance.locale_id == Locale.get_default().pk:
self.validate_english_release_date_text_format(release_date_text)

return cleaned_data

Expand Down

0 comments on commit 7bb1076

Please sign in to comment.