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 live content in page preview #3427

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion integreat_cms/cms/forms/pages/mirrored_page_field_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class MirroredPageFieldWidget(forms.widgets.Select):
#: The current language slug
language_slug: str | None = None

mirrored_page_region_slug: str | None = None

def create_option(
self,
name: str,
Expand Down Expand Up @@ -59,7 +61,7 @@ def create_option(
preview_url = reverse(
"get_page_content_ajax",
kwargs={
"region_slug": self.form.instance.region.slug,
"region_slug": self.mirrored_page_region_slug,
"language_slug": self.language_slug,
"page_id": value,
},
Expand Down
3 changes: 3 additions & 0 deletions integreat_cms/cms/forms/pages/page_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ def __init__(self, **kwargs: Any) -> None:
self.fields[
"mirrored_page_region"
].initial = self.instance.mirrored_page.region_id
self.fields[
"mirrored_page"
].widget.mirrored_page_region_slug = self.instance.mirrored_page.region.slug

# Let mirrored page queryset be empty per default and only fill it if a region is selected
mirrored_page_queryset = Page.objects.none()
Expand Down
3 changes: 2 additions & 1 deletion integreat_cms/cms/views/pages/page_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def get_page_content_ajax(

:return: Page translation content as a JSON.
"""
region = request.region
region = Region.objects.filter(slug=region_slug).first()
page = get_object_or_404(region.pages, id=page_id)
if page_translation := page.get_translation(language_slug):
return JsonResponse(data={"content": page_translation.content})
Expand Down Expand Up @@ -597,6 +597,7 @@ def render_mirrored_page_field(
)
# Pass language to mirrored page widget to render the preview urls
page_form.fields["mirrored_page"].widget.language_slug = language_slug
page_form.fields["mirrored_page"].widget.mirrored_page_region_slug = region.slug
return render(
request,
"pages/_mirrored_page_field.html",
Expand Down
Loading