当前位置: 首页>>代码示例>>Python>>正文


Python utils.get_deleted_objects方法代码示例

本文整理汇总了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) 
开发者ID:stormsha,项目名称:StormOnline,代码行数:18,代码来源:delete.py

示例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) 
开发者ID:Superbsco,项目名称:weibo-analysis-system,代码行数:22,代码来源:delete.py

示例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) 
开发者ID:Liweimin0512,项目名称:ImitationTmall_Django,代码行数:18,代码来源:delete.py

示例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) 
开发者ID:LexPredict,项目名称:lexpredict-contraxsuite,代码行数:16,代码来源:admin.py

示例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) 
开发者ID:stormsha,项目名称:StormOnline,代码行数:49,代码来源:actions.py

示例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) 
开发者ID:Wenvki,项目名称:django-idcops,代码行数:58,代码来源:actions.py

示例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) 
开发者ID:Superbsco,项目名称:weibo-analysis-system,代码行数:54,代码来源:actions.py

示例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) 
开发者ID:Liweimin0512,项目名称:ImitationTmall_Django,代码行数:49,代码来源:actions.py


注:本文中的django.contrib.admin.utils.get_deleted_objects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。