Пример #1
0
def permission_add(request, second_menu_id):
    """
    添加权限信息
    :param request:
    :param second_menu_id: 已选择的二级菜单ID(用于设置默认值)
    :return:
    """

    if request.method == 'GET':
        form = PermissionModelForm()
        return render(request, 'rbac/update.html', {'form': form})

    if request.method == 'POST':
        form = PermissionModelForm(data=request.POST)
        if form.is_valid():
            second_menu_obj = models.Permission.objects.filter(
                id=second_menu_id).first()
            if not second_menu_obj:
                return HttpResponse('二级菜单不存在,请重新选择!')
            form.instance.pid = second_menu_obj
            form.save()
            return redirect(memory_reverse(request, 'rbac:menu_list'))

        return render(request, 'rbac/update.html',
                      {'form': form})  # 错误信息保存在form中
Пример #2
0
def permission_add(request, second_menu_id):
    """
    三级菜单增加视图功能函数(即添加权限)
    :param request:
    :return:
    """
    # menu_obj = models.Menu.objects.filter(id=menu_id).first()
    if request.method == "GET":
        form = PermissionModelForm()
        return render(request, 'rbac/change.html', {'form': form})

    # 数据校验相关,校验成功则直接保存到数据库
    form = PermissionModelForm(data=request.POST)
    if form.is_valid():
        # 查询传过来的二级菜单是否存在,不存在则返回错误页面
        second_menu_objects = models.Permission.objects.filter(
            pid=second_menu_id).first()
        if not second_menu_objects:
            return render(request, 'rbac/menu_error.html')
        # form.instance 中包含了用户提交的所有值
        form.instance.ppid = second_menu_objects
        form.save()
        url = memory_reverse(request, 'menu_list')
        return redirect(url)
    return render(request, 'rbac/change.html', {'form': form})
Пример #3
0
def permission_edit(request, pk):
    """
    编辑权限
    :param request:
    :param pk:编辑的id
    :return:
    """
    obj = models.Permission.objects.filter(id=pk).first()
    if not obj:
        return HttpResponse('菜单不存在')
    if request.method == 'GET':
        form = PermissionModelForm(instance=obj)  # instance=obj编辑页面带默认值
        return render(request, 'rbac/change.html', {
            'form': form,
            'pk': pk
        })  # memory_reverse自己写的反解析

    # POST
    form = PermissionModelForm(instance=obj, data=request.POST)
    if form.is_valid():
        form.save()
        return redirect(memory_reverse(request, 'rbac:menu_list'))

    # 数据错误展示
    return render(request, 'rbac/change.html', {'form': form, 'pk': pk})
Пример #4
0
def permission_add(request, second_id):
    """
    添加权限
    :param request:
    :param second_id:
    :return:
    """
    if request.method == 'POST':
        form = PermissionModelForm(request.POST)
        if form.is_valid():
            second_menu_obj = models.Permission.objects.filter(
                id=second_id).first()
            if not second_menu_obj:
                return HttpResponse('二级菜单不存在,请重新选择')
            # form.instance中包含用户提交的所有值,相当于写了下面两段代码
            # instance = models.Permission(title='',name='',url='')
            # instance.id = second_menu_obj
            form.instance.pid = second_menu_obj
            form.save()
            url = memory_reverse(request, 'rbac:menu_list')
            return redirect(url)
        else:
            return render(request, 'rbac/change.html', {'form': form})
    form = PermissionModelForm()
    return render(request, 'rbac/change.html', {'form': form})
Пример #5
0
def permission_add(request, second_menu_id):
    '''
    添加权限
    :param request:
    :param second_menu_id:
    :return:
    '''

    if request.method == 'GET':
        form = PermissionModelForm()  #initial= {} 初始化赋值, menu_object, 如 信息管理
        return render(request, 'rbac/change.html', {'form': form})

    form = PermissionModelForm(data=request.POST)
    if form.is_valid():
        second_menu_object = models.Permission.objects.filter(
            id=second_menu_id).first()
        if not second_menu_object:
            return HttpResponse('二级菜单不存在,请重新选择:')

        #form.instance中包含用户提交的所有值, instance
        # instance = models.Permission(title='', name='', url='', pid=second_menu_object)
        # instance.pid = second_menu_object 相当于给instance 增加 pid=second_menu_object
        # instance.save()

        form.instance.pid = second_menu_object
        form.save()
        return redirect(memory_reverse(
            request, 'rbac:menu_list'))  #重定向到带原始参数的URL(通过URL参数反向解析得到带参的URL)

    return render(request, 'rbac/change.html',
                  {'form': form})  #防止表单没有输入直接点保存报错
