def add_group(request): if request.user.is_superuser: if request.method == 'POST': form = UserGroupForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('list_groups')) else: form = UserGroupForm(request.POST) else: form = UserGroupForm() context = RequestContext(request) extra_context = {'form': form, 'title': _("Add new group")} return render_to_response('account/edit_group.html', extra_context, context_instance=context) else: return HttpResponseRedirect('/')
def edit_group(request, group): if request.user.is_superuser: group = UserGroup.objects.get(pk=group) if request.method == 'POST': form = UserGroupForm(request.POST, instance=group) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('list_groups')) else: form = UserGroupForm(request.POST) else: form = UserGroupForm(instance=group) context = RequestContext(request) extra_context = {'form': form, 'title': _("Update group")} return render_to_response('account/edit_group.html', extra_context, context_instance=context) else: return HttpResponseRedirect('/')