def update_profile(request): if request.user.is_authenticated(): if request.method == "POST": user_form = UserForm(request.POST, instance=request.user,) profile_form = UserProfileForm(request.POST, request.FILES, instance=request.user.userprofile) if user_form.is_valid() and profile_form.is_valid(): user_form.save() profile_form.save() else: try: profile = request.user.userprofile except UserProfile.DoesNotExist: profile = UserProfile(user=request.user) profile.save() profile_form = UserProfileForm(instance=request.user.userprofile) user_form = UserForm(instance=request.user) context = {'user_form':user_form, 'profile_form':profile_form, } return render_to_response('userprofiles/edit_profile.html', context, RequestContext(request))
def edit_user_profile(request): if request.method == "POST": form = UserProfileForm(data=request.POST, instance=request.user.profile) else: form = UserProfileForm(instance=request.user.profile) if form.is_valid(): form.save() return render(request, 'accounts/user_profile.html') else: print "This isn't right" return render(request, 'accounts/edit_profile.html', {"form": form})
def confirmcheckout(request, orderid): """ Handle successful checkouts """ save_info = request.session.get('save_info') order = get_object_or_404(Userorders, orderid=orderid) if request.user.is_authenticated: profile = UserProfile.objects.get(user=request.user) # Attach the user's profile to the order order.userprofile = profile order.save() # Save the user's info if save_info: profile_data = { 'userphone': order.phone, 'useraddress1': order.address1, 'useraddress2': order.address2, 'usertown': order.town, 'usercounty': order.county, 'userpostalcode': order.postalcode, 'usercountry': order.country, } user_profile_form = UserProfileForm(profile_data, instance=profile) if user_profile_form.is_valid(): user_profile_form.save() messages.success(request, f'\ Order Successful. \ A confirmation \ email will be sent to {order.emailaddress}.') if 'basket' in request.session: del request.session['basket'] template = 'checkout/confirmcheckout.html' context = { 'order': order, } return render(request, template, context)
def register(request, event_id = None): profile = None registration = None request.session['user_registered'] = None event = get_event(event_id) request.session['event_id'] = event.id if request.session.has_key('login_email'): profile, registration = get_user_profile_registration(event, request.session['login_email']) if profile and registration: request.session['user_registered'] = "True" if registration.completed_exit_survey == "True": request.session['thank_you'] = "thanks" else: request.session['login_email'] = None login_form = LoginForm() logout_form = LogoutForm() register_event_form = RegisterEventForm() user_profile_form = UserProfileForm() if request.method == "POST": login_form = LoginForm(request.POST) logout_form = LogoutForm(request.POST) register_event_form = RegisterEventForm(request.POST) user_profile_form = UserProfileForm(request.POST) if user_profile_form.is_valid(): if not user_profile_exists(user_profile_form.cleaned_data['email']): usr = user_profile_form.save(commit=False) usr.ip_address = request.META['REMOTE_ADDR'] usr.save() login_user(request, user_profile_form.cleaned_data['email']) register_user_for_event(request, event, usr) return HttpResponseRedirect(reverse('event', args=[event_id])) else: # the user already exists # TO DO user_profile_form = UserProfileForm() pass elif login_form.is_valid(): if user_profile_exists(login_form.cleaned_data['email']): login_user(request, login_form.cleaned_data['email']) #if is_first_redirect(request): # return HttpResponseRedirect(reverse('register', args=[event_id, settings.REGISTRATION_MESSAGE])) #else: return HttpResponseRedirect(reverse('event', args=[event_id])) else: # Do Nothing (page will reload with no one logged in) login_form = LoginForm() logout_form = LogoutForm() pass elif logout_form.is_valid(): logout_user(request) login_form = LoginForm() user_profile_form = UserProfileForm() register_event_form = RegisterEventForm() if user_is_logged_in(request): if register_event_form.is_valid(): register_user_for_event(request, event, profile) return HttpResponseRedirect(reverse('event', args=[event_id])) context_data = { 'event': event, 'login_form': login_form, 'logout_form': logout_form, 'register_event_form': register_event_form, 'user_profile_form': user_profile_form, } return render_to_response('register.html', context_data, context_instance = RequestContext(request))