Пример #6
0
def permission_add(request, second_menu_id):
    """
    添加权限(三级菜单)
    :param request:
    :param second_menu_id:
    :return:
    """
    if request.method == 'GET':
        form = PermissionModelForm()
        return render(request, 'rbac/change.html', {'form': form})
    form = PermissionModelForm(data=request.POST)
    if form.is_valid():
        # 先查看id是否存在
        second_menu_object = models.Permission.objects.filter(
            id=second_menu_id).first()

        if not second_menu_object:
            return HttpResponse('二级菜单不存在!请重试')

        # form.instance 中包含用户提交的所有值,重新把 second_menu_object添加进去
        # 因为用户填表的时候没有填入pid所以手动跟进值
        form.instance.pid = second_menu_object

        form.save()
        return redirect(memory_reverse(
            request, 'rbac:menu_list'))  # memory_reverse自己写的反解析

    # 如果提交空数据
    return render(request, 'rbac/change.html', {'form': form})
Пример #7
0
def permission_add(request, second_menu_id):
	"""
	添加权限
	:param request:
	:param second_menu_id:
	:return:
	"""

	if request.method == 'GET':
		form = PermissionModelForm()
		return render(request, 'rbac/change.html', {'form': form})

	form = PermissionModelForm(data=request.POST)
	if form.is_valid():

		second_menu_object = models.Permission.objects.filter(id=second_menu_id).first()
		if not second_menu_object:
			return HttpResponse('二级菜单不存在,请重新选择')

		# form.instance中包含用户提交的所有值
		form.instance.pid = second_menu_object

		form.save()
		return redirect(memory_reverse(request, 'rbac:menu_list'))

	return render(request, 'rbac/change.html', {'form': form})
Пример #8
0
def permission_add(request, second_menu_id):
    '''
    添加权限
    :param request:
    :param second_menu_id:
    :return:
    '''
    if request.method == 'GET':
        form = PermissionModelForm()
        return render(request, 'rbac/change.html', {'form': form})

    form = PermissionModelForm(data=request.POST)
    if form.is_valid():
        # 先做一次查询
        second_menu_object = models.Permission.objects.filter(
            id=second_menu_id).first()
        if not second_menu_object:
            return HttpResponse("二级菜单不存在, 请重新选择!")
        # form.intance 中包含用户提交的所有值
        # instance = models.Permission(title='', name='', url='', pid=second_menu_object)
        form.instance.pid = second_menu_object
        # form.instance = second_menu_object
        form.save()  # 这一步是保存到数据库中
        return redirect(memory_reverse(request, 'rbac:menu_list'))
    return render(request, 'rbac/change.html', {'form': form})
Пример #9
0
def permission_edit(request, pid):
    """
    修改三级菜单
    :param request:
    :param pid: 选中的三级菜单id
    :return:
    """
    permission_obj = Permission.objects.filter(id=pid).first()
    if request.method == 'GET':
        form = PermissionModelForm(instance=permission_obj)
        return render(request, 'rbac/change.html', {'form': form})
    form = PermissionModelForm(instance=permission_obj, data=request.POST)
    if form.is_valid():
        form.save()
        return redirect(memory_reverse(request, 'rbac:menu-list'))
    return render(request, 'rbac/change.html', {'form': form})
Пример #10
0
def permission_edit(request, second_id):
    obj = models.Permission.objects.filter(pk=second_id)
    url = memory_reverse(request, 'rbac:menu_list')
    if not obj.first():
        response = HttpResponse('角色不存在')
        response.status_code = 404
        return response
    if request.method == 'GET':
        form = PermissionModelForm(instance=obj.first())
        return render(request, 'rbac/change.html', {'form': form})

    form = PermissionModelForm(instance=obj.first(), data=request.POST)
    if form.is_valid():
        form.save()
        return redirect(url)
    return render(request, 'rbac/change.html', {'form': form})
Пример #11
0
def permission_add(request, second_menu_id):

    if request.method == 'GET':
        form = PermissionModelForm()
        return render(request, 'rbac/change.html', {'form': form})
    form = PermissionModelForm(request.POST)

    if form.is_valid():

        second_menu_obj = models.Permission.objects.filter(
            pk=second_menu_id).first()
        if not second_menu_obj:
            return HttpResponse('二级菜单不存在!')
        form.instance.pid = second_menu_obj
        form.save()
        return redirect(urls.memory_reverse(request, 'rbac:menu_list'))
    return render(request, 'rbac/change.html', {'form': form})
Пример #12
0
def permission_edit(request, id):
    """
    编辑权限功能视图函数
    :param request:
    :param id: 要编辑的权限 id
    :return:
    """
    permission_obj = models.Permission.objects.filter(pid=id).first()
    if request.method == "GET":
        form = PermissionModelForm(instance=permission_obj)
        return render(request, 'rbac/change.html', {'form': form})
    form = PermissionModelForm(data=request.POST, instance=permission_obj)
    if form.is_valid():
        form.save()
        url = memory_reverse(request, 'menu_list')
        return redirect(url)
    return render(request, 'rbac/change.html', {'form': form})
Пример #13
0
def permission_edit(request, pk):
    '''
    编辑权限
    :param request:
    :param menu_id:已选择的一级菜单ID(用于设置默认值)
    :return:
    '''
    permission_object = models.Permission.objects.filter(id=pk).first()

    if request.method == 'GET':
        form = PermissionModelForm(instance=permission_object)
        return render(request, 'rbac/change.html', {'form': form})

    form = PermissionModelForm(data=request.POST, instance=permission_object)
    if form.is_valid():
        form.save()
        return redirect(memory_reverse(request, 'rbac:menu_list'))
    return render(request, 'rbac/change.html', {'form': form})
