def get_role(req, id): ctx = Context() role = ctx.get_role(id) if role is None: raise Http404 data = [] data.append("'id': '%s'" % role.id) data.append("'description': '%s'" % role.description) data.append("'permissions': ['%s']" % "','".join([p.id.replace("'", "\\'") for p in role.permissions])) return HttpResponse("{%s}" % ",".join(data), "text/plain")
def get_role(req, id): ctx = Context() role = ctx.get_role(id) if role is None: raise Http404 data = [] data.append("'id': '%s'" % role.id) data.append("'description': '%s'" % role.description) data.append( "'permissions': ['%s']" % "','".join([p.id.replace("'", "\\'") for p in role.permissions])) return HttpResponse("{%s}" % ",".join(data), "text/plain")
def edit_role(req, id): ctx = Context() role = ctx.get_role(id=id) if not role: raise Http404 role.description = req.POST['description'] role.permissions = [] for id in (req.POST['permissions'].strip() and req.POST['permissions'].split(",") or []): role.permissions.append(ctx.get_permission(id)) for i in xrange(len(ctx.roles)): if ctx.roles[i].id == id: ctx.roles[i] = role break ctx.write_xml() return HttpResponse("{'result': 'OK'}")
def edit_user(req, id): ctx = Context() user = ctx.get_user(id=id) if not user: raise Http404 user.name = req.POST['name'] user.roles = [] for id in (req.POST['roles'].strip() and req.POST['roles'].split(",") or []): user.roles.append(ctx.get_role(id)) user.superuser = (req.POST['superuser'] == "yes") if req.POST['password'].strip(): password = req.POST['password'] for i in xrange(len(ctx.users)): if ctx.users[i].login == id: ctx.users[i] = user break ctx.write_xml() return HttpResponse("{'result': 'OK'}")