Beispiel #1
0
def process_checkout(request):
	request.session['order_step'] = None

	try:
		if request.session['current_fundraiser']:
			request.session['finalized_order'] = request.session['current_fundraiser']
			del request.session['current_fundraiser']
	except:
		pass

	try:
		finalized_order = Fundraiser.objects.get(id=request.session['finalized_order'])
		order_type      = str(finalized_order.get_payment_type())
	except:
		finalized_order = None
		order_type = None

	session_finalized_fundraiser = SessionVariable(request).session_finalized_fundraiser()
	context = {
		'finalized_order' : finalized_order,
		'order_type' : order_type, 
		'form' : SimpleSignUpForm
	}
	# if session_finalized_fundraiser.profile.email:
	if session_finalized_fundraiser.profile.email and not session_finalized_fundraiser.receipt_email_sent:
		
		data = {
			'user' : session_finalized_fundraiser.profile.contact_person(),
			'organization' : session_finalized_fundraiser.profile.organization,
			'address' : session_finalized_fundraiser.shipment().address.street,
			'city' : session_finalized_fundraiser.shipment().address.city,
			'state' : session_finalized_fundraiser.shipment().address.state,
			'zip_code' : session_finalized_fundraiser.shipment().address.zip_code,
			'total' : session_finalized_fundraiser.net_total_in_dollars(),
			'title' : session_finalized_fundraiser.title,
			'selections' : session_finalized_fundraiser.selections_str(),
			'shipping' : session_finalized_fundraiser.free_shipping(),
			'phone' : session_finalized_fundraiser.profile.phone_number
		}

		template_name  = EMAIL_TEMPLATE_DIR + 'email_fundraiser_receipt_text_based.txt'
		text_email     = loader.render_to_string(template_name,data)
		email = session_finalized_fundraiser.profile.email
		type = session_finalized_fundraiser.type 
		
		send_fundraiser_receipt_email.delay(
			str(finalized_order.organization())+' Fundraiser', 
			text_email,
			'Jose Madrid Salsa fundraising <*****@*****.**>',
			[email],
			type.id
			)
	
		session_finalized_fundraiser.receipt_email_sent = True
		session_finalized_fundraiser.save()
	template = 'fundraiser/checkout-invoice.html'
	return render(request,template,context)
Beispiel #2
0
def choose_salsas(request):
	request.session['order_step'] = 'choose_salsas'
	session_shipment = SessionVariable(request,'current_fundraiser').session_shipment()
	session_fundraiser = SessionVariable(request,'current_fundraiser').session_fundraiser()
	session_fundraiser.discount = 0
	session_fundraiser.save()
	
	context = {}
	template = 'fundraiser/shipment.html'
	return render(request,template,context)
Beispiel #3
0
def auth_simple_sign_up(request):
	form = SimpleSignUpForm(request.POST or None)
	
	if form.is_valid():
		
		cleaned_form = form.cleaned_data
		username     = cleaned_form['username']
		password     = cleaned_form['password']
		confirmation = cleaned_form['confirm']

		user,created = User.objects.get_or_create(username=username)
		
		if created:
			session_finalized_fundraiser = SessionVariable(request).session_finalized_fundraiser()
			user.set_password(password)
			user.save()
			if session_finalized_fundraiser is None:
				title = 'session expired. call back office to set up account.'
				messages.error(request,title)
				return HttpResponseRedirect(reverse('describe_fundraiser'))

			profile = session_finalized_fundraiser.profile
			profile.account = user 
			profile.save()
			session_finalized_fundraiser.account = user
			session_finalized_fundraiser.save()
			
			auth = authenticate(username=username,password=password)
			
			login(request,auth)

			title = str(user.username) + ', You have successfully signed up! See your profile to manage your Organization.'
			messages.success(request,title)
			return HttpResponseRedirect(reverse('process_checkout'))
		else:
			title = 'Username exists, pick a more unique username!'
			messages.error(request,title)
			return HttpResponseRedirect(reverse('process_checkout'))
	else:
		title = 'There was an error in creating your account. Make sure passwords match!'
		messages.error(request,title)
		return HttpResponseRedirect(reverse('process_checkout'))
Beispiel #4
0
class Discount:
	def __init__(self,request,code):
		self.request = request
		self.code = code 
		self.type = None
		self.discount  = None
		self.session_fundraiser = SessionVariable(request,'current_fundraiser').session_fundraiser()

	def check_if_generic_code(self):
		try:
			generic_code = GenericDiscount.objects.get(special_code=self.code)
			if generic_code.active == False:
				generic_code = False
			else:

				self.type = 'generic'
				self.discount = generic_code
		except:
			generic_code = False	

		return generic_code

	def check_if_single_code(self):
		try:
			single_code = SingleDiscount.objects.get(special_code=self.code)
			if single_code.active == False:
				single_code = False
			else:
				self.type = 'single'
				self.discount = single_code
		except:
			single_code = False	

		return single_code

	def is_valid(self):
		if self.check_if_generic_code():
			return self.check_if_generic_code()
		elif self.check_if_single_code():
			return self.check_if_single_code()
		else:
			return False
		

	def set_discount(self):
		if self.discount.percent and self.discount.dollars:
			discount = (self.session_fundraiser.total_cost() * self.discount.to_percent())
			discount += self.discount.dollars
			self.session_fundraiser.discount = discount 
			self.session_fundraiser.save()
		elif self.discount.percent:
			discount = (self.session_fundraiser.total_cost() * self.discount.to_percent())
			self.session_fundraiser.discount = discount
			self.session_fundraiser.save()
		elif self.discount.dollars:
			self.session_fundraiser.discount = self.discount.dollars
			self.session_fundraiser.save()
		else:
			return False

	def use_discount(self):

		if self.type:
			if self.discount.active == False:
				return False
			else:
				if self.type == 'single':
					self.discount.fundraiser = self.session_fundraiser
				
				self.discount.used += 1
				
				self.set_discount()

				if self.discount.expired():
					self.discount.active = False

				self.discount.save()

				return True
Beispiel #5
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)