Пример #14
0
def permission_add(request, smid):
    """
    添加三级菜单
    :param request:
    :param smid: 选中的二级菜单id
    :return:
    """
    if request.method == 'GET':
        form = PermissionModelForm()
        return render(request, 'rbac/change.html', {'form': form})
    form = PermissionModelForm(data=request.POST)
    if form.is_valid():
        permission_obj = Permission.objects.filter(id=smid).first()
        if not permission_obj:
            return HttpResponse('二级菜单不存在,请重新选择')
        form.instance.pid = permission_obj
        form.save()
        return redirect(memory_reverse(request, 'rbac:menu-list'))
    return render(request, 'rbac/change.html', {'form': form})
Пример #15
0
def permission_edit(request, pk):
    """
    权限编辑
    :param request:
    :param pk: 要编辑的权限id
    :return:
    """
    permission_obj = models.Permission.objects.filter(id=pk).first()

    if request.method == 'GET':
        forms = PermissionModelForm(instance=permission_obj)
        return render(request, 'rbac/change.html', {'forms': forms})

    forms = PermissionModelForm(data=request.POST, instance=permission_obj)
    if forms.is_valid():
        forms.save()
        url = memory_reverse(request, 'rbac:menu_list')
        return redirect(url)
    return render(request, 'rbac/change.html', {'forms': forms})
Пример #16
0
def permission_edit(request, pk):
    '''
    编辑二级菜单
    :param request:
    :param pk: 当前要编辑的二级菜单
    :return:
    '''

    permission_object = models.Permission.objects.filter(id=pk).first()
    if request.method == 'GET':
        form = PermissionModelForm(instance=permission_object)    # 初始化赋值
        return render(request, 'rbac/change.html', {'form': form})

    form = PermissionModelForm(data=request.POST, instance=permission_object)
    if form.is_valid():
        form.save()
        return redirect(memory_reverse(request, 'rbac:menu_list'))   #重定向到带原始参数的URL(通过URL参数反向解析得到带参的URL)

    return render(request, 'rbac/change.html', {'form': form})   #防止表单没有输入直接点保存报错
Пример #17
0
def permission_edit(request, pk):
    permission_obj = models.Permission.objects.filter(pk=pk).first()

    if not permission_obj:
        return HttpResponse('权限不存在!')

    if request.method == 'GET':
        form = PermissionModelForm(instance=permission_obj)

        return render(request, 'rbac/change.html', {'form': form})

    form = PermissionModelForm(instance=permission_obj, data=request.POST)

    if form.is_valid():
        form.save()

        return redirect(urls.memory_reverse(request, 'rbac:menu_list'))

    return render(request, 'rbac/change.html', {'form': form})
Пример #18
0
def permission_edit(request, pk):
    """
    编辑权限
    :param request:
    :param pk: 当前要编辑的权限ID
    :return:
    """

    permission_object = models.Permission.objects.filter(id=pk).first()

    if request.method == 'GET':
        form = PermissionModelForm(instance=permission_object)
        return render(request, 'rbac/user_add.html', {'form': form})

    form = PermissionModelForm(data=request.POST, instance=permission_object)
    if form.is_valid():
        form.save()
        return redirect(memory_reverse(request, 'rbac:menu_list'))
    return render(request, 'rbac/user_add.html', context=locals())
Пример #19
0
def permission_edit(request, pk):
    """
	编辑
	:param request:
	:param pk:
	:return:
	"""
    obj = models.Permission.objects.filter(id=pk).first()
    if not obj:
        return HttpResponse("菜单不存在")

    if request.method == "GET":
        form = PermissionModelForm(instance=obj)
        return render(request, 'rbac/change.html', {"form": form})

    form = PermissionModelForm(instance=obj, data=request.POST)
    if form.is_valid():
        form.save()
        return redirect(memory_reverse_url(request, 'rbac:menu_list'))
    return render(request, 'rbac/change.html', {"form": form})
Пример #20
0
def permission_add(request,second_menu_id):
	"""
	增加权限信息
	:param request:
	:param second_menu_id: 关联的父级菜单ID
	:return:
	"""
	if request.method == "GET":
		form = PermissionModelForm()
		return render(request, 'rbac/change.html', {'form':form})

	form = PermissionModelForm(data=request.POST)
	if form.is_valid():
		second_menu_object = models.Permission.objects.filter(id=second_menu_id).first()
		if not  second_menu_object:
			return HttpResponse("二级菜单不存在,请重新选择!")
		# form.instance 中包含了用户提交的所有值
		# 这里相当于是增加了一个pid的值
		form.instance.pid = second_menu_object
		form.save()
		return redirect(memory_reverse_url(request,'rbac:menu_list'))
	return render(request, 'rbac/change.html', {'form': form})