Skip to content

Commit b5bf099

Browse files
metaforxfsbraun
andauthored
feat: extend page serializer with additional page fields (#35)
* feat: extend page serializer with additional fields (`depth`, `numchild`, `login_required`, `application_namespace`) and update tests (types) * docs: update README with revised API responses and disclaimers * Update pyproject.toml * refactor: remove `depth` and `numchild` fields from page serializer and types --------- Co-authored-by: Fabian Braun <[email protected]>
1 parent 532da54 commit b5bf099

File tree

4 files changed

+36
-15
lines changed

4 files changed

+36
-15
lines changed

README.md

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ permissions for authenticated staff user<br>
2424

2525
🧩 **Flexible responses** – Fetch plugin content as JSON or fully rendered HTML
2626

27-
> ⚠️ **Disclaimer**
27+
> ⚠️ **Note**
2828
>
29-
> `djangocms-rest` is under active development. While it is safe to explore and test, using it in
30-
> production is at your own responsibility.
31-
>
32-
> The impact is limited since the API is **read-only** and does not expose any write operations.
29+
> `djangocms-rest` is under active development. Since the API is read-only, it's safe to explore
30+
> without risk of unintended data changes.
3331
3432
## What is headless mode?
3533

@@ -260,15 +258,20 @@ https://drf-spectacular.readthedocs.io/en/latest/index.html
260258
"absolute_url": "string",
261259
"path": "string",
262260
"is_home": true,
261+
"login_required": true,
263262
"in_navigation": true,
264263
"soft_root": true,
265264
"template": "string",
266265
"xframe_options": "string",
267-
"limit_visibility_in_menu": true,
266+
"limit_visibility_in_menu": false,
268267
"language": "string",
269268
"languages": [
270269
"string"
271270
],
271+
"is_preview": false,
272+
"application_namespace": "string",
273+
"creation_date": "2025-05-29T07:59:21.301Z",
274+
"changed_date": "2025-05-29T07:59:21.301Z",
272275
"children": []
273276
}
274277
```
@@ -310,7 +313,9 @@ To determine permissions `user_can_view_page()` from djangocms is used, usually
310313

311314
### Sample API-Response: api/{en}/pages/{sub}/
312315

316+
> GET CONTENT using `/api/{language}/placeholders/{content_type_id}/{object_id}/{slot}/`
313317
```json
318+
314319
{
315320
"title": "sub",
316321
"page_title": "sub",
@@ -319,31 +324,39 @@ To determine permissions `user_can_view_page()` from djangocms is used, usually
319324
"redirect": null,
320325
"in_navigation": true,
321326
"soft_root": false,
322-
"template": "INHERIT",
323-
"xframe_options": 0,
324-
"limit_visibility_in_menu": null,
327+
"template": "home.html",
328+
"xframe_options": "",
329+
"limit_visibility_in_menu": false,
325330
"language": "en",
326331
"path": "sub",
327332
"absolute_url": "/sub/",
328333
"is_home": false,
334+
"login_required": false,
329335
"languages": [
330336
"en"
331337
],
332338
"is_preview": false,
333-
"creation_date": "2025-02-26T21:22:16.844637Z",
334-
"changed_date": "2025-02-26T21:22:16.856326Z",
335-
// GET CONTENT using `/api/{language}/placeholders/{content_type_id}/{object_id}/{slot}/`
339+
"application_namespace": null,
340+
"creation_date": "2025-02-27T16:49:01.180050Z",
341+
"changed_date": "2025-02-27T16:49:01.180214Z",
336342
"placeholders": [
337343
{
338344
"content_type_id": 5,
339-
"object_id": 5,
345+
"object_id": 6,
340346
"slot": "content"
347+
},
348+
{
349+
"content_type_id": 5,
350+
"object_id": 6,
351+
"slot": "cta"
341352
}
342353
]
343354
}
344355
```
345356

346-
### Sample API-Response: api/{en}/placeholders/{5}/{5}/{content}/[?html=1]
357+
### Sample API-Response: api/{en}/placeholders/{5}/{6}/{content}/[?html=1]
358+
359+
> Rendered HTML with an optional flag ?html=1
347360

348361
```json
349362
{
@@ -375,7 +388,6 @@ To determine permissions `user_can_view_page()` from djangocms is used, usually
375388
}
376389
],
377390
"html": "<p>Test Content</p>"
378-
//Rendered HTML when uins ?html=1
379391
}
380392
```
381393

djangocms_rest/serializers/pages.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class BasePageSerializer(serializers.Serializer):
1616
absolute_url = serializers.URLField(max_length=200, allow_blank=True)
1717
path = serializers.CharField(max_length=200)
1818
is_home = serializers.BooleanField()
19+
login_required = serializers.BooleanField()
1920
in_navigation = serializers.BooleanField()
2021
soft_root = serializers.BooleanField()
2122
template = serializers.CharField(max_length=100)
@@ -24,6 +25,7 @@ class BasePageSerializer(serializers.Serializer):
2425
language = serializers.CharField(max_length=10)
2526
languages = serializers.ListSerializer(child=serializers.CharField(), allow_empty=True, required=False)
2627
is_preview = serializers.BooleanField(default=False)
28+
application_namespace = serializers.CharField(max_length=200, allow_null=True)
2729
creation_date = serializers.DateTimeField()
2830
changed_date = serializers.DateTimeField()
2931

@@ -56,8 +58,10 @@ def get_base_representation(self, page_content: PageContent) -> Dict:
5658
"path": relative_url,
5759
"absolute_url": absolute_url,
5860
"is_home": page_content.page.is_home,
61+
"login_required": page_content.page.login_required,
5962
"languages": page_content.page.get_languages(),
6063
"is_preview": getattr(self, "is_preview", False),
64+
"application_namespace": page_content.page.application_namespace,
6165
"creation_date": page_content.creation_date,
6266
"changed_date": page_content.changed_date,
6367
}

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ classifiers = [
1515
"Framework :: Django",
1616
"Framework :: Django :: 4.2",
1717
"Framework :: Django :: 5.0",
18+
"Framework :: Django :: 5.1",
19+
"Framework :: Django :: 5.2",
1820
"Framework :: Django CMS",
1921
"Framework :: Django CMS :: 4.0",
2022
"Framework :: Django CMS :: 4.1",
23+
"Framework :: Django CMS :: 5.0",
2124
"Intended Audience :: Developers",
2225
"License :: OSI Approved :: BSD License",
2326
"Operating System :: OS Independent",

tests/types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
"path": str,
2020
"absolute_url": str,
2121
"is_home": bool,
22+
"login_required": bool,
2223
"languages": list,
2324
"is_preview": bool,
25+
"application_namespace": (str, type(None)),
2426
"creation_date": (str, "datetime"),
2527
"changed_date": (str, "datetime"),
2628
}

0 commit comments

Comments
 (0)