예제 #1
0
def role_edit(request, pk):
    '''
    编辑角色
    此处重点:role_add, 与role_edit 显示的表单是一样的,唯一不同的是,role_add 页面表单不显示默认值,role_edit页面表单
    显示默认值,因此,两个视频函数,添加role_add, 编辑role_edit 渲染时使用同一个页面文件role_add.html
    :param request:
    :param pk: 要修改的角色id
    :return:
    '''
    obj = models.Role.objects.filter(id=pk).first()
    if not obj:
        return HttpResponse('角色不存在')

    if request.method == 'GET':
        form = RoleModelForm(instance=obj)  #因为有instance=obj ,所以表单中有默认值
        return render(request, 'rbac/change.html',
                      {'form': form
                       })  #访问http://127.0.0.1:8000/rbac/role/edit/1/, 表单中有默认值

    form = RoleModelForm(instance=obj,
                         data=request.POST)  #data=request.POST 表示提交过来的数据
    if form.is_valid():
        form.save()
        return redirect(reverse('rbac:role_list'))

    return render(request, 'rbac/change.html',
                  {'form': form})  #错误信息的展示 防止表单没有输入直接点保存报错
예제 #2
0
def role_add(request):
    if request.method == 'GET':
        form = RoleModelForm()
        return render(request, 'rbac/change.html', {'form': form})
    form = RoleModelForm(request.POST)
    if form.is_valid():
        form.save()
        return redirect(reverse('rbac:role_list'))
    return render(request, 'rbac/change.html', {'form': form})
예제 #3
0
def role_edit(request, rid):
    role_obj = Role.objects.get(pk=rid)
    form = RoleModelForm(instance=role_obj)
    if request.method == 'POST':
        form = RoleModelForm(data=request.POST, instance=role_obj)
        if form.is_valid():
            form.save()
            url = reverse('rbac:role_list')
            return redirect(url)
    return render(request, 'rbac/change.html', {"form": form})
예제 #4
0
def role_add(request):
    form = RoleModelForm()

    if request.method == 'POST':
        form = RoleModelForm(data=request.POST)
        if form.is_valid():
            form.save()
            url = reverse('rbac:role_list')
            return redirect(url)
    return render(request, 'rbac/change.html', {"form": form})
예제 #5
0
def role_add(request):
    """添加角色"""
    if request.method == 'GET':
        form = RoleModelForm()
        return render(request, 'rbac/change.html', {'form': form})
    form = RoleModelForm(data=request.POST)
    if form.is_valid():
        form.save()
        return redirect(reverse('rbac:role_list'))  # 根据
    else:
        # 如果提交空数据
        return render(request, 'rbac/change.html', {'form': form})
예제 #6
0
def role_add(requet):

	if requet.method == "GET":
		form = RoleModelForm()
		return render(requet, 'rbac/role_change.html', {'form':form})

	form = RoleModelForm(data=requet.POST)
	if form.is_valid():
		form.save()
		return redirect(reverse('rbac:role_list'))

	return render(requet, 'rbac/role_change.html', {'form': form}) # 如果输入为空,则在form 中有errors的错误信息
예제 #7
0
def role_edit(request,pk):
    #pk就是要修改的角色id
    obj = models.Role.objects.filter(pk=pk).first()
    if not obj:
        return HttpResponse('角色不存在')
    if request.method == 'GET':
        form = RoleModelForm(instance=obj)#这个instance就是可以传入默认值
        return render(request, 'rbac/role_change.html', {'form':form})
    form = RoleModelForm(instance=obj,data=request.POST)
    if form.is_valid():
        form.save()
        return redirect(reverse('rbac:role_list'))
    return render(request, 'rbac/role_change.html', {'form': form})
예제 #8
0
def role_edit(request, id):
    obj = Role.objects.filter(id=id).first()
    if not obj:
        return HttpResponse('不存在该用户')

    if request.method == 'GET':
        form = RoleModelForm(instance=obj)
        return render(request, 'rbac/change.html', {'form': form})
    form = RoleModelForm(instance=obj, data=request.POST)
    if form.is_valid():
        form.save()
        return redirect(reverse('rbac:role_list'))
    return render(request, 'rbac/change.html', {'form': form})
예제 #9
0
def role_add(request):
    """
    添加角色
    :param request:
    :return:
    """
    if request.method == 'GET':
        form = RoleModelForm()
        return render(request, 'rbac/user_add.html', {'form': form})

    form = RoleModelForm(data=request.POST)
    if form.is_valid():
        form.save()
        return redirect(reverse('rbac:role_list'))
    return render(request, 'rbac/user_add.html', {'form': form})
