Esempio n. 1
0
 def post(self,request,*args,**kwargs):
     res = {"code":0}
     pk = kwargs.get('pk')
     p = Product.objects.get(pk=pk)
     form = ProductForm(request.POST,instance=p)
     if form.is_valid():
         form.save()
         res['result'] = "更新业务线成功"
     else:
         res['code'] = 1
         res['errmsg'] = form.errors
     return render(request,settings.JUMP_PAGE,res)
Esempio n. 2
0
    def post(self, request):
        res = {"code": 0, 'next_url': reverse("cmdb:product_detail", args=[1])}
        form = ProductForm(request.POST)
        if form.is_valid():
            try:
                form.save()
                res['result'] = "添加业务线成功"
            except Exception as e:
                msg = "用户{} 业务线出错:{}".format(request.user.username, e.args)
                logger.error(msg)
                res['code'] = 1
                res['errmsg'] = msg

        else:
            msg = "用户{} 添加业务线验证失败:{}".format(request.user.username, form.errors)
            logger.error(msg)
            res['code'] = 1
            res['errmsg'] = msg
        return render(request, settings.JUMP_PAGE, res)
Esempio n. 3
0
    def post(self, request, *args, **kwargs):

        pk = kwargs.get('pk')
        p = self.model.objects.get(pk=pk)
        form = ProductForm(request.POST, instance=p)
        if form.is_valid():
            form.save()
            res = {
                "code": 0,
                "result": "更新产品线成功",
                'next_url': reverse("cmdb:product_detail", args=[1])
            }
        else:
            res = {
                "code": 1,
                "errmsg": form.errors,
                'next_url': reverse("cmdb:product_detail", args=[1])
            }
        return render(request, settings.JUMP_PAGE, res)