def editar_usuario(request, pk, template_name='usuarios/listar_usuarios.html'): u = get_object_or_404(User, pk=pk) form = UserForm(request.POST or None, instance=u) if request.method == 'POST': form.save() return redirect('listar_usuarios') return render(request, template_name, {'u': u})
def editar_perfil(request): if request.method == 'POST': user_form = UserForm(request.POST, instance=request.user) if user_form.is_valid(): user_form.save() return HttpResponseRedirect('/privado') else: user_form = UserForm(instance=request.user) return render_to_response('editar_perfil.html', { 'user_form': user_form }, context_instance=RequestContext(request))
def editar_perfil(request): if request.method == 'POST': user_form = UserForm(request.POST, instance=request.user) if user_form.is_valid(): user_form.save() return HttpResponseRedirect('/privado') else: user_form = UserForm(instance=request.user) return render_to_response('editar_perfil.html', {'user_form': user_form}, context_instance=RequestContext(request))
def registro(request): registered = False if request.method == "POST": user_form = UserForm(data=request.POST) profile_form = InfoExtraUsuarioForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user profile.save() registered = True else: print(user_form.errors, profile_form.errors) else: user_form = UserForm() profile_form = InfoExtraUsuarioForm() return render( request, 'usuarios/registro.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered })