예제 #1
0
def groupadd(request):
    style = 'home'
    username = request.user.first_name
    u = request.user
    if request.method == 'POST':
        form = GroupForm(request.POST)
        if form.is_valid():
            if u.has_perm("auth.add_group", "auth.group"):
                form.save()
                return HttpResponse(json.dumps({"code": 1}))
            else:
                auth = u'没有添加用户组权限'
                return HttpResponse(json.dumps({"code": 0, "message": {"auth": auth}}))
        else:
            return HttpResponse(json.dumps({"code": 0, "message": {"name": form['name'].errors,
                                                                   "permissions": form['permissions'].errors}}))
    else:
        form = GroupForm()
        return render(request, "myprofile/groupadd.html", {'form': form, 'index': style, 'username': username})
예제 #2
0
def groupedit(request, id):
    style = 'home'
    username = request.user.first_name
    group = Group.objects.get(id=id)
    u = request.user
    if request.method == 'POST':
        form = GroupForm(request.POST, instance=group)
        if form.is_valid():
            if u.has_perm("auth.change_group", "auth.group"):
                form.save()
                return HttpResponse(json.dumps({"code": 1}))
            else:
                auth = u'没有修改用户组权限'
                return HttpResponse(json.dumps({"code": 0, "message": {"auth": auth}}))
        else:
            return HttpResponse(json.dumps({"code": 0, "message": {"name": form['name'].errors,
                                                                   "permissions": form['permissions'].errors}}))
    else:
        form = GroupForm(instance=group)
        return render(request, "myprofile/groupedit.html", {'form': form, 'index': style, 'username': username})