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

fixed web preview #239

Merged
merged 3 commits into from
Jan 30, 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
6 changes: 3 additions & 3 deletions home/import_content_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def __init__(
self.locale = locale
self.locale_map: dict[str, Locale] = {}
self.shadow_pages: dict[PageId, ShadowContentPage] = {}
self.go_to_page_buttons: dict[
PageId, dict[int, list[dict[str, Any]]]
] = defaultdict(lambda: defaultdict(list))
self.go_to_page_buttons: dict[PageId, dict[int, list[dict[str, Any]]]] = (
defaultdict(lambda: defaultdict(list))
)

def locale_from_display_name(self, langname: str) -> Locale:
if langname not in self.locale_map:
Expand Down
20 changes: 20 additions & 0 deletions home/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,26 @@ def clean(self):
# The variable check is only for templates
if self.is_whatsapp_template and len(self.whatsapp_body.raw_data) > 0:
whatsapp_message = self.whatsapp_body.raw_data[0]["value"]["message"]

right_mismatch = re.findall(r"(?<!\{){[^{}]*}\}", whatsapp_message)
left_mismatch = re.findall(r"\{{[^{}]*}(?!\})", whatsapp_message)
mismatches = right_mismatch + left_mismatch

if mismatches:
errors.setdefault("whatsapp_body", []).append(
StreamBlockValidationError(
{
0: StreamBlockValidationError(
{
"message": ValidationError(
f"Please provide variables with matching braces. You provided {mismatches}."
)
}
)
}
)
)

vars_in_msg = re.findall(r"{{(.*?)}}", whatsapp_message)
non_digit_variables = [var for var in vars_in_msg if not var.isdecimal()]

Expand Down
12 changes: 12 additions & 0 deletions home/templates/home/content_page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "base.html" %}
{% load wagtailcore_tags %}

{% block body_class %}template-contentpage{% endblock %}


{% block content %}
<h1>{{ page.title }}</h1>
<h2>{{ page.subtitle }}</h2>
{% include_block page.body %}

{% endblock %}
2 changes: 1 addition & 1 deletion home/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def test_clean_text_valid_variables(self):
"WA Title",
[
WABlk(
"{{2}}{{1}} {{foo}}",
"{{2}}{{1}} {{foo}} {{mismatch1} {mismatch2}}",
)
],
)
Expand Down
8 changes: 5 additions & 3 deletions home/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,11 @@ def profile_field(self, obj):
def page(self, obj):
if obj.pages:
return [
p.value["contentpage"].slug
if p.value and "contentpage" in p.value
else ""
(
p.value["contentpage"].slug
if p.value and "contentpage" in p.value
else ""
)
for p in obj.pages
]
return ["-"]
Expand Down
6 changes: 3 additions & 3 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
black
ruff
black==24.1.1
ruff==0.1.14
responses
pytest
pytest==8.0.0
pytest-django
pytest-cov
pytest-xdist
Expand Down
Loading