예제 #10
0
def role_add(request):
    """
    添加角色
    :param request:
    :return:
    """
    if request.method == "GET":
        form = RoleModelForm()
        return render(request, 'rbac/change.html', {'form': form})

    form = RoleModelForm(data=request.POST)
    if form.is_valid():
        form.save()
        return redirect(reverse("rbac:role_list"))  # 反向生成url
    return render(request, 'rbac/change.html', {'form': form})
예제 #11
0
def role_edit(request, pk):
    
    role_obj = models.Role.objects.filter(pk=pk).first()

    if not role_obj:
        return HttpResponse('请先选择角色,再操作!')

    if request.method == 'GET':
        form = RoleModelForm(instance=role_obj)

        return render(request, 'rbac/change.html', {'form': form})
    form = RoleModelForm(instance=role_obj, data=request.POST)
    if form.is_valid():
        form.save()
        return redirect(urls.memory_reverse(request, 'rbac:role_list'))
    return render(request, 'rbac/change.html', {'form': form})
예제 #12
0
def role_edit(request, pk):
    """修改角色"""
    obj = models.Role.objects.filter(id=pk).first()
    if not obj:
        return HttpResponse('角色不存在')
    if request.method == 'GET':
        form = RoleModelForm(instance=obj)  # instance=obj编辑页面带默认值
        return render(request, 'rbac/change.html', {'form': form, 'pk': pk})

    # POST
    form = RoleModelForm(instance=obj, data=request.POST)
    if form.is_valid():
        form.save()
        return redirect(reverse('rbac:role_list'))  # 反向获取

    # 数据错误展示
    return render(request, 'rbac/change.html', {'form': form, 'pk': pk})
예제 #13
0
def role_edit(request, id):
    """
    角色编辑功能视图函数
    :param request:
    :param id: 当前编辑角色的 id 号
    :return:
    """
    obj = models.Role.objects.filter(rid=id).first()
    if not obj:
        return render(request, 'rbac/role_error.html')
    if request.method == 'GET':
        form = RoleModelForm(instance=obj)  # instance= 表示给模板传默认值
        return render(request, 'rbac/change.html', {'form': form})
    form = RoleModelForm(instance=obj, data=request.POST)
    if form.is_valid():
        form.save()
        return redirect(reverse("role_list"))
    return render(request, 'rbac/change.html', {'form': form})
예제 #14
0
def role_edit(request, rid):
    """
    编辑角色
    :param request:
    :param rid: 角色id
    :return:
    """
    role_obj = Role.objects.filter(pk=rid).first()
    if not role_obj:
        return HttpResponse('数据不存在')
    if request.method == 'GET':
        form = RoleModelForm(instance=role_obj)
        return render(request, 'rbac/change.html', {'form': form})
    form = RoleModelForm(instance=role_obj, data=request.POST)
    if form.is_valid():
        form.save()
        return redirect(reverse('rbac:role-list'))
    return render(request, 'rbac/change.html', {'form': form})
예제 #15
0
def role_add(request):
    '''
    添加角色
    :param request:
    :return:
    '''
    if request.method == 'GET':
        form = RoleModelForm()
        print('form:', form)
        return render(request, 'rbac/change.html', {'form': form})

    form = RoleModelForm(data=request.POST)
    if form.is_valid():
        form.save()
        return redirect(reverse('rbac:role_list'))  #反向生成

    return render(request, 'rbac/change.html',
                  {'form': form})  #防止表单没有输入直接点保存报错
예제 #16
0
def role_add(request):
    """
    添加角色功能视图函数
    :param request:
    :return:
    """
    if request.method == "GET":
        form = RoleModelForm()
        return render(request, 'rbac/change.html', {'form': form})
    # ModelForm 获取 request.POST 请求中的数据并提交到后台进行校验
    form = RoleModelForm(data=request.POST)
    # is_valid() 为校验成功后保存的所有数据,此处判断 is_valid 中是否有值,有值成功则保存
    if form.is_valid():
        form.save()  # 直接将数据保存到数据库表中
        # reverse 说明: 从urls路由控制器中指定的别名反向生成路径(url)地址
        return redirect(reverse('role_list'))
    # 判断出错则返回错误信息,form 中保存了正确的内容及错误信息内容,所以直接返货 form 即可
    return render(request, 'rbac/change.html', {'form': form})
예제 #17
0
def role_edit(request, pk):
    """
    编辑角色
    :param request:
    :param pk:
    :return:
    """
    obj = models.Role.objects.filter(id=pk).first()
    if not obj:
        return HttpResponse("角色不存在")
    if request.method == "GET":
        form = RoleModelForm(instance=obj)
        return render(request, 'rbac/change.html', {'form': form})
    form = RoleModelForm(instance=obj, data=request.POST)
    if form.is_valid():
        form.save()
        return redirect(reverse('rbac:role_list'))
    return render(request, 'rbac/change.html', {'form': form})
