Skip to content

Commit c4f8366

Browse files
committed
Add setting for JSON view and update readme
1 parent 5026714 commit c4f8366

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ projects, this is often not the case.
6666

6767
**Limitations and considerations in headless mode:**
6868

69-
- Inline editing and content preview are currently only available in a structured view. (Solutions
70-
are currently being evaluated).
69+
- Inline editing and content preview are available as JSON views on both edit and preview mode. Turn
70+
JSON rendering on and of using the `REST_JSON_RENDERING` setting.
7171
- Not all features of a standard Django CMS are available through the API (eg. templates and tags).
7272
- The API focuses on fetching plugin content and page structure as JSON data.
7373
- Website rendering is entirely decoupled and must be implemented in the frontend framework.
@@ -140,12 +140,15 @@ class CustomHeadingPluginModel(CMSPlugin):
140140
Yes, djangocms-rest provides out of the box support for any and all django CMS plugins whose content
141141
can be serialized.
142142

143+
Custom DRF serializers can be declared for custom plugins by setting its `serializer_class` property.
143144

144145
## Does the TextPlugin (Rich Text Editor, RTE) provide a json representation of the rich text?
145146

146147
Yes, djangocms-text has both HTML blob and structured JSON support for rich text.
147148

148-
URLs to other CMS objects are dynamic, in the form of `<app-name>.<object-name>:<uid>`, for example
149+
URLs to other Django model objects are dynamic and resolved to API endpoints if possible. If the referenced model
150+
provides a `get_api_endpoint()` method, it is used for resolution. If not, djangocms-rest tries to reverse `<model-name>-detail`.
151+
If resolution fails dynamic objects are returned in the form of `<app-name>.<object-name>:<uid>`, for example
149152
`cms.page:2`. The frontend can then use this to resolve the object and create the appropriate URLs
150153
to the object's frontend representation.
151154

djangocms_rest/cms_config.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from functools import cached_property
22

3+
from django.conf import settings
34
from django.urls import NoReverseMatch, reverse
45

56
from cms.app_base import CMSAppConfig
@@ -49,11 +50,15 @@ class RESTToolbarMixin:
4950
def __init__(self, *args, **kwargs):
5051
super().__init__(*args, **kwargs)
5152

52-
@cached_property
53-
def content_renderer(self):
54-
from .plugin_rendering import RESTRenderer
53+
if getattr(
54+
settings, "REST_JSON_RENDERING", not getattr(settings, "CMS_TEMPLATES", False)
55+
):
5556

56-
return RESTRenderer(request=self.request)
57+
@cached_property
58+
def content_renderer(self):
59+
from .plugin_rendering import RESTRenderer
60+
61+
return RESTRenderer(request=self.request)
5762

5863

5964
class RESTCMSConfig(CMSAppConfig):

0 commit comments

Comments
 (0)