Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix KeyError 'changes_to_release_date' #26

Merged
merged 4 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading