Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* fixed 'cancel' button on edit plugin form (when used in as PluginFi…

…eld in a custom model)

* mind that the fix duplicates code from pluginadmin.py; however, this seems to be the common pattern (most of the edit_plugin method is already duplicated)
  • Loading branch information...
commit a7af082844f95b02164a47eb58b3250c80f4364a 1 parent 6fec447
@kux authored
View
24 cms/admin/placeholderadmin.py
@@ -202,7 +202,29 @@ def edit_plugin(self, request, plugin_id):
post_request = request.POST.copy()
post_request['_continue'] = True
request.POST = post_request
-
+
+ if request.POST.get("_cancel", False):
+ # cancel button was clicked
+ context = {
+ 'CMS_MEDIA_URL': settings.CMS_MEDIA_URL,
+ 'plugin': cms_plugin,
+ 'is_popup': True,
+ 'name': unicode(cms_plugin),
+ "type": cms_plugin.get_plugin_name(),
+ 'plugin_id': plugin_id,
+ 'icon': force_escape(escapejs(cms_plugin.get_instance_icon_src())),
+ 'alt': force_escape(escapejs(cms_plugin.get_instance_icon_alt())),
+ 'cancel': True,
+ }
+ instance = cms_plugin.get_plugin_instance()[0]
+ if not instance:
+ # cancelled before any content was added to plugin
+ cms_plugin.delete()
+ context.update({
+ "deleted":True,
+ })
+ return render_to_response('admin/cms/page/plugin_forms_ok.html', context, RequestContext(request))
+
if not instance:
# instance doesn't exist, call add view
response = plugin_admin.add_view(request)
View
10 cms/test_utils/testcases.py
@@ -219,6 +219,16 @@ def get_request(self, path=None, language=None, post_data=None, enforce_csrf_che
request.user = getattr(self, 'user', AnonymousUser())
request.LANGUAGE_CODE = language
request._dont_enforce_csrf_checks = not enforce_csrf_checks
+
+ class MockStorage(object):
+
+ def add(self, level, message, extra_tags=''):
+ pass
+
+ def update(self, response):
+ pass
+
+ request._messages = MockStorage()
return request
def check_published_page_attributes(self, page):
View
36 cms/tests/placeholder.py
@@ -452,6 +452,42 @@ def test_type_limit(self):
self.assertEqual(response.status_code, 400)
self.assertEqual(response.content, "This placeholder already has the maximum number (1) of TextPlugin plugins.")
+ def test_edit_plugin_and_cancel(self):
+ placeholder = self.get_placeholder()
+ admin = self.get_admin()
+ data = {
+ 'plugin_type': 'TextPlugin',
+ 'placeholder': placeholder.pk,
+ 'language': 'en',
+ }
+ superuser = self.get_superuser()
+ with UserLoginContext(self, superuser):
+ with SettingsOverride(CMS_PLACEHOLDER_CONF=self.placeholderconf):
+ request = self.get_post_request(data)
+ response = admin.add_plugin(request)
+ self.assertEqual(response.status_code, 200)
+ plugin_id = int(response.content)
+ data = {
+ 'body': 'Hello World',
+ }
+ request = self.get_post_request(data)
+ response = admin.edit_plugin(request, plugin_id)
+ self.assertEqual(response.status_code, 200)
+ text_plugin = Text.objects.get(pk=plugin_id)
+ self.assertEquals('Hello World', text_plugin.body)
+
+ # edit again, but this time press cancel
+ data = {
+ 'body': 'Hello World!!',
+ '_cancel': True,
+ }
+ request = self.get_post_request(data)
+ response = admin.edit_plugin(request, plugin_id)
+ self.assertEqual(response.status_code, 200)
+ text_plugin = Text.objects.get(pk=plugin_id)
+ self.assertEquals('Hello World', text_plugin.body)
+
+
class PlaceholderPluginPermissionTests(PlaceholderAdminTest):
Please sign in to comment.
Something went wrong with that request. Please try again.