Skip to content
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

Can't copy/move plugins when CMS_TOOLBAR_HIDE = True #6616

Open
bhrutledge opened this Issue Feb 19, 2019 · 1 comment

Comments

Projects
None yet
1 participant
@bhrutledge
Copy link

bhrutledge commented Feb 19, 2019

Summary

I have CMS_TOOLBAR_HIDE = True as part of a workaround for #6608. However, now I'm getting an error modal when attempt to copy or move plugins. I've shared an example video on Dropbox.

I would like to write a failing test for this, but I'm not yet familiar enough with the code to know where to start.

Expected behaviour

With CMS_TOOLBAR_HIDE = True, I should be able to use Structure mode to copy and move plugins in and between placeholders.

Actual behaviour

With CMS_TOOLBAR_HIDE = True, when I attempt to copy or move a plugin in Structure mode, I get an error modal with following:

AttributeError at /en/admin/cms/page/copy-plugins/
Exception Value: 'WSGIRequest' object has no attribute 'toolbar'

I've reproduced this in a demo site, initially using 3.4.5 (as I'm currently using in the project where I discovered this), then upgraded to 3.6.0, using the Django CMS Installer.

$ djangocms --django-version 1.11 --cms-version 3.4 -p . -s mysite
$ pip install -U django-cms djangocms-admin-style

Environment

  • Python version: 2.7.15
  • Django version: 1.11.20
  • django CMS version: 3.4.5, 3.6.0

Traceback

Environment:


Request Method: POST
Request URL: http://localhost:8000/en/admin/cms/page/copy-plugins/?cms_path=%2Fen%2F

Django Version: 1.11.20
Python Version: 2.7.15
Installed Applications:
('djangocms_admin_style',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.admin',
 'django.contrib.sites',
 'django.contrib.sitemaps',
 'django.contrib.staticfiles',
 'django.contrib.messages',
 'cms',
 'menus',
 'sekizai',
 'treebeard',
 'djangocms_text_ckeditor',
 'filer',
 'easy_thumbnails',
 'djangocms_column',
 'djangocms_file',
 'djangocms_link',
 'djangocms_picture',
 'djangocms_style',
 'djangocms_snippet',
 'djangocms_googlemap',
 'djangocms_video',
 'mysite')
Installed Middleware:
('cms.middleware.utils.ApphookReloadMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'cms.middleware.user.CurrentUserMiddleware',
 'cms.middleware.page.CurrentPageMiddleware',
 'cms.middleware.toolbar.ToolbarMiddleware',
 'cms.middleware.language.LanguageCookieMiddleware')



Traceback:

File "/Users/brian/Code/django-cms-test/venv/lib/python2.7/site-packages/django/core/handlers/exception.py" in inner
  41.             response = get_response(request)

File "/Users/brian/Code/django-cms-test/venv/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "/Users/brian/Code/django-cms-test/venv/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/Users/brian/Code/django-cms-test/venv/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  149.                     response = view_func(request, *args, **kwargs)

File "/Users/brian/Code/django-cms-test/venv/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  57.         response = view_func(request, *args, **kwargs)

File "/Users/brian/Code/django-cms-test/venv/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
  224.             return view(request, *args, **kwargs)

File "/Users/brian/Code/django-cms-test/venv/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
  67.             return bound_func(*args, **kwargs)

File "/Users/brian/Code/django-cms-test/venv/lib/python2.7/site-packages/django/views/decorators/http.py" in inner
  40.             return func(request, *args, **kwargs)

File "/Users/brian/Code/django-cms-test/venv/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
  63.                 return func.__get__(self, type(self))(*args2, **kwargs2)

File "/Users/brian/Code/django-cms-test/venv/lib/python2.7/site-packages/django/views/decorators/clickjacking.py" in wrapped_view
  39.         resp = view_func(*args, **kwargs)

File "/Users/brian/Code/django-cms-test/venv/lib/python2.7/site-packages/django/utils/decorators.py" in inner
  185.                     return func(*args, **kwargs)

File "/Users/brian/Code/django-cms-test/venv/lib/python2.7/site-packages/cms/admin/placeholderadmin.py" in copy_plugins
  385.         copy_to_clipboard = target_placeholder.pk == request.toolbar.clipboard.pk

Exception Type: AttributeError at /en/admin/cms/page/copy-plugins/
Exception Value: 'WSGIRequest' object has no attribute 'toolbar'
@bhrutledge

This comment has been minimized.

Copy link
Author

bhrutledge commented Feb 19, 2019

My workaround, similar to #6608, is to subclass ToolbarMiddleware and ensure that is_cms_request returns True for copy/move requests.

At the moment, that means augmenting this:

return match.url_name in ('pages-root', 'pages-details-by-slug')

with:

or match.func.__module__ == 'cms.admin.placeholderadmin'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.