Skip to content

Commit

Permalink
Merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit Vermeulen committed Dec 11, 2024
2 parents 79c929c + 50f3462 commit d35ad72
Show file tree
Hide file tree
Showing 12 changed files with 731 additions and 43 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!--
## Unreleased
- Importing assessments with commas in inflection values will now be caught with a helpful error message
=======
### Added
- Go to form actions for lists and buttons
### Fixed
- ContentPage import: Accept xlsx where field formatting is numeric.
- Validate OrderedContentSets on import
- Forms import: Error message for differing number of answer items for different fields
- Imports: consolodate import logic so that all imports use the same code
- Imports: headers are now case-insensitive
- Importing assessments with commas in inflection values will now be caught with a helpful error message
### Security
- Updated django from 4.2.16 to 4.2.17
-->

## v1.3.0
Expand Down
5 changes: 5 additions & 0 deletions home/export_content_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ def serialise_buttons(buttons: blocks.StreamValue.StreamChild) -> str:
if button.value.get("page") is None:
continue
button_dict["slug"] = button.value["page"].slug
if button.block_type == "go_to_form":
# Exclude buttons that has deleted forms that they are linked to it
if button.value.get("form") is None:
continue
button_dict["slug"] = button.value["form"].slug

button_dicts.append(button_dict)
return dumps(button_dicts)
Expand Down
48 changes: 43 additions & 5 deletions home/import_content_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from home.import_helpers import ImportException, parse_file, validate_using_form

from .models import (
Assessment,
ContentPage,
ContentPageIndex,
ContentQuickReply,
Expand Down Expand Up @@ -185,10 +186,11 @@ def add_go_to_page_buttons(self) -> None:
f"page '{slug}'",
row.row_num,
)
page.whatsapp_body[message_index].value["buttons"].append(
("go_to_page", {"page": related_page, "title": title})
page.whatsapp_body[message_index].value["buttons"].insert(
button["index"],
("go_to_page", {"page": related_page, "title": title}),
)
page.save_revision().publish()
page.save()

def add_go_to_page_list_items(self) -> None:
for (slug, locale), messages in self.go_to_page_list_items.items():
Expand All @@ -212,7 +214,7 @@ def add_go_to_page_list_items(self) -> None:
item["index"],
("go_to_page", {"page": related_page, "title": title}),
)
page.save_revision().publish()
page.save()

def parse_file(self) -> list["ContentRow"]:
return [
Expand Down Expand Up @@ -343,7 +345,7 @@ def add_message_to_shadow_content_page_from_row(
if row.is_whatsapp_message:
page.enable_whatsapp = True
buttons = []
for button in row.buttons:
for index, button in enumerate(row.buttons):
if button["type"] == "next_message":
buttons.append(
{
Expand All @@ -353,8 +355,28 @@ def add_message_to_shadow_content_page_from_row(
}
)
elif button["type"] == "go_to_page":
button["index"] = index
page_gtps = self.go_to_page_buttons[(row.slug, locale)]
page_gtps[len(page.whatsapp_body)].append(button)
elif button["type"] == "go_to_form":
try:
form = Assessment.objects.get(
slug=button["slug"], locale=locale
)
except Assessment.DoesNotExist:
raise ImportException(
f"No form found with slug '{button['slug']}' and locale "
f"'{locale}' for go_to_form button '{button['title']}' on "
f"page '{row.slug}'"
)
buttons.append(
{
"id": str(uuid4()),
"type": button["type"],
"value": {"title": button["title"], "form": form.id},
}
)

list_items = []
for index, item in enumerate(row.list_items):
if item["type"] == "next_message":
Expand All @@ -369,6 +391,22 @@ def add_message_to_shadow_content_page_from_row(
item["index"] = index
page_gtpli = self.go_to_page_list_items[(row.slug, locale)]
page_gtpli[len(page.whatsapp_body)].append(item)
elif item["type"] == "go_to_form":
try:
form = Assessment.objects.get(slug=item["slug"], locale=locale)
except Assessment.DoesNotExist:
raise ImportException(
f"No form found with slug '{item['slug']}' and locale "
f"'{locale}' for go_to_form list item '{item['title']}' on "
f"page '{row.slug}'"
)
list_items.append(
{
"id": str(uuid4()),
"type": item["type"],
"value": {"title": item["title"], "form": form.id},
}
)
page.whatsapp_body.append(
ShadowWhatsappBlock(
message=row.whatsapp_body,
Expand Down
Loading

0 comments on commit d35ad72

Please sign in to comment.