-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Add menu endpoints #49
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
Open
fsbraun
wants to merge
18
commits into
main
Choose a base branch
from
fest/menu-endpoint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
db0fd08
feat: Add serializer for menu nodes
fsbraun 9101c43
feat: endpoints and noop-views
fsbraun e2e4707
feat: Working serializer
fsbraun c5956d0
Fix: request.current_page
fsbraun 352b2a4
perf: Avoid page query for menu-root
fsbraun 5a2c83f
feat: Rename endpoints
fsbraun c705a36
feat: Replace preview endpoints by "?preview" GET param
fsbraun 8675f4d
Update djangocms_rest/views.py
fsbraun 37fe8bb
tests: Add first menu test
fsbraun caf21ff
Improve tests
fsbraun e1b2358
fix utils test case
fsbraun 4e3b481
Add menu below id, submenu and breadcrumbs
fsbraun a948e34
Update readme
fsbraun b375e13
Update tests
fsbraun d556d8c
fix: No class patching -> better thread-savety
fsbraun cbe17ca
fix: Pickling error
fsbraun e3dfc79
add comment
fsbraun b29b7e7
Merge branch 'main' into fest/menu-endpoint
fsbraun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from rest_framework import serializers | ||
|
||
from menus.base import NavigationNode | ||
|
||
from djangocms_rest.utils import get_absolute_frontend_url | ||
|
||
|
||
class NavigationNodeSerializer(serializers.Serializer): | ||
id = serializers.IntegerField() | ||
namespace = serializers.CharField(allow_null=True) | ||
title = serializers.CharField() | ||
url = serializers.URLField(allow_null=True) | ||
api_endpoint = serializers.URLField(allow_null=True) | ||
visible = serializers.BooleanField() | ||
selected = serializers.BooleanField() | ||
attr = serializers.DictField(allow_null=True) | ||
level = serializers.IntegerField(allow_null=True) | ||
children = serializers.SerializerMethodField() | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.request = self.context.get("request") | ||
|
||
def get_children(self, obj: NavigationNode) -> list[dict]: | ||
# Assuming obj.children is a list of NavigationNode-like objects | ||
serializer = NavigationNodeSerializer( | ||
obj.children or [], many=True, context=self.context | ||
) | ||
return serializer.data | ||
|
||
def to_representation(self, obj: NavigationNode) -> dict: | ||
"""Customize the base representation of the NavigationNode.""" | ||
return { | ||
"id": obj.id, | ||
"title": obj.title, | ||
"url": get_absolute_frontend_url(self.request, obj.url), | ||
"api_endpoint": get_absolute_frontend_url(self.request, obj.api_endpoint), | ||
"visible": obj.visible, | ||
"selected": obj.selected | ||
or obj.attr.get("is_home", False) | ||
fsbraun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
and getattr(self.request, "is_home", False), | ||
"attr": obj.attr, | ||
"level": obj.level, | ||
"children": self.get_children(obj), | ||
} | ||
|
||
|
||
class NavigationNodeListSerializer(serializers.ListSerializer): | ||
child = NavigationNodeSerializer() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.