本文整理汇总了Python中cms.plugin_base.CMSPluginBase方法的典型用法代码示例。如果您正苦于以下问题:Python plugin_base.CMSPluginBase方法的具体用法?Python plugin_base.CMSPluginBase怎么用?Python plugin_base.CMSPluginBase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cms.plugin_base
的用法示例。
在下文中一共展示了plugin_base.CMSPluginBase方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_plugin_child_classes_from_settings
# 需要导入模块: from cms import plugin_base [as 别名]
# 或者: from cms.plugin_base import CMSPluginBase [as 别名]
def test_plugin_child_classes_from_settings(self):
page = api.create_page("page", "nav_playground.html", "en", published=True)
placeholder = page.placeholders.get(slot='body')
ChildClassesPlugin = type('ChildClassesPlugin', (CMSPluginBase,),
dict(child_classes=['TextPlugin'], render_template='allow_children_plugin.html'))
plugin_pool.register_plugin(ChildClassesPlugin)
plugin = api.add_plugin(placeholder, ChildClassesPlugin, settings.LANGUAGES[0][0])
plugin = plugin.get_plugin_class_instance()
## assert baseline
self.assertEqual(['TextPlugin'], plugin.get_child_classes(placeholder.slot, page))
CMS_PLACEHOLDER_CONF = {
'body': {
'child_classes': {
'ChildClassesPlugin': ['LinkPlugin', 'PicturePlugin'],
}
}
}
with self.settings(CMS_PLACEHOLDER_CONF=CMS_PLACEHOLDER_CONF):
self.assertEqual(['LinkPlugin', 'PicturePlugin'],
plugin.get_child_classes(placeholder.slot, page))
plugin_pool.unregister_plugin(ChildClassesPlugin)
示例2: test_plugin_parent_classes_from_settings
# 需要导入模块: from cms import plugin_base [as 别名]
# 或者: from cms.plugin_base import CMSPluginBase [as 别名]
def test_plugin_parent_classes_from_settings(self):
page = api.create_page("page", "nav_playground.html", "en", published=True)
placeholder = page.placeholders.get(slot='body')
ParentClassesPlugin = type('ParentClassesPlugin', (CMSPluginBase,),
dict(parent_classes=['TextPlugin'], render_plugin=False))
plugin_pool.register_plugin(ParentClassesPlugin)
plugin = api.add_plugin(placeholder, ParentClassesPlugin, settings.LANGUAGES[0][0])
plugin = plugin.get_plugin_class_instance()
## assert baseline
self.assertEqual(['TextPlugin'], plugin.get_parent_classes(placeholder.slot, page))
CMS_PLACEHOLDER_CONF = {
'body': {
'parent_classes': {
'ParentClassesPlugin': ['TestPlugin'],
}
}
}
with self.settings(CMS_PLACEHOLDER_CONF=CMS_PLACEHOLDER_CONF):
self.assertEqual(['TestPlugin'],
plugin.get_parent_classes(placeholder.slot, page))
plugin_pool.unregister_plugin(ParentClassesPlugin)
示例3: test_plugin_require_parent
# 需要导入模块: from cms import plugin_base [as 别名]
# 或者: from cms.plugin_base import CMSPluginBase [as 别名]
def test_plugin_require_parent(self):
"""
Assert that a plugin marked as 'require_parent' is not listed
in the plugin pool when a placeholder is specified
"""
ParentRequiredPlugin = type('ParentRequiredPlugin', (CMSPluginBase,),
dict(require_parent=True, render_plugin=False))
plugin_pool.register_plugin(ParentRequiredPlugin)
page = api.create_page("page", "nav_playground.html", "en", published=True)
placeholder = page.placeholders.get(slot='body')
plugin_list = plugin_pool.get_all_plugins(placeholder=placeholder, page=page)
self.assertFalse(ParentRequiredPlugin in plugin_list)
plugin_pool.unregister_plugin(ParentRequiredPlugin)
示例4: test_simple_naming
# 需要导入模块: from cms import plugin_base [as 别名]
# 或者: from cms.plugin_base import CMSPluginBase [as 别名]
def test_simple_naming(self):
class MyPlugin(CMSPluginBase):
render_template = 'base.html'
self.assertEqual(MyPlugin.name, 'My Plugin')
示例5: test_simple_context
# 需要导入模块: from cms import plugin_base [as 别名]
# 或者: from cms.plugin_base import CMSPluginBase [as 别名]
def test_simple_context(self):
class MyPlugin(CMSPluginBase):
render_template = 'base.html'
plugin = MyPlugin(ArticlePluginModel, admin.site)
context = {}
out_context = plugin.render(context, 1, 2)
self.assertEqual(out_context['instance'], 1)
self.assertEqual(out_context['placeholder'], 2)
self.assertIs(out_context, context)
示例6: test_verify_plugin_type_invalid_plugin_class
# 需要导入模块: from cms import plugin_base [as 别名]
# 或者: from cms.plugin_base import CMSPluginBase [as 别名]
def test_verify_plugin_type_invalid_plugin_class(self):
class InvalidPlugin(CMSPluginBase):
model = Text
self.assertRaises(AssertionError, _verify_plugin_type, InvalidPlugin)
示例7: _verify_plugin_type
# 需要导入模块: from cms import plugin_base [as 别名]
# 或者: from cms.plugin_base import CMSPluginBase [as 别名]
def _verify_plugin_type(plugin_type):
"""
Verifies the given plugin_type is valid and returns a tuple of
(plugin_model, plugin_type)
"""
if (hasattr(plugin_type, '__module__') and
issubclass(plugin_type, CMSPluginBase)):
plugin_pool.set_plugin_meta()
plugin_model = plugin_type.model
assert plugin_type in plugin_pool.plugins.values()
plugin_type = plugin_type.__name__
elif isinstance(plugin_type, six.string_types):
try:
plugin_model = plugin_pool.get_plugin(plugin_type).model
except KeyError:
raise TypeError(
'plugin_type must be CMSPluginBase subclass or string'
)
else:
raise TypeError('plugin_type must be CMSPluginBase subclass or string')
return plugin_model, plugin_type
#===============================================================================
# Public API
#===============================================================================
示例8: register_plugin
# 需要导入模块: from cms import plugin_base [as 别名]
# 或者: from cms.plugin_base import CMSPluginBase [as 别名]
def register_plugin(self, plugin):
"""
Registers the given plugin(s).
Static sanity checks is also performed.
If a plugin is already registered, this will raise PluginAlreadyRegistered.
"""
if not issubclass(plugin, CMSPluginBase):
raise ImproperlyConfigured(
"CMS Plugins must be subclasses of CMSPluginBase, %r is not."
% plugin
)
plugin_name = plugin.__name__
if plugin_name in self.plugins:
raise PluginAlreadyRegistered(
"Cannot register %r, a plugin with this name (%r) is already "
"registered." % (plugin, plugin_name)
)
plugin.value = plugin_name
self.plugins[plugin_name] = plugin
from cms.signals import pre_save_plugins, post_delete_plugins, pre_delete_plugins
signals.pre_save.connect(pre_save_plugins, sender=plugin.model,
dispatch_uid='cms_pre_save_plugin_%s' % plugin_name)
signals.post_delete.connect(post_delete_plugins, sender=CMSPlugin,
dispatch_uid='cms_post_delete_plugin_%s' % plugin_name)
signals.pre_delete.connect(pre_delete_plugins, sender=CMSPlugin,
dispatch_uid='cms_pre_delete_plugin_%s' % plugin_name)
if is_installed('reversion'):
from cms.utils.reversion_hacks import RegistrationError
try:
reversion_register(plugin.model)
except RegistrationError:
pass
return plugin
示例9: test_plugin_copy_with_reload
# 需要导入模块: from cms import plugin_base [as 别名]
# 或者: from cms.plugin_base import CMSPluginBase [as 别名]
def test_plugin_copy_with_reload(self):
action_options = {
PLUGIN_MOVE_ACTION: {
'requires_reload': True
},
PLUGIN_COPY_ACTION: {
'requires_reload': True
},
}
non_reload_action_options = {
PLUGIN_MOVE_ACTION: {
'requires_reload': False
},
PLUGIN_COPY_ACTION: {
'requires_reload': False
},
}
ReloadDrivenPlugin = type('ReloadDrivenPlugin', (CMSPluginBase,), dict(action_options=action_options, render_plugin=False))
NonReloadDrivenPlugin = type('NonReloadDrivenPlugin', (CMSPluginBase,), dict(action_options=non_reload_action_options, render_plugin=False))
plugin_pool.register_plugin(ReloadDrivenPlugin)
plugin_pool.register_plugin(NonReloadDrivenPlugin)
page = api.create_page("page", "nav_playground.html", "en", published=True)
source_placeholder = page.placeholders.get(slot='body')
target_placeholder = page.placeholders.get(slot='right-column')
api.add_plugin(source_placeholder, ReloadDrivenPlugin, settings.LANGUAGES[0][0])
plugin_2 = api.add_plugin(source_placeholder, NonReloadDrivenPlugin, settings.LANGUAGES[0][0])
# Test Plugin reload == True on Copy
copy_data = {
'source_placeholder_id': source_placeholder.pk,
'target_placeholder_id': target_placeholder.pk,
'target_language': settings.LANGUAGES[0][0],
'source_language': settings.LANGUAGES[0][0],
}
response = self.client.post(URL_CMS_PAGE + "copy-plugins/", copy_data)
self.assertEqual(response.status_code, 200)
json_response = json.loads(response.content.decode('utf8'))
self.assertEqual(json_response['reload'], True)
# Test Plugin reload == False on Copy
copy_data = {
'source_placeholder_id': source_placeholder.pk,
'source_plugin_id': plugin_2.pk,
'target_placeholder_id': target_placeholder.pk,
'target_language': settings.LANGUAGES[0][0],
'source_language': settings.LANGUAGES[0][0],
}
response = self.client.post(URL_CMS_PAGE + "copy-plugins/", copy_data)
self.assertEqual(response.status_code, 200)
json_response = json.loads(response.content.decode('utf8'))
self.assertEqual(json_response['reload'], False)
plugin_pool.unregister_plugin(ReloadDrivenPlugin)
plugin_pool.unregister_plugin(NonReloadDrivenPlugin)
示例10: test_plugin_parent_classes
# 需要导入模块: from cms import plugin_base [as 别名]
# 或者: from cms.plugin_base import CMSPluginBase [as 别名]
def test_plugin_parent_classes(self):
"""
Assert that a plugin with a list of parent classes only appears in the
toolbar plugin struct for those given parent Plugins
"""
ParentClassesPlugin = type('ParentClassesPlugin', (CMSPluginBase,),
dict(parent_classes=['GenericParentPlugin'], render_plugin=False))
GenericParentPlugin = type('GenericParentPlugin', (CMSPluginBase,), {'render_plugin':False})
KidnapperPlugin = type('KidnapperPlugin', (CMSPluginBase,), {'render_plugin':False})
expected_struct = {'module': u'Generic',
'name': u'Parent Classes Plugin',
'value': 'ParentClassesPlugin'}
for plugin in [ParentClassesPlugin, GenericParentPlugin, KidnapperPlugin]:
plugin_pool.register_plugin(plugin)
page = api.create_page("page", "nav_playground.html", "en", published=True)
placeholder = page.placeholders.get(slot='body')
from cms.utils.placeholder import get_toolbar_plugin_struct
toolbar_struct = get_toolbar_plugin_struct([ParentClassesPlugin],
placeholder.slot,
page,
parent=GenericParentPlugin)
self.assertTrue(expected_struct in toolbar_struct)
toolbar_struct = get_toolbar_plugin_struct([ParentClassesPlugin],
placeholder.slot,
page,
parent=KidnapperPlugin)
self.assertFalse(expected_struct in toolbar_struct)
toolbar_struct = get_toolbar_plugin_struct([ParentClassesPlugin, GenericParentPlugin],
placeholder.slot,
page)
expected_struct = {'module': u'Generic',
'name': u'Generic Parent Plugin',
'value': 'GenericParentPlugin'}
self.assertTrue(expected_struct in toolbar_struct)
for plugin in [ParentClassesPlugin, GenericParentPlugin, KidnapperPlugin]:
plugin_pool.unregister_plugin(plugin)