Skip to content

Commit

Permalink
View naming convention cms-model-list/detail
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed May 28, 2024
1 parent 1d03d7c commit 1d5f0c5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
10 changes: 8 additions & 2 deletions djangocms_rest/serializers/pageserializer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.db import models
from django.urls import reverse
from rest_framework import serializers
from rest_framework.request import Request

Expand Down Expand Up @@ -76,7 +77,6 @@ def to_representation(self, page_content):
placeholder.slot
for placeholder in page_content.page.get_declared_placeholders()
]
print(f"{declared_slots=}")
placeholders = [
placeholder
for placeholder in page_content.page.get_placeholders(page_content.language)
Expand Down Expand Up @@ -104,7 +104,13 @@ def to_representation(self, page_content):
"absolute_url": page_content.page.get_absolute_url(
page_content.language
),
"path": page_content.page.get_path(page_content.language),
"path": f"{self.request.scheme}://{self.request.get_host()}" + reverse(
"cms-page-root",
args=(page_content.language,)
) if page_content.page.is_home else f"{self.request.scheme}://{self.request.get_host()}" + reverse(
"cms-page-detail",
args=(page_content.language, page_content.page.get_path(page_content.language),)
),
"is_home": page_content.page.is_home,
"languages": page_content.page.languages.split(","),
}
2 changes: 1 addition & 1 deletion djangocms_rest/serializers/placeholder.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def to_representation(self, instance):
{
placeholder.slot: self.host
+ reverse(
"placeholder-detail",
"cms-placeholder-detail",
args=(
self.language,
content_type_id,
Expand Down
10 changes: 5 additions & 5 deletions djangocms_rest/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
from . import views

urlpatterns = [
path("", views.LanguageList.as_view(), name="languages-list"),
path("<slug:language>/pages", views.PageList.as_view(), name="pages-list"),
path("<slug:language>/pages/", views.PageDetail.as_view(), name="pages-root"),
path("<slug:language>/pages/<path:path>/", views.PageDetail.as_view()),
path("", views.LanguageList.as_view(), name="language-list"),
path("<slug:language>/pages", views.PageList.as_view(), name="cms-page-list"),
path("<slug:language>/pages/", views.PageDetail.as_view(), name="cms-page-root"),
path("<slug:language>/pages/<path:path>/", views.PageDetail.as_view(), name="cms-page-detail"),
path(
"<slug:language>/placeholders/<int:content_type_id>/<int:object_id>/<str:slot>/",
views.PlaceholderDetail.as_view(),
name="placeholder-detail",
name="cms-placeholder-detail",
),
]

Expand Down
2 changes: 1 addition & 1 deletion djangocms_rest/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get(self, request, format=None):
raise Http404
for conf in languages:
conf["pages"] = f"{request.scheme}://{request.get_host()}" + reverse(
"pages-list", args=(conf["code"],)
"cms-page-list", args=(conf["code"],)
)
return Response(languages)

Expand Down

0 comments on commit 1d5f0c5

Please sign in to comment.