Example #1
0
def user_add(request):
    form = UserChangeForm(data=request.POST.copy() or None)

    if form.is_valid():
        if form.has_changed():
            form.save()
        return redirect('user-list')
    return render(request, 'users/user_add_edit.html', {
        'form': form,
        'created': True
    })
Example #2
0
def profile_edit(request):
    if not request.user.is_authenticated():
        #TODO handle somehow
        raise Exception('Nemůžete změnit své údaje, když nejste přihlášen.')

    if request.method == 'POST':
        #form = UserChangeForm(request.POST, instance=User.objects.get(id=request.user.id))
        form = UserChangeForm(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
            #save user profile
            p = request.user.get_profile()
            p.gender = form.cleaned_data['gender'] == 'True'
            p.save()

            return HttpResponseRedirect(reverse('home'))

    else:
        logging.debug(request.user)
        form = UserChangeForm(instance=request.user)

    return render_to_response('auth/profile_edit.html', {'form': form},
                              context_instance=RequestContext(request))