-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Add RESTRenderer #42
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
Merged
Merged
Changes from 22 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
266bce7
feat: Add RESTRenderer
fsbraun 1a6a8fd
ruff issues
fsbraun 870f30d
Add json formatting
fsbraun e03978a
Fix placeholder rendering
fsbraun 4edcc0f
feat: collapse objects
fsbraun c7b57b6
better evt handling
fsbraun ae98857
update formatting
fsbraun 3914853
Remove js
fsbraun 0060988
css tweaks
fsbraun 81c7f43
Robust plugin moving
fsbraun eeb624d
fix rendering
fsbraun 61e6153
Unify rendering
fsbraun 492ffff
Fix linting
fsbraun adadf8a
Sort imports
fsbraun bdb66de
Add tests
fsbraun baba357
Fix rendering bug
fsbraun 6225467
Fix bool formatting
fsbraun 51f9c85
Add link resolution
fsbraun 36c07c6
Fix tests
fsbraun 9f7f8f4
Improve tests
fsbraun 6711164
Add bs4 test requirement
fsbraun 98ba50a
Add tests for fk serialization
fsbraun 1854a71
Update djangocms_rest/serializers/pages.py
fsbraun a8f45ef
Update djangocms_rest/apps.py
fsbraun 4f91903
Update djangocms_rest/cms_config.py
fsbraun 256b2cd
Update djangocms_rest/cms_config.py
fsbraun abee91d
Update djangocms_rest/serializers/plugins.py
fsbraun 34b0fa9
Add test for preview endpoint
fsbraun 721bf5b
Removed last trailing comma
fsbraun 5026714
Add comment
fsbraun c4f8366
Add setting for JSON view and update readme
fsbraun 3db89c4
Fix tests
fsbraun ebad887
Update plugin-list
fsbraun 9f41aac
Remove unused method
fsbraun 0ad048c
Test enum types
fsbraun 4c05132
Add test for nested serializer
fsbraun ea97287
Remove debug code
fsbraun 346bd63
Add autolinks
fsbraun e6a9442
feat: Add ellipses for folded json
fsbraun b2429eb
fix: reflect site when getting current language
fsbraun f8f733f
Merge branch 'main' into feat/json-edit
fsbraun 94db37c
fix: Import get_current_site
fsbraun bbe4863
Merge branch 'feat/json-edit' of github.com:fsbraun/djangocms-rest in…
fsbraun 6a027f1
fix: Import cycle
fsbraun 20f4a0b
Feat/json edit review (#44)
metaforx 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class DjangocmsRestConfig(AppConfig): | ||
""" | ||
AppConfig for the djangocms_rest application. | ||
This application provides RESTful APIs for Django CMS. | ||
""" | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "djangocms_rest" | ||
verbose_name = "Django CMS REST API" | ||
|
||
def ready(self): | ||
try: | ||
from djangocms_text import settings | ||
|
||
settings.TEXT_INLINE_EDITING = False | ||
except (ImportError, ModuleNotFoundError): | ||
pass |
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,66 @@ | ||
from functools import cached_property | ||
|
||
from django.urls import NoReverseMatch, reverse | ||
|
||
from cms.app_base import CMSAppConfig | ||
from cms.models import Page | ||
from cms.utils.i18n import force_language, get_current_language | ||
|
||
|
||
try: | ||
from filer.models import File | ||
except (ImportError, ModuleNotFoundError): | ||
fsbraun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
File = None | ||
|
||
|
||
def get_page_api_endpoint(page, language=None, fallback=True): | ||
"""Get the API endpoint for a given page in a specific language. | ||
If the page is a home page, return the root endpoint. | ||
""" | ||
if not language: | ||
language = get_current_language() | ||
|
||
with force_language(language): | ||
try: | ||
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 | ||
) | ||
except NoReverseMatch: | ||
return None | ||
|
||
|
||
def get_file_api_endpoint(file): | ||
"""For a file reference, return the URL of the file if it is public.""" | ||
if not file: | ||
return None | ||
if file.is_public: | ||
return file.url | ||
return None | ||
fsbraun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
class RESTToolbarMixin: | ||
""" | ||
Mixin to add REST rendering capabilities to the CMS toolbar. | ||
""" | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
@cached_property | ||
def content_renderer(self): | ||
from .plugin_rendering import RESTRenderer | ||
|
||
return RESTRenderer(request=self.request) | ||
|
||
|
||
class RESTCMSConfig(CMSAppConfig): | ||
cms_enabled = True | ||
cms_toolbar_mixin = RESTToolbarMixin | ||
|
||
Page.add_to_class("get_api_endpoint", get_page_api_endpoint) | ||
File.add_to_class("get_api_endpoint", get_file_api_endpoint) if File else None |
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,8 @@ | ||
from cms.toolbar_base import CMSToolbar | ||
from cms.toolbar_pool import toolbar_pool | ||
|
||
|
||
@toolbar_pool.register | ||
class RestToolbar(CMSToolbar): | ||
class Media: | ||
css = {"all": ("djangocms_rest/highlight.css",)} |
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.