Beispiel #1
0
def edit_shipment(request,id):
	request.session['order_step'] = 'checkout'

	session            = SessionVariable(request,'current_fundraiser')
	session_fundraiser = session.session_fundraiser()
	session_shipment   = session.session_shipment()

	profile_form = ShipmentProfileForm(request.POST or None,instance=session_fundraiser.profile)
	address_form = AddressForm(request.POST or None, instance=session_shipment.address)
	
	if profile_form.is_valid() and address_form.is_valid():
		profile_form.save()
		address_form.save()
		title = 'You have successfully updated your shipment.'
		messages.success(request,title)
		return HttpResponseRedirect(reverse('create_shipment'))

	template = 'fundraiser/edit_shipment.html'
	context = {
		'shipment_address_form' : address_form, 
		'shipment_profile_form' : profile_form,
		'session_shipment' : session_shipment
	}
	return render(request,template,context)		
Beispiel #2
0
def create_shipment(request):
	request.session['order_step'] = 'create_shipment'
	shipment_profile_form = ShipmentProfileForm(request.POST or None)
	shipment_address_form = AddressForm(request.POST or None)
	billing_address_form  = AddressForm(request.POST or None)
	
	if shipment_profile_form.is_valid() and shipment_address_form.is_valid():

		a = shipment_address_form.cleaned_data
		p = shipment_profile_form.cleaned_data
		
		
		title    = a['title']
		street   = a['street']
		line_2   = a['line_2']
		city     = a['city']
		state    = a['state']
		zip_code = a['zip_code']

		first_name = p['first_name']
		last_name  = p['last_name']
		phone      = p['phone_number']
		email      = p['email']
		
		try:
			address, created = Address.objects.get_or_create(
				title=title,
				street=street,
				line_2=line_2,
				city=city,
				state=state,
				zip_code=zip_code
			)
		except:
			address = Address.objects.filter(street=street).first()


		session_fundraiser  = SessionVariable(request,'current_fundraiser').session_fundraiser()
		session_shipment    = SessionVariable(request,'current_fundraiser').session_shipment()


		if session_fundraiser.profile is None:
			messages.error(
				request, "Your profile was deleted from logging out, you'll have to recreate it.")
			return HttpResponseRedirect(reverse('describe_fundraiser'))
		else:
			session_shipment.address = address
			session_shipment.title   = title
			session_shipment.save()

			session_fundraiser.profile.first_name   = first_name
			session_fundraiser.profile.last_name    = last_name
			session_fundraiser.profile.phone_number = phone
			session_fundraiser.profile.email        = email
			session_fundraiser.profile.address      = address
			session_fundraiser.profile.save()

			return HttpResponseRedirect(reverse('checkout'))


	context = {
		'shipment_profile_form' : shipment_profile_form,
		'shipment_address_form' : shipment_address_form,
		'billing_address_form' : billing_address_form
	}

	template = 'fundraiser/shipment.html'
	return render(request,template,context)