Ejemplo n.º 1
0
def add_object(request,obj):
    """
                    创建对象

      obj:表示需要创建哪个对象 group 还是user 还是 auth 。...

    """
    if(request.POST):
        form = __generateForm(post=request.POST,obj=obj) #生成obj对应的表单
        if(form.is_valid()):
            form.save()
            logger.info("The called function is "+__name__+" and args are "+obj)
            return redirect("/admin/show_"+obj)
        
        else:
            #由于权限组的权限部分显示  要求比较特殊 所以我们要进行特殊处理
            if(obj=="group"):
                return render(request,"add.html",{"form":form,"obj":obj,"authority":[authorityService.getFormattedAuth(),request.REQUEST.getlist("authority")]})
            else:
                return render(request,"add.html",{"form":form,"obj":obj})
    else:
        form = __generateForm(obj=obj)
        #由于权限组的权限部分显示  要求比较特殊 所以我们要进行特殊处理
        if(obj=="group"):
            return render(request,"add.html",{"form":form,"obj":obj,"authority":[authorityService.getFormattedAuth()]})
   
        else:
            return render(request,"add.html",{"form":form,"obj":obj})
Ejemplo n.º 2
0
def edit_object(request,Id,obj):
    """
        编辑对象

        obj:表示需要编辑哪个对象

    """
    instance_ = adminService.getObjectById(obj, Id) 
    if(request.POST):
        form = __generateForm(post=request.POST,instance_=instance_,obj=obj)#生成相应的表单
       
        if(form.is_valid()):
            form.save()
            logger.info("The called function is "+__name__+" and args are "+obj+" "+Id)
            return redirect("/admin/show_"+obj)
        else: 
            #由于权限组的权限部分显示  要求比较特殊 所以我们要进行特殊处理
            if(obj=="group"):
                return render(request,"edit.html",{"form":form,"obj":obj,"id":Id,"authority":[authorityService.getFormattedAuth(),[ a.id  for a in Group.objects.get(id=Id).authority.all()]]})
            else:
                return render(request,"edit.html",{"form":form,"obj":obj,"id":Id})
        
    else:
        form = __generateForm(instance_=instance_,obj=obj)
        #由于权限组的权限部分显示  要求比较特殊 所以我们要进行特殊处理
        if(obj=="group"):
            return render(request,"edit.html",{"form":form,"obj":obj,"id":Id,"authority":[authorityService.getFormattedAuth(),[ a.id  for a in Group.objects.get(id=Id).authority.all()]]})
        else:
            return render(request,"edit.html",{"form":form,"obj":obj,"id":Id})