예제 #18
0
def role_edit(request, pk):
    """
    编辑角色
    :param request:
    :param pk: 要修改的角色ID
    :return:
    """
    obj = models.Role.objects.filter(id=pk).first()
    if not obj:
        # 当然这里404可以写一个页面,这里为了简单起见,所以直接返回
        return HttpResponse('角色不存在')
    if request.method == 'GET':
        form = RoleModelForm(instance=obj)
        return render(request, 'rbac/change.html', {'form': form})

    form = RoleModelForm(instance=obj, data=request.POST)
    if form.is_valid():
        form.save()
        return redirect(reverse('rbac:role_list'))

    return render(request, 'rbac/change.html', {'form': form})
예제 #19
0
파일: role.py 프로젝트: WuAlin0327/Rbac
def role_edit(request, num):
    """
    更改角色
    :param request:
    :param num:
    :return:
    """
    obj = models.Role.objects.filter(pk=num)
    if not obj.first():
        response = HttpResponse('角色不存在')
        response.status_code = 404
        return response
    if request.method == 'GET':
        form = RoleModelForm(instance=obj.first())
        return render(request, 'rbac/change.html', {'form': form})

    form = RoleModelForm(instance=obj.first(), data=request.POST)
    if form.is_valid():
        form.save()
        return redirect(reverse('rbac:role_list'))
    return render(request, 'rbac/change.html', {'form': form})
예제 #20
0
def role_edit(request, pk):
    """
    修改角色
    :param request:
    :param pk:要修改的角色id
    :return:
    """
    obj = models.Role.objects.filter(id=pk).first()
    if not obj:
        return HttpResponse('角色不存在')

    if request.method == 'GET':
        form = RoleModelForm(instance=obj)   # instance=obj : 使編輯框内帶默認值
        return render(request, 'rbac/update.html', {'form': form})

    if request.method == 'POST':
        form = RoleModelForm(instance=obj, data=request.POST)
        if form.is_valid():
            form.save()
            return redirect(reverse('rbac:role_list'))

        return render(request, 'rbac/update.html', {'form': form})  # 错误信息保存在form中
예제 #21
0
파일: role.py 프로젝트: bodyncp/ZGDX
def role_add(request):
    """
    添加角色
    :param request:
    :return:
    """
    if request.method == 'GET':
        form = RoleModelForm()

        user_name = None
        user_name_dict = request.session.get("show_permission")
        if user_name_dict:
            user_name = user_name_dict.get("user_name")

        return render(
            request, 'rbac/change.html', {
                'form': form,
                "users": user_name,
                "rest_password": request.session.get("rest_password"),
                "user_edit_href": request.session.get("user_edit_href"),
                "queryset_count": request.session.get("queryset_count"),
                "queryset_count_all": request.session.get('queryset_count_all')
            })

    form = RoleModelForm(data=request.POST)
    if form.is_valid():
        form.save()
        return redirect(reverse('rbac:role_list'))

    return render(
        request, 'rbac/change.html', {
            'form': form,
            "users": request.session["show_permission"].get("user_name"),
            "rest_password": request.session.get("rest_password"),
            "user_edit_href": request.session.get("user_edit_href"),
            "queryset_count": request.session.get("queryset_count"),
            "queryset_count_all": request.session.get('queryset_count_all')
        })
예제 #22
0
파일: role.py 프로젝트: bodyncp/ZGDX
def role_edit(request, pk):
    """
    编辑角色
    :param request:
    :param pk: 要修改的角色ID
    :return:
    """
    obj = models.Role.objects.filter(id=pk).first()
    if not obj:
        return HttpResponse('角色不存在')
    if request.method == 'GET':
        form = RoleModelForm(instance=obj)
        return render(
            request, 'rbac/change.html', {
                'form': form,
                "users": request.session["show_permission"].get("user_name"),
                "rest_password": request.session.get("rest_password"),
                "user_edit_href": request.session.get("user_edit_href"),
                "queryset_count": request.session.get("queryset_count"),
                "queryset_count_all": request.session.get('queryset_count_all')
            })

    form = RoleModelForm(instance=obj, data=request.POST)
    if form.is_valid():
        form.save()
        return redirect(reverse('rbac:role_list'))

    return render(
        request, 'rbac/change.html', {
            'form': form,
            "users": request.session["show_permission"].get("user_name"),
            "rest_password": request.session.get("rest_password"),
            "user_edit_href": request.session.get("user_edit_href"),
            "queryset_count": request.session.get("queryset_count"),
            "queryset_count_all": request.session.get('queryset_count_all')
        })