Skip to content

Commit

Permalink
Fixed #413 -- Don't use model class for plugin url names (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakob-o authored and czpython committed Feb 1, 2017
1 parent 3da2d58 commit 39a8833
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions djangocms_text_ckeditor/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ def pattern(regex, func):
return url_patterns

def get_admin_url_name(self, name):
model_name = self.model._meta.model_name
url_name = "%s_%s_%s" % (self.model._meta.app_label, model_name, name)
plugin_type = self.__class__.__name__.lower()
url_name = "%s_%s_%s" % (self.model._meta.app_label, plugin_type, name)
return url_name

def _get_text_plugin_from_request(self, request, data):
Expand Down
21 changes: 14 additions & 7 deletions djangocms_text_ckeditor/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from cms.api import add_plugin, create_page, create_title
from cms.models import CMSPlugin, Page, Title
from cms.utils.urlutils import admin_reverse
from django.contrib import admin
from django.contrib.auth import get_permission_codename
from django.contrib.auth.models import Permission
Expand All @@ -11,6 +12,7 @@
from django.utils.html import escape
from django.utils.http import urlencode, urlunquote

from djangocms_text_ckeditor.cms_plugins import TextPlugin
from djangocms_text_ckeditor.models import Text
from djangocms_text_ckeditor.utils import (
_plugin_tags_to_html, _render_cms_plugin, plugin_tags_to_admin_html, plugin_tags_to_id_list,
Expand All @@ -22,6 +24,11 @@

class PluginActionsTestCase(BaseTestCase):

def get_custom_admin_url(self, plugin_class, name):
plugin_type = plugin_class.__name__.lower()
url_name = "%s_%s_%s" % (plugin_class.model._meta.app_label, plugin_type, name)
return admin_reverse(url_name)

def _add_child_plugin(self, text_plugin, plugin_type='PicturePlugin', data_suffix=None):
name = '{} record'.format(plugin_type)

Expand Down Expand Up @@ -330,7 +337,7 @@ def test_add_and_cancel_plugin_permissions(self):
cms_plugin = CMSPlugin.objects.get(pk=text_plugin_pk)
text_plugin_class = cms_plugin.get_plugin_class_instance()

endpoint = self.get_admin_url(Text, 'delete_on_cancel')
endpoint = self.get_custom_admin_url(TextPlugin, 'delete_on_cancel')

# Assert a standard user (no staff) can't delete ghost plugin
with self.login_user_context(self.get_standard_user()):
Expand Down Expand Up @@ -455,7 +462,7 @@ def test_render_child_plugin_endpoint(self):
with self.login_user_context(self.get_superuser()):
request = self.get_request()
action_token = text_plugin_class.get_action_token(request, text_plugin)
endpoint = self.get_admin_url(Text, 'render_plugin')
endpoint = self.get_custom_admin_url(TextPlugin, 'render_plugin')
endpoint += '?token={}&plugin={}'.format(action_token, child_plugin.pk)
response = self.client.get(endpoint)

Expand All @@ -478,7 +485,7 @@ def test_render_child_plugin_endpoint(self):
with self.login_user_context(self.get_superuser()):
request = self.get_request()
action_token = text_plugin_class.get_action_token(request, text_plugin)
endpoint = self.get_admin_url(Text, 'render_plugin')
endpoint = self.get_custom_admin_url(TextPlugin, 'render_plugin')
endpoint += '?token={}&plugin={}'.format(action_token, child_plugin.pk)
response = self.client.get(endpoint)

Expand Down Expand Up @@ -513,7 +520,7 @@ def test_render_child_plugin_endpoint_calls_context_processors(self):
with self.login_user_context(self.get_superuser()):
request = self.get_request()
action_token = text_plugin_class.get_action_token(request, text_plugin)
endpoint = self.get_admin_url(Text, 'render_plugin')
endpoint = self.get_custom_admin_url(TextPlugin, 'render_plugin')
endpoint += '?token={}&plugin={}'.format(action_token, child_plugin.pk)
response = self.client.get(endpoint)

Expand Down Expand Up @@ -550,7 +557,7 @@ def test_render_child_plugin_permissions(self):
with self.login_user_context(self.get_standard_user()):
request = self.get_request()
action_token = text_plugin_class.get_action_token(request, text_plugin)
endpoint = self.get_admin_url(Text, 'render_plugin')
endpoint = self.get_custom_admin_url(TextPlugin, 'render_plugin')
endpoint += '?token={}&plugin={}'.format(action_token, child_plugin.pk)
response = self.client.get(endpoint)

Expand Down Expand Up @@ -584,7 +591,7 @@ def test_render_child_plugin_token_validation(self):

with self.login_user_context(self.get_superuser()):
action_token = text_plugin_class.get_action_token(request, text_plugin)
endpoint = self.get_admin_url(Text, 'render_plugin')
endpoint = self.get_custom_admin_url(TextPlugin, 'render_plugin')
endpoint += '?token={}&plugin={}'.format(action_token, child_plugin.pk)
response = self.client.get(endpoint)

Expand All @@ -604,7 +611,7 @@ def test_render_child_plugin_token_validation(self):
with self.login_user_context(self.get_superuser()):
request = self.get_request()
action_token = text_plugin_class.get_action_token(request, text_plugin_2)
endpoint = self.get_admin_url(Text, 'render_plugin')
endpoint = self.get_custom_admin_url(TextPlugin, 'render_plugin')
endpoint += '?token={}&plugin={}'.format(action_token, child_plugin.pk)
response = self.client.get(endpoint)

Expand Down

0 comments on commit 39a8833

Please sign in to comment.