本文整理汇总了Python中django.contrib.admin.utils.get_deleted_objects方法的典型用法代码示例。如果您正苦于以下问题:Python utils.get_deleted_objects方法的具体用法?Python utils.get_deleted_objects怎么用?Python utils.get_deleted_objects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.admin.utils
的用法示例。
在下文中一共展示了utils.get_deleted_objects方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_request
# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import get_deleted_objects [as 别名]
def init_request(self, object_id, *args, **kwargs):
"The 'delete' admin view for this model."
self.obj = self.get_object(unquote(object_id))
if not self.has_delete_permission(self.obj):
raise PermissionDenied
if self.obj is None:
raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_text(self.opts.verbose_name), 'key': escape(object_id)})
using = router.db_for_write(self.model)
# Populate deleted_objects, a data structure of all related objects that
# will also be deleted.
(self.deleted_objects, model_count, self.perms_needed, self.protected) = get_deleted_objects(
[self.obj], self.opts, self.request.user, self.admin_site, using)
示例2: init_request
# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import get_deleted_objects [as 别名]
def init_request(self, object_id, *args, **kwargs):
"The 'delete' admin view for this model."
self.obj = self.get_object(unquote(object_id))
if not self.has_delete_permission(self.obj):
raise PermissionDenied
if self.obj is None:
raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_text(self.opts.verbose_name), 'key': escape(object_id)})
using = router.db_for_write(self.model)
# Populate deleted_objects, a data structure of all related objects that
# will also be deleted.
if django_version > (2, 1):
(self.deleted_objects, model_count, self.perms_needed, self.protected) = get_deleted_objects(
[self.obj], self.opts, self.admin_site)
else:
(self.deleted_objects, model_count, self.perms_needed, self.protected) = get_deleted_objects(
[self.obj], self.opts, self.request.user, self.admin_site, using)
示例3: init_request
# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import get_deleted_objects [as 别名]
def init_request(self, object_id, *args, **kwargs):
"The 'delete' admin view for this model."
self.obj = self.get_object(unquote(object_id))
if not self.has_delete_permission(self.obj):
raise PermissionDenied
if self.obj is None:
raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_unicode(self.opts.verbose_name), 'key': escape(object_id)})
using = router.db_for_write(self.model)
# Populate deleted_objects, a data structure of all related objects that
# will also be deleted.
(self.deleted_objects, model_count, self.perms_needed, self.protected) = get_deleted_objects(
[self.obj], self.opts, self.request.user, self.admin_site, using)
示例4: delete_selected_action
# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import get_deleted_objects [as 别名]
def delete_selected_action(self, model_admin, request, qs):
objects = UsersTasksValidationAdmin.QSList(qs)
if request.POST.get('post'):
deletable_objects, model_count, perms_needed, protected = get_deleted_objects(
objects, request, model_admin.admin_site)
if not protected:
res = delete_selected(model_admin, request, objects)
for obj in objects:
self.on_object_deleted(obj)
return res
response = delete_selected(model_admin, request, objects)
context = response.context_data
context['running_tasks'] = self.get_user_task_names() or None
return TemplateResponse(request, model_admin.delete_selected_confirmation_template, context)
示例5: do_action
# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import get_deleted_objects [as 别名]
def do_action(self, queryset):
# Check that the user has delete permission for the actual model
if not self.has_delete_permission():
raise PermissionDenied
using = router.db_for_write(self.model)
# Populate deletable_objects, a data structure of all related objects that
# will also be deleted.
deletable_objects, model_count, perms_needed, protected = get_deleted_objects(
queryset, self.opts, self.user, self.admin_site, using)
# The user has already confirmed the deletion.
# Do the deletion and return a None to display the change list view again.
if self.request.POST.get('post'):
if perms_needed:
raise PermissionDenied
self.delete_models(queryset)
# Return None to display the change list page again.
return None
if len(queryset) == 1:
objects_name = force_text(self.opts.verbose_name)
else:
objects_name = force_text(self.opts.verbose_name_plural)
if perms_needed or protected:
title = _("Cannot delete %(name)s") % {"name": objects_name}
else:
title = _("Are you sure?")
context = self.get_context()
context.update({
"title": title,
"objects_name": objects_name,
"deletable_objects": [deletable_objects],
'queryset': queryset,
"perms_lacking": perms_needed,
"protected": protected,
"opts": self.opts,
"app_label": self.app_label,
'action_checkbox_name': ACTION_CHECKBOX_NAME,
})
# Display the confirmation page
return TemplateResponse(self.request, self.delete_selected_confirmation_template or
self.get_template_list('views/model_delete_selected_confirm.html'), context)
示例6: delete
# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import get_deleted_objects [as 别名]
def delete(request, queryset):
model = queryset.model
opts = model._meta
action = sys._getframe().f_code.co_name
action_name = "删除"
modeladmin = admin.site._registry.get(model)
# queryset = queryset.filter(actived=False)
if not modeladmin.has_delete_permission(request):
raise PermissionDenied
using = router.db_for_write(modeladmin.model)
deletable_objects, model_count, perms_needed, protected = get_deleted_objects(
queryset, request, modeladmin.admin_site)
if request.POST.get('post') and not protected:
if perms_needed:
raise PermissionDenied
if queryset.count():
for obj in queryset:
log_action(
user_id=request.user.pk,
content_type_id=get_content_type_for_model(obj, True).pk,
object_id=obj.pk,
action_flag="删除"
)
if not SOFT_DELELE:
queryset.delete()
else:
queryset.update(deleted=True, actived=False)
return None
if len(queryset) == 1:
objects_name = force_text(opts.verbose_name)
else:
objects_name = force_text(opts.verbose_name_plural)
meta, menus = construct_model_meta(request, model, action_name)
context = dict(
objects_name=objects_name,
deletable_objects=[deletable_objects],
model_count=dict(model_count).items(),
queryset=queryset,
perms_lacking=perms_needed,
protected=protected,
opts=opts,
meta=meta,
action=action,
action_name=action_name,
menus=menus,
)
request.current_app = modeladmin.admin_site.name
return TemplateResponse(request, 'base/base_confirmation.html', context)
示例7: do_action
# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import get_deleted_objects [as 别名]
def do_action(self, queryset):
# Check that the user has delete permission for the actual model
if not self.has_delete_permission():
raise PermissionDenied
# Populate deletable_objects, a data structure of all related objects that
# will also be deleted.
if django_version > (2, 1):
deletable_objects, model_count, perms_needed, protected = get_deleted_objects(
queryset, self.opts, self.admin_site)
else:
using = router.db_for_write(self.model)
deletable_objects, model_count, perms_needed, protected = get_deleted_objects(
queryset, self.opts, self.user, self.admin_site, using)
# The user has already confirmed the deletion.
# Do the deletion and return a None to display the change list view again.
if self.request.POST.get('post'):
if perms_needed:
raise PermissionDenied
self.delete_models(queryset)
# Return None to display the change list page again.
return None
if len(queryset) == 1:
objects_name = force_text(self.opts.verbose_name)
else:
objects_name = force_text(self.opts.verbose_name_plural)
if perms_needed or protected:
title = _("Cannot delete %(name)s") % {"name": objects_name}
else:
title = _("Are you sure?")
context = self.get_context()
context.update({
"title": title,
"objects_name": objects_name,
"deletable_objects": [deletable_objects],
'queryset': queryset,
"perms_lacking": perms_needed,
"protected": protected,
"opts": self.opts,
"app_label": self.app_label,
'action_checkbox_name': ACTION_CHECKBOX_NAME,
})
# Display the confirmation page
return TemplateResponse(self.request, self.delete_selected_confirmation_template or
self.get_template_list('views/model_delete_selected_confirm.html'), context)
示例8: do_action
# 需要导入模块: from django.contrib.admin import utils [as 别名]
# 或者: from django.contrib.admin.utils import get_deleted_objects [as 别名]
def do_action(self, queryset):
# Check that the user has delete permission for the actual model
if not self.has_delete_permission():
raise PermissionDenied
using = router.db_for_write(self.model)
# Populate deletable_objects, a data structure of all related objects that
# will also be deleted.
deletable_objects, model_count, perms_needed, protected = get_deleted_objects(
queryset, self.opts, self.user, self.admin_site, using)
# The user has already confirmed the deletion.
# Do the deletion and return a None to display the change list view again.
if self.request.POST.get('post'):
if perms_needed:
raise PermissionDenied
self.delete_models(queryset)
# Return None to display the change list page again.
return None
if len(queryset) == 1:
objects_name = force_unicode(self.opts.verbose_name)
else:
objects_name = force_unicode(self.opts.verbose_name_plural)
if perms_needed or protected:
title = _("Cannot delete %(name)s") % {"name": objects_name}
else:
title = _("Are you sure?")
context = self.get_context()
context.update({
"title": title,
"objects_name": objects_name,
"deletable_objects": [deletable_objects],
'queryset': queryset,
"perms_lacking": perms_needed,
"protected": protected,
"opts": self.opts,
"app_label": self.app_label,
'action_checkbox_name': ACTION_CHECKBOX_NAME,
})
# Display the confirmation page
return TemplateResponse(self.request, self.delete_selected_confirmation_template or
self.get_template_list('views/model_delete_selected_confirm.html'), context)