Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix issue 2709 #2740

Merged
merged 9 commits into from

3 participants

Jacob Rief Patrick Lauber Coveralls
Jacob Rief

This PR fixes issue #2709 and terminology as discussed in #2728.
PlaceholderAdmin now is deprecated, but available as mixin class PlaceholderAdminMixin.
FrontendEditableAdmin was renamed to FrontendEditableAdminMixin since it always was a mixin class.

Patrick Lauber
Collaborator

lgtm

Patrick Lauber
Collaborator

Is the PlaceholderAdmin anywhere used in the test_utils? or tests?

Jacob Rief

Yes, please check jrief@2aa7f69

Jacob Rief

ah, you mean the old one? Emmm...., nope

Coveralls

Coverage Status

Coverage remained the same when pulling 421f999 on jrief:fix-issue-2709 into 1f27008 on divio:develop.

Patrick Lauber digi604 merged commit 7f06aea into from
Angelo Dini FinalAngel referenced this pull request
Merged

Crossbrowser fixes #2749

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
1  CHANGELOG.txt
View
@@ -188,6 +188,7 @@ Please see Install/2.4 release notes *before* attempting to upgrade to version 2
- moved apphooks from title to page model so we need to add them only once.
- request.current_app has been removed.
- added a namespace field, reverse_id is not used anymore for apphook namespaces.
+- PlaceholderAdmin is deprecated and available as mixin class renamed to PlaceholderAdminMixin.
- PlaceholderAdmin does not have LanguageTabs anymore. It only has a PluginAPI now.
- PageAdmin uses the same Plugin API as PlaceholderAdmin
- Toolbar API for your own apps added
4 cms/admin/pageadmin.py
View
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from functools import wraps
import sys
-from cms.admin.placeholderadmin import PlaceholderAdmin
+from cms.admin.placeholderadmin import PlaceholderAdminMixin
from cms.plugin_pool import plugin_pool
from django.contrib.admin.helpers import AdminForm
@@ -87,7 +87,7 @@ def create_revision():
INITIAL_COMMENT = "Initial version."
-class PageAdmin(PlaceholderAdmin, ModelAdmin):
+class PageAdmin(PlaceholderAdminMixin, ModelAdmin):
form = PageForm
search_fields = ('title_set__slug', 'title_set__title', 'reverse_id')
revision_form_template = "admin/cms/page/history/revision_header.html"
15 cms/admin/placeholderadmin.py
View
@@ -35,7 +35,7 @@
from cms.utils.i18n import get_language_list
-class FrontendEditableAdmin(object):
+class FrontendEditableAdminMixin(object):
frontend_editable_fields = []
def get_urls(self):
@@ -51,7 +51,7 @@ def get_urls(self):
'',
pat(r'edit-field/([0-9]+)/([a-z\-]+)/$', self.edit_field),
)
- return url_patterns + super(FrontendEditableAdmin, self).get_urls()
+ return url_patterns + super(FrontendEditableAdminMixin, self).get_urls()
def _get_object_for_single_field(self, object_id, language):
# Quick and dirty way to retrieve objects for django-hvad
@@ -111,7 +111,7 @@ def edit_field(self, request, object_id, language):
return render_to_response('admin/cms/page/plugin/change_form.html', context, RequestContext(request))
-class PlaceholderAdmin(ModelAdmin):
+class PlaceholderAdminMixin(object):
def get_urls(self):
"""
Register the plugin specific urls (add/edit/copy/remove/move)
@@ -130,7 +130,7 @@ def get_urls(self):
pat(r'clear-placeholder/([0-9]+)/$', self.clear_placeholder),
pat(r'move-plugin/$', self.move_plugin),
)
- return url_patterns + super(PlaceholderAdmin, self).get_urls()
+ return url_patterns + super(PlaceholderAdminMixin, self).get_urls()
def has_add_plugin_permission(self, request, placeholder, plugin_type):
if not permissions.has_plugin_permission(request.user, plugin_type, "add"):
@@ -547,3 +547,10 @@ def clear_placeholder(self, request, placeholder_id):
}
return TemplateResponse(request, "admin/cms/page/plugin/delete_confirmation.html", context,
current_app=self.admin_site.name)
+
+
+class PlaceholderAdmin(PlaceholderAdminMixin, ModelAdmin):
+ def __init__(self, *args, **kwargs):
+ warnings.warn("Class PlaceholderAdmin is deprecated and will be removed in 3.1. "
+ "Instead, combine PlaceholderAdminMixin with admin.ModelAdmin.", DeprecationWarning)
+ super(PlaceholderAdmin, self).__init__(*args, **kwargs)
4 cms/admin/static_placeholder.py
View
@@ -1,9 +1,9 @@
from cms.models import StaticPlaceholder
from django.contrib import admin
-from cms.admin.placeholderadmin import PlaceholderAdmin
+from cms.admin.placeholderadmin import PlaceholderAdminMixin
-class StaticPlaceholderAdmin(PlaceholderAdmin):
+class StaticPlaceholderAdmin(PlaceholderAdminMixin, admin.ModelAdmin):
list_display = ('name', 'code', 'creation_method')
search_fields = ('name', 'code',)
exclude = ('creation_method',)
8 cms/models/placeholdermodel.py
View
@@ -130,8 +130,8 @@ def _get_attached_fields(self):
for rel in self._meta.get_all_related_objects():
if issubclass(rel.model, CMSPlugin):
continue
- from cms.admin.placeholderadmin import PlaceholderAdmin
- if rel.model in admin.site._registry and isinstance(admin.site._registry[rel.model], PlaceholderAdmin):
+ from cms.admin.placeholderadmin import PlaceholderAdminMixin
+ if rel.model in admin.site._registry and isinstance(admin.site._registry[rel.model], PlaceholderAdminMixin):
field = getattr(self, rel.get_accessor_name())
if field.count():
self._attached_fields_cache.append(rel.field)
@@ -149,8 +149,8 @@ def _get_attached_field(self):
for rel in relations:
if issubclass(rel.model, CMSPlugin):
continue
- from cms.admin.placeholderadmin import PlaceholderAdmin
- if rel.model in admin.site._registry and isinstance(admin.site._registry[rel.model], PlaceholderAdmin):
+ from cms.admin.placeholderadmin import PlaceholderAdminMixin
+ if rel.model in admin.site._registry and isinstance(admin.site._registry[rel.model], PlaceholderAdminMixin):
field = getattr(self, rel.get_accessor_name())
if field.count():
self._attached_field_cache = rel.field
10 cms/test_utils/project/placeholderapp/admin.py
View
@@ -1,19 +1,19 @@
-from cms.admin.placeholderadmin import PlaceholderAdmin, FrontendEditableAdmin
+from cms.admin.placeholderadmin import PlaceholderAdminMixin, FrontendEditableAdminMixin
from cms.test_utils.project.placeholderapp.models import (Example1, MultilingualExample1, TwoPlaceholderExample)
from django.contrib import admin
from hvad.admin import TranslatableAdmin
-class ExampleAdmin(FrontendEditableAdmin, PlaceholderAdmin):
+class ExampleAdmin(FrontendEditableAdminMixin, PlaceholderAdminMixin, admin.ModelAdmin):
frontend_editable_fields = ("char_1", "char_2")
-class TwoPlaceholderExampleAdmin(PlaceholderAdmin):
+class TwoPlaceholderExampleAdmin(PlaceholderAdminMixin, admin.ModelAdmin):
pass
-class MultilingualAdmin(FrontendEditableAdmin, TranslatableAdmin,
- PlaceholderAdmin):
+class MultilingualAdmin(FrontendEditableAdminMixin, TranslatableAdmin,
+ PlaceholderAdminMixin, admin.ModelAdmin):
frontend_editable_fields = ("char_1", "char_2")
6 cms/test_utils/project/sampleapp/admin.py
View
@@ -1,11 +1,13 @@
-from cms.admin.placeholderadmin import PlaceholderAdmin
+from cms.admin.placeholderadmin import PlaceholderAdminMixin
from django.contrib import admin
from cms.test_utils.project.sampleapp.models import Picture, Category
+
class PictureInline(admin.StackedInline):
model = Picture
-class CategoryAdmin(PlaceholderAdmin):
+
+class CategoryAdmin(PlaceholderAdminMixin, admin.ModelAdmin):
inlines = [PictureInline]
admin.site.register(Category, CategoryAdmin)
4 cms/tests/frontend.py
View
@@ -242,7 +242,9 @@ def test_copy_from_language(self):
hov = ActionChains(self.driver).move_to_element(submenu)
hov.perform()
- copy_from_english = self.driver.find_element_by_css_selector('.cms_submenu-item a[data-rel="copy-lang"][data-language="en"]')
+ submenu_link_selector = '.cms_submenu-item a[data-rel="copy-lang"][data-language="en"]'
+ WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, submenu_link_selector)))
+ copy_from_english = self.driver.find_element_by_css_selector(submenu_link_selector)
copy_from_english.click()
# Done, check if the text plugin was copied and it is only one
13 cms/tests/placeholder.py
View
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import with_statement
+import warnings
from django.core.cache import cache
from django.utils.numberformat import format
from django.db import models
@@ -10,6 +11,7 @@
from cms.models.placeholdermodel import Placeholder
from cms.plugin_pool import plugin_pool
from cms.plugin_rendering import render_placeholder
+from cms.admin.placeholderadmin import PlaceholderAdmin, PlaceholderAdminMixin
from djangocms_link.cms_plugins import LinkPlugin
from cms.utils.compat.tests import UnittestCompatMixin
from djangocms_text_ckeditor.cms_plugins import TextPlugin
@@ -605,6 +607,17 @@ def test_placeholder_languages_page(self):
langs = [lang['code'] for lang in placeholder.get_filled_languages()]
self.assertEqual(avail_langs, set(langs))
+ def test_deprecated_PlaceholderAdmin(self):
+ admin_site = admin.sites.AdminSite()
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter("always")
+ pa = PlaceholderAdmin(Placeholder, admin_site)
+ self.assertEqual(len(w), 1)
+ self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
+ self.assertTrue("PlaceholderAdminMixin with admin.ModelAdmin" in str(w[-1].message))
+ self.assertIsInstance(pa, admin.ModelAdmin, 'PlaceholderAdmin not admin.ModelAdmin')
+ self.assertIsInstance(pa, PlaceholderAdminMixin, 'PlaceholderAdmin not PlaceholderAdminMixin')
+
class PlaceholderActionTests(FakemlngFixtures, CMSTestCase):
def test_placeholder_no_action(self):
12 docs/extending_cms/frontend_models.rst
View
@@ -122,16 +122,16 @@ and the resulting forms.
Complete changeform edit
========================
-You need to properly setup your admin class by adding the
-``FrontendEditableAdmin`` mixin to the parents of your admin class (see
+You need to properly setup your admin class by adding the ``FrontendEditableAdminMixin``
+mixin to the parents of your admin class (see
:mod:`Django admin documentation <django.contrib.admin>` for further information)
on Django admin::
- from cms.admin.placeholderadmin import FrontendEditableAdmin
+ from cms.admin.placeholderadmin import FrontendEditableAdminMixin
from django.contrib import admin
- class MyModelAdmin(FrontendEditableAdmin, admin.ModelAdmin):
+ class MyModelAdmin(FrontendEditableAdminMixin, admin.ModelAdmin):
...
Then setup the templates adding ``render_model`` templatetag::
@@ -156,11 +156,11 @@ Set up the admin
You need to add to your model admin a tuple of fields editable from the frontend
admin::
- from cms.admin.placeholderadmin import FrontendEditableAdmin
+ from cms.admin.placeholderadmin import FrontendEditableAdminMixin
from django.contrib import admin
- class MyModelAdmin(FrontendEditableAdmin, admin.ModelAdmin):
+ class MyModelAdmin(FrontendEditableAdminMixin, admin.ModelAdmin):
frontend_editable_fields = ("foo", "bar")
...
23 docs/extending_cms/placeholders.rst
View
@@ -69,17 +69,19 @@ Admin Integration
.. versionchanged:: 3.0
-If you install this model in the admin application, you have to use
-:class:`~cms.admin.placeholderadmin.PlaceholderAdmin` instead of
-:class:`~django.contrib.admin.ModelAdmin` so the interface renders
+If you install this model in the admin application, you have to use the mixin
+:class:`~cms.admin.placeholderadmin.PlaceholderAdminMixin` together with
+:class:`~django.contrib.admin.ModelAdmin` so that the interface renders
correctly::
from django.contrib import admin
- from cms.admin.placeholderadmin import PlaceholderAdmin
+ from cms.admin.placeholderadmin import PlaceholderAdminMixin
from myapp.models import MyModel
- admin.site.register(MyModel, PlaceholderAdmin)
+ class MyModelAdmin(PlaceholderAdminMixin, admin.ModelAdmin):
+ pass
+ admin.site.register(MyModel, MyModelAdmin)
.. warning::
@@ -92,8 +94,9 @@ correctly::
I18N Placeholders
=================
-Out of the box :class:`~cms.admin.placeholderadmin.PlaceholderAdmin` supports multiple languages and will
-display language tabs. If you extend `PlaceholderAdmin` and overwrite `change_form_template` be sure to have a look at
+Out of the box :class:`~cms.admin.placeholderadmin.PlaceholderAdminMixin` supports multiple
+languages and will display language tabs. If you extend yout model admin class derived from
+`PlaceholderAdminMixin` and overwrite `change_form_template` be sure to have a look at
'admin/placeholders/placeholder/change_form.html' on how to display the language tabs.
If you need other fields then the placeholders translated as well: django CMS has support for `django-hvad`_. If you
@@ -109,15 +112,15 @@ use a `TranslatableModel` model be sure to not include the placeholder fields in
def __unicode__(self):
return self.title
-Be sure to combine both hvad's :class:`TranslatableAdmin` and :class:`~cms.admin.placeholderadmin.PlaceholderAdmin` when
+Be sure to combine both hvad's :class:`TranslatableAdmin` and :class:`~cms.admin.placeholderadmin.PlaceholderAdminMixin` when
registering your model with the admin site::
- from cms.admin.placeholderadmin import PlaceholderAdmin
+ from cms.admin.placeholderadmin import PlaceholderAdminMixin
from django.contrib import admin
from hvad.admin import TranslatableAdmin
from myapp.models import MultilingualExample1
- class MultilingualModelAdmin(TranslatableAdmin, PlaceholderAdmin):
+ class MultilingualModelAdmin(TranslatableAdmin, PlaceholderAdminMixin, admin.ModelAdmin):
pass
admin.site.register(MultilingualExample1, MultilingualModelAdmin)
5 docs/upgrade/3.0.rst
View
@@ -256,6 +256,11 @@ Details can be found in :ref:`multi_apphook`.
``PlaceholderAdmin``
====================
+``PlaceholderAdmin`` now is deprecated. Instead of deriving from ``admin.ModelAdmin``, a new mixin
+class ``PlaceholderAdminMixin`` has been introduced which shall be used together with ``admin.ModelAdmin``.
+Therefore when defining a model admin class containing a placeholder, now add ``PlaceholderAdminMixin``
+to the list of parent classes, together with ``admin.ModelAdmin``.
+
``PlaceholderAdmin`` doesn't have language tabs anymore and the plugin editor is gone.
The plugin API has changed and is now more consistent. ``PageAdmin`` uses the
same API as ``PlaceholderAdmin`` now. If your app talked with the Plugin API
Something went wrong with that request. Please try again.