Esempio n. 1
0
    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, 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,
            current_app=self.admin_site.name,
        )
Esempio n. 2
0
    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_str(self.opts.verbose_name)
        else:
            objects_name = force_str(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],
            "model_count": dict(model_count).items(),
            '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,
            current_app=self.admin_site.name)
Esempio n. 3
0
    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, self.perms_needed, self.protected) = get_deleted_objects(
            [self.obj], self.opts, self.request.user, self.admin_site, using)
Esempio n. 4
0
    def init_request(self, object_id, *args, **kwargs):
        """
        初始化操作。根据传入的 ``object_id`` 取得要被删除的数据对象,而后进行权限判断
        """
        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)    # 取得所用db
        # 生成 deleted_objects, 存有所有即将被删除的关联数据
        (self.deleted_objects, self.perms_needed, self.protected) = get_deleted_objects(
            [self.obj], self.opts, self.request.user, self.admin_site, using)
Esempio n. 5
0
    def init_request(self, object_id, *args, **kwargs):
        """
        初始化操作。根据传入的 ``object_id`` 取得要被删除的数据对象,而后进行权限判断
        """
        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)  # 取得所用db
        # 生成 deleted_objects, 存有所有即将被删除的关联数据
        (self.deleted_objects, self.perms_needed,
         self.protected) = get_deleted_objects([self.obj], self.opts,
                                               self.request.user,
                                               self.admin_site, using)
Esempio n. 6
0
    def do_action(self, queryset):
        #modify by xxd, set technology cannot be delete
        from django.contrib.contenttypes.models import ContentType
        for q_obj in queryset:
            technology = None
            if ContentType.objects.get_for_model(q_obj).model == 'technology':
                technology = q_obj
            if ContentType.objects.get_for_model(q_obj).model == 'operationgroup':
                technology = q_obj.technology
            if ContentType.objects.get_for_model(q_obj).model == 'operation':
                technology = q_obj.operation_group.technology
            if ContentType.objects.get_for_model(q_obj).model == 'operationattribute':
                technology = q_obj.operation.operation_group.technology
            if technology:
                queryset = queryset.exclude(id=q_obj.id) if technology.technology_workflow_status in [1,2] else queryset

            manufactureplan = None
            if ContentType.objects.get_for_model(q_obj).model == 'manufactureplan':
                manufactureplan = q_obj
            if ContentType.objects.get_for_model(q_obj).model == 'manufactureitemgroup':
                manufactureplan = q_obj.manufactureplan
            if manufactureplan:
                queryset = queryset.exclude(id=q_obj.id) if manufactureplan.manufactureplan_workflow_status in [1,2] else 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, 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, current_app=self.admin_site.name)
Esempio n. 7
0
    def do_action(self, queryset):
        #modify by xxd, set technology cannot be delete
        from django.contrib.contenttypes.models import ContentType
        for q_obj in queryset:
            technology = None
            if ContentType.objects.get_for_model(q_obj).model == 'technology':
                technology = q_obj
            if ContentType.objects.get_for_model(
                    q_obj).model == 'operationgroup':
                technology = q_obj.technology
            if ContentType.objects.get_for_model(q_obj).model == 'operation':
                technology = q_obj.operation_group.technology
            if ContentType.objects.get_for_model(
                    q_obj).model == 'operationattribute':
                technology = q_obj.operation.operation_group.technology
            if technology:
                queryset = queryset.exclude(
                    id=q_obj.id) if technology.technology_workflow_status in [
                        1, 2
                    ] else queryset

            manufactureplan = None
            if ContentType.objects.get_for_model(
                    q_obj).model == 'manufactureplan':
                manufactureplan = q_obj
            if ContentType.objects.get_for_model(
                    q_obj).model == 'manufactureitemgroup':
                manufactureplan = q_obj.manufactureplan
            if manufactureplan:
                queryset = queryset.exclude(
                    id=q_obj.
                    id) if manufactureplan.manufactureplan_workflow_status in [
                        1, 2
                    ] else 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, 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,
            current_app=self.admin_site.name)