8000 feat: Add `FrontendEditableAdminMixin` endpoint to plugins by fsbraun · Pull Request #8062 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

feat: Add FrontendEditableAdminMixin endpoint to plugins #8062

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 20 commits into from
Nov 7, 2024

Conversation

fsbraun
Copy link
Member
@fsbraun fsbraun commented Nov 5, 2024

Description

django CMS provides editing endpoints and frontend support for general models through FrontendEditableAdminMixin. Specifically, it supports editing a subset of fields only.

This PR extends this feature to plugin models which have no model admin registered for themselves, but are managed by the PlaceholderAdmin class. Literally, a few lines of code allow us to have partial editing endpoints for plugins. These can be used for inline editing, for example.

This PR

  • Splits the FrontendEditableAdminMixin into two classes, a base class (BaseEditableAdminMixin) which provides the endpoint, and a specific class (FrontendEditableAdmin) that provides the interface to the model admin.
  • The BaseEditableAdminMixin is added to the PlaceholderAdmin along with the appropriate methods to
    • retrieve the object being edited
    • find its admin instance (which is its plugin class)
  • Tweaks some tricks in the existing FrontendEditableAdminMixin:
    • Replaces get_plugin_name attributes by callables (makes no difference for the template engine, but does for the plugin class)
    • When changing a plugin, the response does not trigger a page reload but just a local update of the plugin through the data bridge
    • Finally, it provides the placeholder endpoints for plugin models instead of the model admin endpoint (which does not exist for placeholders) in all template tags based on `{% render_model %}

Usage

With this PR, partial edit can be included by replacing {{ instance.field }} in a plugin's template by {% render_model instance "field" "field,other_field" %}. Upon double-click this will open a modal with two input fields: field and other_fields.

Especially interesting is the use of {% render_model instance "field" "field" %} which will render the field and allow editing just itself. djangocms-text will take this to inline editing if it is active. See this short demo here on an unstyled blog title field and content fields (not plugins):

inlnie-fields

Any field type can be edited inline if there is an apps (such as djangocms-text) supporting it for that field type. djangocms-text supports HTMLField and CharField.

Docs and tests

... are here now.

Related resources

  • #...
  • #...

Checklist

  • I have opened this pull request against develop-4
  • I have added or modified the tests when changing logic
  • I have followed the conventional commits guidelines to add meaningful information into the changelog
  • I have read the contribution guidelines and I have joined the channel #pr-reviews on our Discord Server to find a “pr review buddy” who is going to review my pull request.

@fsbraun fsbraun requested review from vinitkumar and marksweb and removed request for vinitkumar November 5, 2024 10:41
Copy link
Member
@vinitkumar vinitkumar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@fsbraun fsbraun marked this pull request as ready for review November 6, 2024 21:51
@fsbraun fsbraun merged commit 0224f1e into django-cms:develop-4 Nov 7, 2024
51 checks passed
@fsbraun fsbraun deleted the feat/inline-editing branch November 7, 2024 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0