本文整理汇总了Python中cms.models.pluginmodel.CMSPlugin.get_last_root_node方法的典型用法代码示例。如果您正苦于以下问题:Python CMSPlugin.get_last_root_node方法的具体用法?Python CMSPlugin.get_last_root_node怎么用?Python CMSPlugin.get_last_root_node使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cms.models.pluginmodel.CMSPlugin
的用法示例。
在下文中一共展示了CMSPlugin.get_last_root_node方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: move_plugin
# 需要导入模块: from cms.models.pluginmodel import CMSPlugin [as 别名]
# 或者: from cms.models.pluginmodel.CMSPlugin import get_last_root_node [as 别名]
def move_plugin(self, request):
"""
POST request with following parameters:
-plugin_id
-placeholder_id
-plugin_language (optional)
-plugin_parent (optional)
-plugin_order (array, optional)
"""
plugin = CMSPlugin.objects.get(pk=int(request.POST['plugin_id']))
placeholder = Placeholder.objects.get(pk=request.POST['placeholder_id'])
parent_id = request.POST.get('plugin_parent', None)
language = request.POST.get('plugin_language', None)
source_placeholder = plugin.placeholder
if not parent_id:
parent_id = None
else:
parent_id = int(parent_id)
if not language and plugin.language:
language = plugin.language
order = request.POST.getlist("plugin_order[]")
if not self.has_move_plugin_permission(request, plugin, placeholder):
return HttpResponseForbidden(force_text(_("You have no permission to move this plugin")))
if not placeholder == source_placeholder:
try:
template = self.get_placeholder_template(request, placeholder)
has_reached_plugin_limit(placeholder, plugin.plugin_type, plugin.language, template=template)
except PluginLimitReached as er:
return HttpResponseBadRequest(er)
if parent_id:
if plugin.parent_id != parent_id:
parent = CMSPlugin.objects.get(pk=parent_id)
if parent.placeholder_id != placeholder.pk:
return HttpResponseBadRequest(force_text('parent must be in the same placeholder'))
if parent.language != language:
return HttpResponseBadRequest(force_text('parent must be in the same language as plugin_language'))
plugin.parent_id = parent.pk
plugin.save()
plugin = plugin.move(parent, pos='last-child')
else:
sibling = CMSPlugin.get_last_root_node()
plugin.parent_id = None
plugin.save()
plugin = plugin.move(sibling, pos='right')
for child in [plugin] + list(plugin.get_descendants()):
child.placeholder = placeholder
child.language = language
child.save()
plugins = reorder_plugins(placeholder, parent_id, language, order)
if not plugins:
return HttpResponseBadRequest('order parameter did not have all plugins of the same level in it')
self.post_move_plugin(request, source_placeholder, placeholder, plugin)
json_response = {'reload': requires_reload(PLUGIN_MOVE_ACTION, [plugin])}
return HttpResponse(json.dumps(json_response), content_type='application/json')
示例2: move_plugin
# 需要导入模块: from cms.models.pluginmodel import CMSPlugin [as 别名]
# 或者: from cms.models.pluginmodel.CMSPlugin import get_last_root_node [as 别名]
#.........这里部分代码省略.........
if parent_id:
parent = CMSPlugin.objects.get(pk=parent_id)
for plugin in top_plugins:
plugin.parent = parent
plugin.placeholder = placeholder
plugin.language = language
plugin.save()
# If an ordering was supplied, we should replace the item that has
# been copied with the new copy
if order:
if '__COPY__' in order:
copy_idx = order.index('__COPY__')
del order[copy_idx]
order[copy_idx:0] = top_plugins_pks
else:
order.extend(top_plugins_pks)
# Set the plugin variable to point to the newly created plugin.
plugin = new_plugins[0][0]
else:
# Regular move
if parent_id:
if plugin.parent_id != parent_id:
parent = CMSPlugin.objects.get(pk=parent_id)
if parent.placeholder_id != placeholder.pk:
return HttpResponseBadRequest(force_text(
_('parent must be in the same placeholder')))
if parent.language != language:
return HttpResponseBadRequest(force_text(
_('parent must be in the same language as '
'plugin_language')))
plugin.parent_id = parent.pk
plugin.language = language
plugin.save()
plugin = plugin.move(parent, pos='last-child')
else:
sibling = CMSPlugin.get_last_root_node()
plugin.parent = plugin.parent_id = None
plugin.placeholder = placeholder
plugin.save()
plugin = plugin.move(sibling, pos='right')
plugins = [plugin] + list(plugin.get_descendants())
# Don't neglect the children
for child in plugins:
child.placeholder = placeholder
child.language = language
child.save()
reorder_plugins(placeholder, parent_id, language, order)
# When this is executed we are in the admin class of the source placeholder
# It can be a page or a model with a placeholder field.
# Because of this we need to get the admin class instance of the
# target placeholder and call post_move_plugin() on it.
# By doing this we make sure that both the source and target are
# informed of the operation.
target_placeholder_admin = self._get_attached_admin(placeholder)
if move_a_copy: # "paste"
self.post_copy_plugins(request, source_placeholder, placeholder, plugins)
if (target_placeholder_admin and
target_placeholder_admin.model != self.model):
target_placeholder_admin.post_copy_plugins(
request,
source_placeholder=source_placeholder,
target_placeholder=placeholder,
plugins=plugins,
)
else:
self.post_move_plugin(request, source_placeholder, placeholder, plugin)
if (target_placeholder_admin and
target_placeholder_admin.model != self.model):
target_placeholder_admin.post_move_plugin(
request,
source_placeholder=source_placeholder,
target_placeholder=placeholder,
plugin=plugin,
)
try:
language = request.toolbar.toolbar_language
except AttributeError:
language = get_language_from_request(request)
with force_language(language):
plugin_urls = plugin.get_action_urls()
json_response = {
'urls': plugin_urls,
'reload': move_a_copy or requires_reload(
PLUGIN_MOVE_ACTION, [plugin])
}
return HttpResponse(
json.dumps(json_response), content_type='application/json')