コード例 #1
0
def user_add(request):
    if request.method == 'GET':
        form = UserModelForm()
        return render(request, 'rbac/change.html', {'form': form})
    form = UserModelForm(request.POST)
    if form.is_valid():
        form.save()
        return redirect(reverse('rbac:user_list'))
    return render(request, 'rbac/change.html', {'form': form})
コード例 #2
0
def user_add(request):
    if request.method == "GET":
        form = UserModelForm()
        return render(request, 'rbac/change.html', {'form': form})

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

    return render(request, 'rbac/change.html',
                  {'form': form})  # 如果输入为空,则在form 中有errors的错误信息
コード例 #3
0
def user_add(request):
    """
    添加用户
    :param request:
    :return:
    """
    if request.method == 'GET':
        form = UserModelForm()
        return render(request, 'rbac/change.html', {'form': form})
    form = UserModelForm(data=request.POST)
    if form.is_valid():
        form.save()
        return redirect(reverse('rbac:user-list'))
    return render(request, 'rbac/change.html', {'form': form})
コード例 #4
0
def user_add(request):
    """添加用户"""
    if request.method == 'GET':
        form = UserModelForm()
        return render(request, 'rbac/user_add.html', context=locals())

    form = UserModelForm(data=request.POST)
    if form.is_valid():
        name = request.POST.get('name', '')
        if models.UserInfo.objects.filter(name=name):
            meg = '%s 用户已经注册' % name
            return render(request, 'rbac/user_add.html', context=locals())
        form.save()
        return redirect(reverse('rbac:user_list'))
    return render(request, 'rbac/user_add.html', context=locals())
コード例 #5
0
def user_add(request):
    '''
    添加用户
    :param request:
    :return:
    '''
    if request.method == 'GET':
        form = UserModelForm()
        print('form:', form)
        return render(request, 'rbac/change.html', {'form': form})

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

    return render(request, 'rbac/change.html', {'form': form})   #防止表单没有输入直接点保存报错
コード例 #6
0
ファイル: user.py プロジェクト: hobe6699/Chunju
def user_add(request):
    """
    添加角色
    :param request:
    :return:
    """
    origin_url = reverse("rbac:rbac_user_list")  # 定义需要返回的地址 前端可以通过此地址跳转
    if request.method == 'GET':  # 请求到页面,生成字段
        form = UserModelForm()
        return render(request, 'rbac/user_change.html/', {
            'form': form,
            "cancel": origin_url
        })
    form = UserModelForm(data=request.POST)  # 当是POST请求是,表示在增加数据
    if form.is_valid():  # 对数据进行验证
        form.save()
        return redirect(origin_url)  # 完成后,跳回到列表页面
    return render(request, 'rbac/user_change.html/', {
        'form': form,
        "cancel": origin_url
    })  # 否则返回错误信息
コード例 #7
0
def user_add(request):
    """
    添加用户功能视图函数
    :param request:
    :return:
    """
    if request.method == "GET":
        form = UserModelForm()
        return render(request, 'rbac/change.html', {'form':form})
    # ModelForm 获取 request.POST 请求中的数据并提交到后台进行校验
    form = UserModelForm(data=request.POST)
    # is_valid() 为校验成功后保存的所有数据,此处判断 is_valid 中是否有值,有值成功则保存
    if form .is_valid():
        form.save()  # 直接将数据保存到数据库表中
        # reverse 说明: 从urls路由控制器中指定的别名反向生成路径(url)地址
        return redirect(reverse('user_list'))
    # 判断出错则返回错误信息,form 中保存了正确的内容及错误信息内容,所以直接返货 form 即可
    return render(request, 'rbac/change.html', {'form': form})
コード例 #8
0
ファイル: user.py プロジェクト: bodyncp/ZGDX
def user_add(request):
    """
    添加角色
    :param request:
    :return:
    """
    if request.method == 'GET':
        form = UserModelForm()
        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 = UserModelForm(data=request.POST)
    if form.is_valid():
        form.save()
        return redirect(reverse('rbac:user_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')
        })