Ejemplo n.º 1
0
def menu(request, menu_id=None):
    obj = models.Menu.objects.filter(pk=menu_id).first()
    form_obj = MenuForm(instance=obj)
    if request.method == 'POST':
        form_obj = MenuForm(request.POST, instance=obj)
        if form_obj.is_valid():
            form_obj.save()
            return redirect(reverse('rbac:menu_list'))
    return render(request, 'rbac/menu_form.html', {'form_obj': form_obj})
Ejemplo n.º 2
0
def menu_add(request, edit_id=None):
    obj = models.Menu.objects.filter(id=edit_id).first()
    form_obj = MenuForm(instance=obj)
    if request.method == "POST":
        form_obj = MenuForm(request.POST, instance=obj)
        if form_obj.is_valid():
            form_obj.save()
            return redirect(reverse('rbac:menu_list'))
    return render(request, 'rbac/menu_add.html', {"form_obj": form_obj})
Ejemplo n.º 3
0
def menu_change(request, pk=None):
    obj = models.Menu.objects.filter(pk=pk).first()
    form_obj = MenuForm(instance=obj)
    if request.method == 'POST':
        form_obj = MenuForm(request.POST, instance=obj)
        if form_obj.is_valid():
            form_obj.save()
            return redirect('menu_list')
    return render(request, 'form.html', {'form_obj': form_obj})
Ejemplo n.º 4
0
 def post(self, request):
     res = dict(result=False)
     if 'id' in request.POST and request.POST['id']:
         menu = get_object_or_404(Menu, pk=request.POST.get('id'))
     else:
         menu = Menu()
     menu_form = MenuForm(request.POST, instance=menu)
     if menu_form.is_valid():
         menu_form.save()
         res['result'] = True
     return HttpResponse(json.dumps(res), content_type='application/json')
Ejemplo n.º 5
0
def edit_meun(request, edit_id=None):
    menu_obj = models.Menu.objects.filter(pk=edit_id).first()
    form_obj = MenuForm(instance=menu_obj)
    if request.method == 'POST':
        print(request.POST)
        form_obj = MenuForm(request.POST, instance=menu_obj)
        print(form_obj)
        if form_obj.is_valid():
            form_obj.save()
            return redirect(reverse('rbac:menu_list'))
        else:
            print('&' * 20)
            print(form_obj)
            return render(request, 'add_menu.html', {'form_obj': form_obj})
    return render(request, 'add_menu.html', {'form_obj': form_obj})
Ejemplo n.º 6
0
def menu_change(request, edit_id=None):
    obj = models.Menu.objects.filter(id=edit_id).first()
    if not edit_id:
        form_obj = MenuForm()
        title = '添加菜单'
    else:
        form_obj = MenuForm(instance=obj)
        title = '编辑菜单'
    if request.method == 'POST':
        form_obj = MenuForm(request.POST, instance=obj)
        if form_obj.is_valid():
            form_obj.save()
            return redirect(reverse('rbac:rbac/menu_list'))

    return render(request, 'rbac/menu_change.html', {
        'form_obj': form_obj,
        'title': title
    })