Example #1
0
def edit(request, user_id):
    if not checkPrivilege(user_id, request):
        return HttpResponse("not yourself")
    else:
        user = get_object_or_404(User, pk=user_id)
        try:
            userMoreInfo = UserMoreInfo.objects.get(pk=user)
        except UserMoreInfo.DoesNotExist:
            userMoreInfo = UserMoreInfo(user_id=user)
            userMoreInfo.save()
        if request.method == "POST":
            form = UserForm(request.POST, instance=user)
            print form.is_valid()
            print form.toString()
            if form.is_valid():
                user = form.save()
                return HttpResponseRedirect(reverse("my", args=()))
            else:
                return HttpResponseRedirect(reverse("reg", args=()))
        else:
            form = UserForm(instance=user)
            if userMoreInfo:
                userMoreInfoForm = UserMoreInfoForm(instance=userMoreInfo)
            else:
                userMoreInfoForm = UserMoreInfoForm()
            c = RequestContext(request, {"form": form, "user_id": user_id, "moreform": userMoreInfoForm})

            return render_to_response("edit.html", c)
Example #2
0
def addInfo(request, user_id):
    if not checkPrivilege(user_id, request):
        return HttpResponse("not yourself")
    else:
        if request.method == "POST":
            form = UserForm(request.POST)
            if form.is_valid():
                user = form.save()
                return HttpResponseRedirect(reverse("my", args=()))
            else:
                return HttpResponseRedirect("/")
        else:
            form = UserForm()
            c = RequestContext(request, {"form": form})
    return render_to_response("addinfo.html", c)