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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update of FrontendEditableAdminMixin
  • Loading branch information
Github Release Action committed Nov 4, 2024
commit 24d5aeefab5d4062f6ff0352ff97ce67844ea752
5 changes: 2 additions & 3 deletions cms/admin/pageadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
from cms.constants import MODAL_HTML_REDIRECT
from cms.models import (
CMSPlugin,
EmptyPageContent,
GlobalPagePermission,
Page,
PageContent,
Expand Down Expand Up @@ -169,6 +168,7 @@ def get_urls(self):
"""Get the admin urls
"""
info = f"{self.model._meta.app_label}_{self.model._meta.model_name}"

def pat(regex, fn):
return re_path(regex, self.admin_site.admin_view(fn), name=f'{info}_{fn.__name__}')

Expand Down Expand Up @@ -763,6 +763,7 @@ def get_urls(self):
"""Get the admin urls
"""
info = f"{self.model._meta.app_label}_{self.model._meta.model_name}"

def pat(regex, fn):
return re_path(regex, self.admin_site.admin_view(fn), name=f'{info}_{fn.__name__}')

Expand Down Expand Up @@ -916,7 +917,6 @@ def response_add(self, request, obj):
return HttpResponse(MODAL_HTML_REDIRECT.format(url=url))
return super().response_add(request, obj)


def get_filled_languages(self, request, page):
site_id = get_site(request).pk
filled_languages = page.get_languages()
Expand Down Expand Up @@ -1122,7 +1122,6 @@ def change_template(self, request, object_id):
if to_template not in (placeholder_set[0] for placeholder_set in get_cms_setting('PLACEHOLDERS')):
return HttpResponseBadRequest(_("Placeholder selection not valid"))


page_content.template = to_template
page_content.save()

Expand Down
11 changes: 8 additions & 3 deletions cms/admin/placeholderadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from cms.models.placeholdermodel import Placeholder
from cms.models.placeholderpluginmodel import PlaceholderReference
from cms.models.pluginmodel import CMSPlugin
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from cms.signals import post_placeholder_operation, pre_placeholder_operation
from cms.toolbar.utils import get_plugin_tree
Expand Down Expand Up @@ -93,6 +94,7 @@ def get_urls(self):
Register the url for the single field edit view
"""
info = f"{self.model._meta.app_label}_{self.model._meta.model_name}"

def pat(regex, fn):
return re_path(regex, self.admin_site.admin_view(fn), name=f"{info}_{fn.__name__}")
url_patterns = [
Expand Down Expand Up @@ -139,7 +141,8 @@ def edit_field(self, request, object_id, language):
if not cancel_clicked and request.method == 'POST':
form = form_class(instance=obj, data=request.POST)
if form.is_valid():
form.save()
new_object = form.save(commit=False)
self.save_model(request, new_object, form, change=True) # Call save model like the admin does
saved_successfully = True
else:
form = form_class(instance=obj)
Expand Down Expand Up @@ -168,6 +171,9 @@ def edit_field(self, request, object_id, language):
})
return render(request, 'admin/cms/page/plugin/confirm_form.html', context)
if not cancel_clicked and request.method == 'POST' and saved_successfully:
if isinstance(self, CMSPluginBase):
# Update the structure board by populating the data bridge
return self.render_close_frame(request, obj)
return render(request, 'admin/cms/page/plugin/confirm_form.html', context)
return render(request, 'admin/cms/page/plugin/change_form.html', context)

Expand Down Expand Up @@ -226,6 +232,7 @@ def get_urls(self):
Register the plugin specific urls (add/edit/copy/remove/move)
"""
info = f"{self.model._meta.app_label}_{self.model._meta.model_name}"

def pat(regex, fn):
return re_path(regex, self.admin_site.admin_view(fn), name=f"{info}_{fn.__name__}")
url_patterns = [
Expand Down Expand Up @@ -1126,5 +1133,3 @@ def clear_placeholder(self, request, placeholder_id):
}
request.current_app = self.admin_site.name
return TemplateResponse(request, "admin/cms/page/plugin/delete_confirmation.html", context)


2 changes: 0 additions & 2 deletions cms/admin/settingsadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,3 @@ def get_model_perms(self, request):
Return empty perms dict thus hiding the model from admin index.
"""
return {}


18 changes: 7 additions & 11 deletions cms/templatetags/cms_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
from classytags.values import ListValue, StringValue
from django import template
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
from django.core.mail import mail_managers
from django.db.models import Model
from django.template.loader import render_to_string
Expand Down Expand Up @@ -531,25 +529,20 @@ def _get_editable_context(self, context, instance, language, edit_fields,
else:
lang = get_language()
opts = instance._meta
# Django < 1.10 creates dynamic proxy model subclasses when fields are
# deferred using .only()/.exclude(). Make sure to use the underlying
# model options when it's the case.
if getattr(instance, '_deferred', False):
opts = opts.proxy_for_model._meta
with force_language(lang):
extra_context = {}
if edit_fields == 'changelist':
instance.get_plugin_name = "{} {} list".format(smart_str(_('Edit')), smart_str(opts.verbose_name))
instance.get_plugin_name = lambda: f"{smart_str(_('Edit'))} {smart_str(opts.verbose_name)} list"
extra_context['attribute_name'] = 'changelist'
elif editmode:
instance.get_plugin_name = "{} {}".format(smart_str(_('Edit')), smart_str(opts.verbose_name))
instance.get_plugin_name = lambda: f"{smart_str(_('Edit'))} {smart_str(opts.verbose_name)}"
if not context.get('attribute_name', None):
# Make sure CMS.Plugin object will not clash in the frontend.
extra_context['attribute_name'] = '-'.join(
edit_fields
) if not isinstance('edit_fields', str) else edit_fields
else:
instance.get_plugin_name = "{} {}".format(smart_str(_('Add')), smart_str(opts.verbose_name))
instance.get_plugin_name = lambda: f"{smart_str(_('Add'))} {smart_str(opts.verbose_name)}"
extra_context['attribute_name'] = 'add'
extra_context['instance'] = instance
extra_context['generic'] = opts
Expand Down Expand Up @@ -578,7 +571,10 @@ def _get_editable_context(self, context, instance, language, edit_fields,
url_base = reverse(view_url, args=(instance.pk,))
else:
if not view_url:
view_url = f'admin:{opts.app_label}_{opts.model_name}_edit_field'
if isinstance(instance, CMSPlugin):
view_url = f'admin:{opts.app_label}_{opts.model_name}_edit_field' # TODO: Correct endpoint
else:
view_url = f'admin:{opts.app_label}_{opts.model_name}_edit_field'
if view_url.endswith('_changelist'):
url_base = reverse(view_url)
else:
Expand Down
292C
0