Skip to content
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
18 changes: 7 additions & 11 deletions djangocms_rest/cms_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ def get_page_api_endpoint(page, language=None, fallback=True):
if page.is_home:
return reverse("page-root", kwargs={"language": language})
path = page.get_path(language, fallback)
return (
reverse("page-detail", kwargs={"language": language, "path": path})
if path
else None
)
return reverse("page-detail", kwargs={"language": language, "path": path}) if path else None
except NoReverseMatch:
return None

Expand All @@ -51,6 +47,10 @@ def inner(self, page_content: PageContent, *args, **kwargs):
page_content.page,
page_content.language,
)
# To save API calls, we add the page's path to the node attributes
node.attr["path"] = page_content.page.get_path(
page_content.language,
)
return node

return inner
Expand All @@ -59,9 +59,7 @@ def inner(self, page_content: PageContent, *args, **kwargs):
def patch_page_menu(menu: type[CMSMenu]):
"""Patch the CMSMenu to use the REST API endpoint for pages."""
if hasattr(menu, "get_menu_node_for_page_content"):
menu.get_menu_node_for_page_content = patch_get_menu_node_for_page_content(
menu.get_menu_node_for_page_content
)
menu.get_menu_node_for_page_content = patch_get_menu_node_for_page_content(menu.get_menu_node_for_page_content)


class NavigationNodeMixin:
Expand Down Expand Up @@ -101,9 +99,7 @@ class RESTToolbarMixin:
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

if getattr(
settings, "REST_JSON_RENDERING", not getattr(settings, "CMS_TEMPLATES", False)
):
if getattr(settings, "REST_JSON_RENDERING", not getattr(settings, "CMS_TEMPLATES", False)):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fsbraun can you explain to me why we use a different output for REST_JSON_RENDERING or CMS_TEMPLATES?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REST_JSON_RENDERING toggles the JSON rendering. It is also selected when no CMS_TEMPLATES are available. If they are, the templates are used for rendering.

try:
from djangocms_text import settings

Expand Down
2 changes: 0 additions & 2 deletions djangocms_rest/serializers/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class NavigationNodeSerializer(serializers.Serializer):
namespace = serializers.CharField(allow_null=True)
title = serializers.CharField()
url = serializers.URLField(allow_null=True)
path = serializers.CharField(allow_null=True)
api_endpoint = serializers.URLField(allow_null=True)
visible = serializers.BooleanField()
selected = serializers.BooleanField()
Expand Down Expand Up @@ -40,7 +39,6 @@ def to_representation(self, obj: NavigationNode) -> dict:
"title": obj.title,
"url": get_absolute_frontend_url(self.request, obj.url) or "",
"api_endpoint": api_endpoint,
"path": path,
"visible": obj.visible,
"selected": obj.selected or obj.attr.get("is_home", False) and getattr(self.request, "is_home", False),
"attr": obj.attr,
Expand Down