Skip to content

Commit

Permalink
Update release notes, test and source
Browse files Browse the repository at this point in the history
  • Loading branch information
DevChima committed Feb 5, 2025
1 parent 9e597a6 commit 6a07f70
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Answer responses for Forms
- Language_code field on imports and exports
- Fix for assessment import for multiple languages
### Removed
- Locale field on exports
-->
Expand Down
24 changes: 6 additions & 18 deletions home/import_assessments.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,31 +264,23 @@ def add_field_values_to_assessment(self, assessment: Assessment) -> None:
assessment.high_result_page_id = (
None
if self.high_result_page == ""
else get_content_page_id_from_slug(
self.high_result_page, self.locale.language_code
)
else get_content_page_id_from_slug(self.high_result_page, self.locale)
)
assessment.medium_inflection = self.medium_inflection
assessment.medium_result_page_id = (
None
if self.medium_result_page == ""
else get_content_page_id_from_slug(
self.medium_result_page, self.locale.language_code
)
else get_content_page_id_from_slug(self.medium_result_page, self.locale)
)
assessment.low_result_page_id = (
None
if self.low_result_page == ""
else get_content_page_id_from_slug(
self.low_result_page, self.locale.language_code
)
else get_content_page_id_from_slug(self.low_result_page, self.locale)
)
assessment.skip_high_result_page_id = (
None
if self.skip_high_result_page == ""
else get_content_page_id_from_slug(
self.skip_high_result_page, self.locale.language_code
)
else get_content_page_id_from_slug(self.skip_high_result_page, self.locale)
)
assessment.skip_threshold = self.skip_threshold
assessment.generic_error = self.generic_error
Expand Down Expand Up @@ -406,19 +398,15 @@ def from_flat(cls, row: dict[str, str], row_num: int) -> "AssessmentRow":
)


def get_content_page_id_from_slug(slug: str, locale: str) -> int:
def get_content_page_id_from_slug(slug: str, locale: Locale) -> int:
try:
page = ContentPage.objects.get(slug=slug, locale__language_code=locale)
page = ContentPage.objects.get(slug=slug, locale=locale)
except ObjectDoesNotExist:
raise ImportAssessmentException(
f"You are trying to add an assessment, where one of the result pages "
f"references the content page with slug {slug} and locale {locale} which does not exist. "
"Please create the content page first."
)
except ContentPage.MultipleObjectsReturned:
raise ImportAssessmentException(
f"Multiple ContentPages found with slug '{slug}' and locale '{locale}'. Please ensure slugs are unique within each locale."
)
return page.id


Expand Down
2 changes: 1 addition & 1 deletion home/tests/test_assessment_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def test_missing_related_pages(self, csv_impexp: ImportExport) -> None:
assert (
e.value.message
== "You are trying to add an assessment, where one of the result pages "
"references the content page with slug fake-page and locale en which does not exist. "
"references the content page with slug fake-page and locale English which does not exist. "
"Please create the content page first."
)

Expand Down

0 comments on commit 6a07f70

Please sign in to comment.