def user_profile(request): """ Almacena el perfil de un usuario @param request: Peticion HTTP @return: El form correspondiente """ if request.method == 'POST': formulario = UserProfileForm(request.POST, instance= User.objects.last().profile) if formulario.is_valid(): formulario.save() return HttpResponseRedirect('/admin_usuarios') else: user= request.user profile = user.profile formulario = UserProfileForm(instance=profile) args = {} args.update(csrf(request)) args['formulario']= formulario return render_to_response('perfil.html', args, context_instance=RequestContext(request))
def register(request): registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = UserProfileForm(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 = UserProfileForm() return render(request, 'register.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered})
def user_data(request): current = request.user if UserProfile.objects.filter(user=current).exists(): return HttpResponseRedirect('/') data = '' email = '' else: registered = False if request.method == 'POST': data = UserProfileForm(data=request.POST) email = UserInfoForm(data=request.POST, instance=request.user) if data.is_valid() and email.is_valid(): email.save() details = data.save(commit=False) details.user = request.user details.save() return HttpResponseRedirect('/') else: print data.errors, email.errors else: data = UserProfileForm() email = UserInfoForm() return render(request, 'details.html', {'data': data, 'registered': registered, 'email': email})