Пример #1
0
	def save(self, user_id):
		username = self.cleaned_data["username"].lower()	
		address = self.cleaned_data["address1"]
		u = User.objects.get(pk = self.cleaned_data["user_id"])
		u.username = username
		u.save()
		zipcode_obj = ZipCode.objects.get(code=self.cleaned_data["zip_code"])
		phone = parse_phone_number(self.cleaned_data["phone"], zipcode_obj.city.region.country.code)
		m = Merchant.objects.get(user__pk = self.cleaned_data["user_id"])
		p, created = MerchantPhone.objects.get_or_create(merchant=m, number = phone)
		m.address_1 = address
		m.business_name = self.cleaned_data["business_name"]
		m.zipcode= zipcode_obj
		url = self.cleaned_data["url"]
		yelp_url = self.cleaned_data["yelp_url"]
		fb_url = self.cleaned_data["fb_url"]
		twitter_url = self.cleaned_data["twitter_url"]
		if url: m.url = url
		if yelp_url : m.yelp_url = yelp_url
		if fb_url: m.fb_url = fb_url
		if twitter_url : m.twitter_url = twitter_url
		m.save()
		m.set_location_from_address()

		phones = self.cleaned_data["phones"]
		phone_list = phones.split(",")
		for p in phone_list:
			p_obj, created = MerchantPhone.objects.get_or_create(merchant=m, number = parse_phone_number(p))
Пример #2
0
	def iphone_review(self):

		us, created = Country.objects.get_or_create(name="United States", code="US")
		region, created = Region.objects.get_or_create(name="Hawaii", code="HI", country=us)
		city, created = City.objects.get_or_create(name="Huna", region=region)
		zipcode1, created = ZipCode.objects.get_or_create(code="96727", city=city)

		# create users
		u, created = User.objects.get_or_create(username="******")
		u.email="*****@*****.**"
		u.set_password("hello")
		u.save()
		
		num = parse_phone_number("6176829602")
		if not Customer.objects.filter(user=u).exists():
			c, created = Customer.objects.get_or_create(user=u, address_1="", address_2="", zipcode=zipcode1, balance=1000)
			p, pcreated = CustomerPhone.objects.get_or_create(customer = c, number = num)
			c.active = True
			c.verified = True
			c.save()
			c.set_location_from_address()
	
		u, created = User.objects.get_or_create(username="******")
		u.email="*****@*****.**"
		u.set_password("hello")
		u.save()
		
		#617-453-8665 Meng's googlevoice number
		num = parse_phone_number("6174538665")
		if not Merchant.objects.filter(user=u).exists():
			m, created = Merchant.objects.get_or_create(user=u, address_1="", address_2="", zipcode=zipcode1, phone=num, balance=10000, business_name="Dunkin Donuts", admin="Jake Sullivan", url="http://www.shoppley.com")
			p, pcreated =MerchantPhone.objects.get_or_create(merchant = m, number = num)
			m.active = True
			m.verified = True
			m.save()
			m.set_location_from_address()

		shop_user = Customer.objects.get(user__email="*****@*****.**")
		shop_merch = Merchant.objects.get(user__email="*****@*****.**")
		shop_user.merchant_likes.add(shop_merch)

		offers = ["$5 off shoes brands, Nike, Reebok",
				"10% off Abercrombie flip flops",
								"Save $15 on your purchase of dress shoes",
								"Buy dress shoes today & get free socks"]

		m = Merchant.objects.get(user__email="*****@*****.**")	
		for o in offers:
			# start offers 30 minutes ago
			input_time = datetime.now()-timedelta(minutes=30)
			offer = Offer(merchant=m, title=o[:40], description=o, time_stamp=input_time, duration=40320, starting_time=input_time) 
			offer.save()

		self.distributor.handle_noargs()
Пример #3
0
	def save(self, user_id):
		username = self.cleaned_data["username"].lower()	
		address = self.cleaned_data["address1"].lower()
		u = User.objects.get(pk = user_id)
		u.username = username
		u.save()
		zipcode_obj = ZipCode.objects.get(code=self.cleaned_data["zip_code"])

		phone = parse_phone_number(self.cleaned_data["phone"], zipcode_obj.city.region.country.code)
		customer = u.shoppleyuser.customer
		if (not customer.customerphone) or (not customer.customerphone.number==phone):
		#phone!= u.shoppleyuser.customer.phone:
			t = TxtTemplates()
			msg = t.render(TxtTemplates.templates["CUSTOMER"]["VERIFY_PHONE"], {})
			sms_notify(phone, msg)
			
		c = u.shoppleyuser.customer
		c.address_1 = address
		p,created = CustomerPhone.objects.get_or_create(customer=c, defaults={"number":phone,})
		if not created:
			p.number = phone
			p.save()

		c.daily_limit = self.cleaned_data["daily_limit"]
		c.zipcode = zipcode_obj
		c.save()
		c.set_location_from_address()
Пример #4
0
	def handle_merchant_signup(self, su, from_number, command, text, parsed):
		self.handle_lack_params(from_number, command, text, parsed)
		parsed_email = parsed[1].lower()
		parsed_zip = parsed[2]
		business = ''.join(i+' ' for i in parsed[3:]).strip()
		email = self.check_email(parsed_email, from_number)
		zipcode = self.check_zipcode(parsed_zip, from_number)
		phone = self.check_phone(from_number, from_number)
		randompassword = gen_random_pw()
		new_user = User.objects.create_user(email,email,randompassword)
		EmailAddress.objects.add_email(new_user,email)
		zipcode_obj = ZipCode.objects.filter(code=parsed_zip)[0]
		clean_phone = parse_phone_number(phone, zipcode_obj.city.region.country.code)
		new_merchant = Merchant.objects.create(user=new_user,
											phone=clean_phone,
											zipcode=zipcode_obj,
											business_name=business,
											verified=True,
											verified_phone=0)
		new_merchant.set_location_from_address()
		p=MerchantPhone.objects.create(number=clean_phone,merchant=new_merchant)
		number = new_merchant.count_customers_within_miles()
		receipt_msg = t.render(templates["MERCHANT"]["SIGNUP_SUCCESS"], {													"email":email,
				"password":randompassword,
				"number":number})
		self.notify(from_number, receipt_msg)
		reg_logger.info("merchant-signup: %s -- success" % from_number)
Пример #5
0
	def handle_customer_signup(self, su, from_number, command, text, parsed):	
		self.handle_lack_params(from_number, command, text, parsed)
		parsed_email = parsed[1].lower()
		parsed_zip = parsed[2]
		email = self.check_email(parsed_email, from_number)
		zipcode = self.check_zipcode(parsed_zip, from_number)
		phone = self.check_phone(from_number, from_number)
		randompassword = gen_random_pw()
		
		new_user = User.objects.create_user(email,email,randompassword)
		EmailAddress.objects.add_email(new_user,email)
		zipcode_obj = ZipCode.objects.filter(code=parsed_zip)[0]
		clean_phone = parse_phone_number(phone,zipcode_obj.city.region.country.code)
		
		new_customer = Customer.objects.create(user=new_user,
											phone=clean_phone,
											zipcode=zipcode_obj,
											verified=True,
											verified_phone=0)
		new_customer.set_location_from_address()
		p =CustomerPhone.objects.create(number=clean_phone,customer=new_customer)
		number = new_customer.count_merchants_within_miles()
		receipt_msg = t.render(templates["CUSTOMER"]["SIGNUP_SUCCESS"], {
						"email":email,
						"password":randompassword,
						"number":number,})
		self.notify(from_number, receipt_msg)
		reg_logger.info("customer-signup: %s -- success" % from_number)
Пример #6
0
def register_merchant(request):
	data = {}
	# input parameters
	business_name = request.POST['business']
	email = request.POST['email'].lower()
	phone = parse_phone_number(request.POST['phone'])
	zipcode = request.POST['zipcode']
	password = request.POST.get(['password'], '')
	
	# need to clean up phone

	if not ZipCode.objects.filter(code=zipcode).exists():
		# ERROR: zip code is invalid
		data["result"] = -2
		data["result_msg"] = "Zip code is invalid or not yet registered in system."
		return JSONHttpResponse(data)	
	else:
		zipcode_obj = ZipCode.objects.get(code=zipcode)

	u, created = User.objects.get_or_create(username=email, email=email)
	if created:
		if len(password) == 0:
		  s = string.lowercase+string.digits
		  password = ''.join(random.sample(s,6))
		
		u.set_password(password)	
		u.save()
		# create customer information
		c = Merchant(user=u, zipcode=zipcode_obj, phone=phone, business_name=business_name)
		# TODO: handle same business name? Possibly no need to
		c.save()
		MerchantPhone.objects.create(number=phone, merchant=c)

		# send a text message and e-mail with random password
		message = _("Please login to http://www.shoppley.com and you will be given free points to start sending Shoppley offers.")
		recipients = [email]
		send_mail("Welcome to Shoppley", message, settings.DEFAULT_FROM_EMAIL, recipients)
		# txt_msg = _("%(password)s is temporary password for shoppley.com. Txt #help to %(shoppley)s to get started.") % { "password": rand_passwd, "shoppley":settings.SHOPPLEY_NUM }
		# sms_notify(phone, txt_msg, SMS_DEBUG)
	else:
		# ERROR: User exists, ask user to login with their password 
		data["result"] = -1
		data["result_msg"] = "User already exists so you should login with their password."
		return JSONHttpResponse(data)	

	# you can start viewing offers	
	user = authenticate(username=email, password=rand_passwd)
	if user is not None:
		login(request, user)
		#logger.debug( "User %s authenticated and logged in"%email )
		data["result"] = 1
		data["result_msg"] = "User registered and authenticated successfully."
		return JSONHttpResponse(data)	 
	else:
		# ERROR: problem authenticating user
		data["result"] = -3
		data["result_msg"] = "Authentication error, possibly the user is not activated."
		return JSONHttpResponse(data)
Пример #7
0
	def save(self):
		# assign email as user name
		username = self.cleaned_data["username"].lower()
		email = self.cleaned_data["email"].lower()
		password = self.cleaned_data["password1"]
		
		if self.cleaned_data["confirmation_key"]:
			from friends.models import JoinInvitation # @@@ temporary fix for issue 93
			try:
				join_invitation = JoinInvitation.objects.get(confirmation_key = self.cleaned_data["confirmation_key"])
				confirmed = True
			except JoinInvitation.DoesNotExist:
				confirmed = False
		else:
			confirmed = False
		
		# @@@ clean up some of the repetition below -- DRY!
		
		if confirmed:
			if email == join_invitation.contact.email:
				new_user = User.objects.create_user(username, email, password)
				join_invitation.accept(new_user) # should go before creation of EmailAddress below
				new_user.message_set.create(message=ugettext(u"Your email address has already been verified"))
				# already verified so can just create
				EmailAddress(user=new_user, email=email, verified=True, primary=True).save()
			else:
				new_user = User.objects.create_user(username, "", password)
				join_invitation.accept(new_user) # should go before creation of EmailAddress below
				if email:
					new_user.message_set.create(message=ugettext(u"Confirmation email sent to %(email)s") % {'email': email})
					EmailAddress.objects.add_email(new_user, email)
		else:
			new_user = User.objects.create_user(username, "", password)
			if email:
				new_user.message_set.create(message=ugettext(u"Confirmation email sent to %(email)s") % {'email': email})
				EmailAddress.objects.add_email(new_user, email)
		
		if settings.ACCOUNT_EMAIL_VERIFICATION:
			new_user.is_active = False
			new_user.save()

		zipcode_obj = ZipCode.objects.get(code=self.cleaned_data["zip_code"])
		phone = parse_phone_number(self.cleaned_data["phone"], zipcode_obj.city.region.country.code)
		t = TxtTemplates()
		msg = t.render(TxtTemplates.templates["CUSTOMER"]["VERIFY_PHONE"], {})
		sms_notify(phone, msg)

		new_customer = Customer.objects.create(user=new_user,
						address_1=self.cleaned_data["address_1"],
						# address_2=self.cleaned_data["address_2"],
				#		phone=phone,
						zipcode=zipcode_obj,
						verified=True,
					)
		new_customer.set_location_from_address()
		p = CustomerPhone.objects.create(number=phone ,customer = new_customer)
		return username, password # required for authenticate()
Пример #8
0
	def validate_number(self,number, phone):
		try:
			a = phone_pattern.parseString(number)
			return parse_phone_number(number)
		except ParseException:
			msg = t.render(templates["SHARED"]["INVALID_NUMBER"], 
						{"number": number, })
			self.notify(phone, msg)
			raise CommandError("INVALID NUMBER: %s is an invalid number." % number)
Пример #9
0
	def clean_phone(self):
		if not phone_red.search(self.cleaned_data["phone"]):
			raise forms.ValidationError(_("This phone number is not recognized as a valid one. %s"%self.cleaned_data["phone"]))
		phone = parse_phone_number(self.cleaned_data["phone"]) 
		#su = ShoppleyUser.objects.filter(phone__icontains=phone)
		if ShoppleyPhone.objects.filter(number=phone).exists():
			raise forms.ValidationError(_("This phone number is being used by another user"))
		else:
			return self.cleaned_data["phone"]
Пример #10
0
	def gen_forward_offercode(self,original_code,phone):
	
		#forwarder = OfferCode.objects.filter(code__iexact=original_code)
		
		gen_code = gen_offer_code()
		phone =parse_phone_number(phone)
	
		while (OfferCode.objects.filter(code__iexact=gen_code).count()>0):
			gen_code = gen_offer_code()
		forwarder=original_code.customer
	
		#friend = Customer.objects.get(phone=(phone))
		print phone
		if CustomerPhone.objects.filter(number=phone).exists():
			p = CustomerPhone.objects.get(number=phone)
			#if p.shoppleyuser.is_customer():
			friend = p.customer
			o=self.offercode_set.create(
					customer=friend,
					code = gen_code,
					forwarder=forwarder,
					time_stamp=datetime.now(),
					expiration_time=original_code.expiration_time,
					rtype = 3)
			o.save()
			forwarder.customer_friends.add(p.customer)
			return o, None # for existing customer

#		except Customer.DoesNotExist:
			# TODO: Need to replace the following with code below
			# create a customer
			# create a username with phone num and create random password

			#print "Creating NEW user with username:"******""
		s = string.letters+string.digits
		rand_passwd = ''.join(random.sample(s,6))
		u.set_password(rand_passwd)	
		u.save()
		
		friend, created = Customer.objects.get_or_create(user=u, address_1="", address_2="", zipcode=original_code.customer.zipcode)
		p= CustomerPhone.objects.create(number = phone, customer = friend)
		if created:
			friend.set_location_from_address()	
		# send out a new offercode
		o=self.offercode_set.create(
				customer = friend,
				code = gen_code,
				forwarder=forwarder,
				time_stamp=datetime.now(),
				expiration_time=original_code.expiration_time,
				rtype = 3)
		o.save()
			
		forwarder.customer_friends.add(friend)
		return o, rand_passwd  # for new customer
Пример #11
0
	def check_phone(self, from_number, phone):
		self.validate_number(phone, from_number)
		phone = parse_phone_number(phone)
	
		if ShoppleyPhone.objects.filter(number__icontains=phone).exists():
			receipt_msg = t.render(templates["SHARED"]["PHONE_TAKEN"], {"phone":phone,})
			self.notify(from_number, receipt_msg)
			raise CommandError("Phone number was already used")
		else:
			return phone
Пример #12
0
	def clean_phones(self):
		phones = self.cleaned_data["phones"]
		phone_list = phones.split(",")
		merchant = Merchant.objects.get(user__id=self.cleaned_data["user_id"])
		for phone in phone_list:
			if not phone_red.search(phone):
				 raise forms.ValidationError(_("This phone number is not recognized as a valid one. %s"%self.cleaned_data["phone"]))
			phone = parse_phone_number(self.cleaned_data["phone"])
			if ShoppleyPhone.objects.filter(number=phone).exists():
				if MerchantPhone.objects.filter(number=phone).exists() and MerchantPhone.objects.filter(number=phone)[0].merchant != merchant:
					raise forms.ValidationError(_("%s is being used by another user") % phone)
		return self.cleaned_data["phones"]
Пример #13
0
def register_customer(request):
	email = request.POST['email'].lower()
	phone = parse_phone_number(request.POST['phone'])
	zipcode = request.POST['zipcode']
	password = request.POST['password']
    
	#TODO check null
	data = customer_register(email, None, zipcode, phone, password, None, None)
	
	if data["result"] == 1:
		data = customer_authenticate(request, data["username"], data["password"]);
		
	return JSONHttpResponse(data)
Пример #14
0
	def clean_phone(self):
		if not phone_red.search(self.cleaned_data["phone"]):
			raise forms.ValidationError(_("This phone number is not recognized as a valid one. %s"%self.cleaned_data["phone"]))
		phone = parse_phone_number(self.cleaned_data["phone"])
		user = User.objects.get(id=self.cleaned_data["user_id"])
		customer = Customer.objects.get(user__id=user.id)
                if customer.customerphone and customer.customerphone.number== phone:
                        return self.cleaned_data["phone"]
 
		#su = ShoppleyUser.objects.filter(phone=phone)
		if ShoppleyPhone.objects.filter(number=phone).exists():
			raise forms.ValidationError(_("This phone number is being used by another user"))
		else:
			return self.cleaned_data["phone"]
Пример #15
0
	def save(self):
		user = self.request.user
		fbuser = self.request.facebook.graph.get_object("me")
		user.username = "******" + self.request.facebook.uid + "|" +fbuser['first_name'] + " " + fbuser['last_name']
		print user, user.username
		user.save()

		email = fbuser['email']
		EmailAddress.objects.get_or_create(user=user, email=fbuser['email'], verified=True, primary=True)

		phone = parse_phone_number(self.cleaned_data["phone"])
		t = TxtTemplates()
		msg = t.render(TxtTemplates.templates["CUSTOMER"]["VERIFY_PHONE"], {})
		#sms_notify(phone, msg)

		code = self.cleaned_data["zip_code"]
		zipcode = ZipCode.objects.get(code=code)
		c = Customer.objects.create(user=user, is_fb_connected=True, zipcode=zipcode)
		p = CustomerPhone.objects.create(customer=c, number=phone)
Пример #16
0
	def save(self):

		user =self.request.user
		fbuser = self.request.facebook.graph.get_object("me")
		user.username = "******" + self.request.facebook.uid + "|" +fbuser['first_name'] + " " + fbuser['last_name']
		
		user.save()
		
		email = fbuser['email']
		EmailAddress.objects.get_or_create(user=user, email=fbuser['email'], verified=True, primary=True)
	
	
		phone = parse_phone_number(self.cleaned_data["phone"])
		code = self.cleaned_data["zip_code"]
		zipcode = ZipCode.objects.get(code=code)
		address_1 = self.cleaned_data["address1"]
		business_name = self.cleaned_data["business_name"]
		m = Merchant.objects.create(user = user, is_fb_connected=True, phone=phone, zipcode=zipcode,address_1=address_1, business_name=business_name)
		p = MerchantPhone.objects.create(merchant = m, number = phone)
Пример #17
0
def customer_signup(request, form_class=CustomerSignupForm,
	template_name="shoppleyuser/customer_signup.html", success_url=None):
	#success_url = "shoopleyuser/customer_landing_page.html"

	success_url = "/shoppleyuser/customer/signup-success"

	if success_url is None:
		success_url = get_default_redirect(request)
	if request.method == "POST":
		form = form_class(request.POST)
		if form.is_valid():
			username, password = form.save()
			#from shoppleyuser.utils import parse_phone_number,sms_notify
			#signup_msg = _("Welcome to Shoppley! Txt \"#help\" for all commands. Enjoy!")
			#sms_notify(parse_phone_number(form.cleaned_data["phone"]),signup_msg)

			if settings.ACCOUNT_EMAIL_VERIFICATION:
				return render_to_response("account/verification_sent.html", {
					"email": form.cleaned_data["email"],
				}, context_instance=RequestContext(request))
			else:
				user = authenticate(username=username, password=password)
				auth_login(request, user)
				request.user.message_set.create(
					message=_("Successfully logged in as %(username)s.") % {
						'username': user.username
					})
				from shoppleyuser.utils import parse_phone_number,sms_notify
				signup_msg =unicode(_("Welcome to Shoppley! Txt \"#help\" for all commands. Enjoy!"))
				#print signup_msg
				try :
					sms_notify(parse_phone_number(form.cleaned_data["phone"]),signup_msg)
				except ValidationError:
					pass

				return HttpResponseRedirect(success_url)
	else:
		form = form_class()
	return render_to_response(template_name, {
		"form": form,
	}, context_instance=RequestContext(request))
Пример #18
0
	def clean(self):
		#		raise forms.ValidationError(_("You must fill in at least one of the two fields testing."))
		if not "business_num" in self.cleaned_data and not "business_name" in self.cleaned_data and not "zipcode" in self.cleaned_data:
			raise	forms.ValidationError(_("You must fill in at least one of the fields."))
		m=None
		if "zipcode" in self.cleaned_data:
			return self.cleaned_data
		if "business_num" in self.cleaned_data:
			
			business_num = parse_phone_number(self.cleaned_data["business_num"])
			if MerchantPhone.objects.filter(number=business_num).exists():
				m = MerchantPhone.objects.get(number=business_num).merchant
		elif "business_name" in self.cleaned_data:
			business_name = self.cleaned_data["business_name"].strip()
			if Merchant.objects.filter(business_name__icontains= business_name).exists():
				m = Merchant.objects.filter(business_name__icontains= business_name)[0]
		
		if m:
			return self.cleaned_data
		else:
			raise forms.ValidationError(_("We cannot find a merchant with the following information. Please create a merchant account for the merchant."))
Пример #19
0
	def test_handle(self,msg):
		from_number = parse_phone_number(msg["from"])
		text = msg["text"].strip()
		su = map_phone_to_user(from_number)
		
		# ************* HANDLE UNVERIFIED NUMBER *****************
		self.handle_unverified_number(su, from_number, text)
		# ************* MERCHANT COMMANDS ******************
		if su and su.is_merchant():
			try:
				parsed = merchant_pattern.parseString(text)
				del parsed[0]
				command = parsed[0].lower()
				print "command" , command
				# ************************* BALANCE ********************
				if command in BALANCE:
					self.handle_balance(su, from_number, parsed)
					
				# ************************* REDEEM *********************
				elif command in REDEEM:
					self.handle_redeem(su, from_number,command, text, parsed)
					
				# ************************* ZIPCODE *********************
				elif command in ZIPCODE:
					self.handle_merchant_zipcode(su, from_number,command, text, parsed)
					
				# ************************* OFFER *********************
				elif command in OFFER:
					self.handle_offer(su, from_number, command, text, parsed)
				# ************************* REOFFER *********************
				elif command in REOFFER:
					self.handle_reoffer(su, from_number, command, text, parsed)
					
				# ************************* STATUSs *********************
				elif command in STATUS:
					self.handle_status(su, from_number, command, text, parsed)
					
				# ************************* RESIGNUP *********************
				elif command in MERCHANT_SIGNUP:
					sender_msg = t.render(templates["MERCHANT"]["RESIGNUP"], {})
					self.notify(from_number, sender_msg)
					reg_logger.info("merchant-signup: %s -- failure (resignup)" % from_number)
				# *************************ADD *********************
				elif command in ADD:
					self.handle_add(su, from_number, command, text, parsed)	
				# ************************* HELP *********************

				elif command in HELP:
					commands = self.merchant_help()
					self.notify(from_number, commands)
					
				# ************************* UNHANDLED COMMAND *********************
				else:
					receipt_msg = t.render(templates["MERCHANT"]["INCORRECT_COMMAND"], {
										"command": command,
										"help": self.merchant_help()})
					self.notify(from_number, receipt_msg)
					
			except ParseException:
				sender_msg = _("%s is not a valid command. Our commands start with # sign. Txt #help for all commands.") % text
				self.notify(from_number, sender_msg)
				
		# ************* CUSTOMER COMMANDS ******************
		elif su and su.is_customer():
			try:
				parsed = customer_pattern.parseString(text)
				del parsed[0]
				command = parsed[0].lower()
				# ************************* BALANCE *********************
				if command in BALANCE:
					self.handle_balance(su, from_number, parsed)
				# ************************* INFO *********************
				elif command in INFO:
					self.handle_info(su, from_number, command, text, parsed)
				# ************************* IWANT *********************
				elif command in IWANT:
					self.handle_iwant(su, from_number, command, text, parsed)
				# ************************* YAY/NAY *********************
				elif command in VOTE:
					self.handle_vote(su, from_number, command, text, parsed)
				# ************************* STOP *********************
				elif command in STOP:
					self.handle_stop(su, from_number)
				# ************************* START *********************
				elif command in START:
					self.handle_start(su, from_number)
				# ************************* ZIPCODE *********************
				elif command in ZIPCODE:
					self.handle_customer_zipcode(su, from_number,command, text, parsed)
				# ************************* FORWARD *********************
				elif command in FORWARD:
					self.handle_forward(su, from_number, command, text, parsed)
				# ************************* HELP *********************
				elif command in HELP:
					self.handle_customer_help(from_number)
				# ************************* RESIGNUP *********************
				elif command in SIGNUP:
					self.handle_customer_resignup( from_number)
				# ************************* UNHANDLED COMMAND *********************
				else:
					receipt_msg = t.render(templates["CUSTOMER"]["INCORRECT_COMMAND"], {
										"command": command,
										"help": self.customer_help()})
					self.notify(from_number, receipt_msg)
					
					
			except ParseException:
				
				sender_msg = _("%s is not a valid command. Our commands start with # sign. Txt #help for all commands.") % text
				self.notify(from_number, sender_msg)				
				
		else:
			if not su:
				try:
					parsed = customer_pattern.parseString(text)
					del parsed[0]
					command = parsed[0].lower()
					# ************************* MERCHANT SIGNUP *********************
					if command in MERCHANT_SIGNUP:
						self.handle_merchant_signup(su, from_number, command, text, parsed)
					# ************************* CUSTOMER SIGNUP *********************
	
					elif command in SIGNUP:
						self.handle_customer_signup(su, from_number, command, text, parsed)
						
					else:
						sender_msg = t.render(templates["SHARED"]["NON_USER"], {
										"site":DEFAULT_SITE,
										"shoppley_num": settings.SHOPPLEY_NUM,})
						self.notify(from_number, sender_msg)
						
				except ParseException:
					sender_msg = t.render(templates["SHARED"]["NON_USER"], {
										"site":DEFAULT_SITE,
										"shoppley_num": settings.SHOPPLEY_NUM,})
					self.notify(from_number, sender_msg)
Пример #20
0
	def setUp(self):
		self.pp = pprint.PrettyPrinter(indent=2)
		self.f = open("/tmp/shoppley.test.out.txt", "w")

		us, created = Country.objects.get_or_create(name="United States", code="US")
		region, created = Region.objects.get_or_create(name="Hawaii", code="HI", country=us)
		city, created = City.objects.get_or_create(name="Aiea", region=region)
		zipcode1, created = ZipCode.objects.get_or_create(code="96701", city=city)
		city, created = City.objects.get_or_create(name="Anahola", region=region)
		zipcode2, created = ZipCode.objects.get_or_create(code="96703", city=city)
		city, created = City.objects.get_or_create(name="Ahualoa", region=region)
		zipcode3, created = ZipCode.objects.get_or_create(code="96727", city=city)

		# create users
		u, created = User.objects.get_or_create(username="******")
		u.email="*****@*****.**"
		u.set_password("hello")
		u.save()
		
		num = parse_phone_number("6176829602")
		if not Customer.objects.filter(user=u).exists():
			c, created = Customer.objects.get_or_create(user=u, address_1="", address_2="", zipcode=zipcode1, balance=1000)
			p, pcreated = CustomerPhone.objects.get_or_create(customer = c, number = num)
			c.active = True
			c.verified = True
			c.save()
			c.set_location_from_address()
		
		u, created = User.objects.get_or_create(username="******")
		u.email="*****@*****.**"
		u.set_password("hello")
		u.save()
		
		num = parse_phone_number("6174538710")
		if not Customer.objects.filter(user=u).exists():
			c, created = Customer.objects.get_or_create(user=u, address_1="15 Franklin St.", address_2="", zipcode=zipcode1, balance=1000)
			p, pcreated = CustomerPhone.objects.get_or_create(customer = c, number = num)
			c.active = True
			c.verified = True
			c.save()
			c.set_location_from_address()

		u, created = User.objects.get_or_create(username="******")
		u.email="*****@*****.**"
		u.set_password("hello")
		u.save()
		
		#617-682-9784 Meng's other googlevoice
		num = parse_phone_number("6176829784")
		if not Customer.objects.filter(user=u).exists():
			c, created = Customer.objects.get_or_create(user=u, address_1="15 Franklin St.", address_2="", zipcode=zipcode2,balance=1000)
			p, pcreated = CustomerPhone.objects.get_or_create(customer = c, number = num)
			c.active = True
			c.verified = True
			c.save()
			c.set_location_from_address()

		u, created = User.objects.get_or_create(username="******")
		u.email="*****@*****.**"
		u.set_password("hello")
		u.save()
		
		#617-453-8665 Meng's googlevoice number
		num = parse_phone_number("6174538665")
		if not Merchant.objects.filter(user=u).exists():
			m, created = Merchant.objects.get_or_create(user=u, address_1="", address_2="", zipcode=zipcode1, phone=num, balance=10000, business_name="Jane's Shoe Store", admin="Jane Sullivan", url="http://www.shoppley.com")
			p, pcreated =MerchantPhone.objects.get_or_create(merchant = m, number = num)
			m.active = True
			m.verified = True
			m.save()
			m.set_location_from_address()
			print "Merchant location set:", m.location

		u, created = User.objects.get_or_create(username="******")
		u.email="*****@*****.**"
		u.set_password("hello")
		u.save()

		num = parse_phone_number("6178710710")
		if not Merchant.objects.filter(user=u).exists():
			m, created = Merchant.objects.get_or_create(user=u, address_1="190 Mass Av.", address_2="", zipcode=zipcode1, phone=num, balance=10000, business_name="Flour Bakery", admin="Kevin Bacon", url="http://www.shoppley.com")
			p, pcreated =MerchantPhone.objects.get_or_create(merchant = m, number = num)
			m.active = True
			m.verified = True
			m.save()
			m.set_location_from_address()

		u, created = User.objects.get_or_create(username="******")
		u.email="*****@*****.**"
		u.set_password("hello")
		u.save()

		num = parse_phone_number("6177154416")
		if not Merchant.objects.filter(user=u).exists():
			m, created = Merchant.objects.get_or_create(user=u, address_1="190 Mass Av.", address_2="", zipcode=zipcode2, phone=num, balance=10000, business_name="John's Auto", admin="John Jacobson", url="http://www.shoppley.com")
			p, pcreated =MerchantPhone.objects.get_or_create(merchant = m, number = num)
			m.active = True
			m.verified = True
			m.save()
			m.set_location_from_address()



		shop_user = Customer.objects.get(user__email="*****@*****.**")
		shop_merch = Merchant.objects.get(user__email="*****@*****.**")
		shop_user.merchant_likes.add(shop_merch)

		# create categories
		categories = [("Dining & Nightlife", "dining"), ("Health & Beauty", "health"), ("Fitness","fitness"), ("Retail & Services", "retail"), ("Activities & Events", "activities"), ("Special Interests", "special")]
		for cat in categories:
			category, created = Category.objects.get_or_create(name=cat[0], tag=cat[1])


		self.distributor = distribute.Command()
Пример #21
0
	def save(self, *args, **kwargs):
		from shoppleyuser.utils import parse_phone_number
		self.number = parse_phone_number(self.number)
		super(ShoppleyPhone, self).save(*args, **kwargs)
Пример #22
0
 def save(self, *args, **kwargs):
     from shoppleyuser.utils import parse_phone_number
     self.number = parse_phone_number(self.number)
     super(ShoppleyPhone, self).save(*args, **kwargs)
Пример #23
0
    def gen_forward_offercode(self, original_code, phone):

        #forwarder = OfferCode.objects.filter(code__iexact=original_code)

        gen_code = gen_offer_code()
        phone = parse_phone_number(phone)

        while (OfferCode.objects.filter(code__iexact=gen_code).count() > 0):
            gen_code = gen_offer_code()
        forwarder = original_code.customer

        #friend = Customer.objects.get(phone=(phone))
        print phone
        if CustomerPhone.objects.filter(number=phone).exists():
            p = CustomerPhone.objects.get(number=phone)
            #if p.shoppleyuser.is_customer():
            friend = p.customer
            o = self.offercode_set.create(
                customer=friend,
                code=gen_code,
                forwarder=forwarder,
                time_stamp=datetime.now(),
                expiration_time=original_code.expiration_time,
                rtype=3)
            o.save()
            forwarder.customer_friends.add(p.customer)
            return o, None  # for existing customer

#		except Customer.DoesNotExist:
# TODO: Need to replace the following with code below
# create a customer
# create a username with phone num and create random password

#print "Creating NEW user with username:"******""
        s = string.letters + string.digits
        rand_passwd = ''.join(random.sample(s, 6))
        u.set_password(rand_passwd)
        u.save()

        friend, created = Customer.objects.get_or_create(
            user=u,
            address_1="",
            address_2="",
            zipcode=original_code.customer.zipcode)
        p = CustomerPhone.objects.create(number=phone, customer=friend)
        if created:
            friend.set_location_from_address()
        # send out a new offercode
        o = self.offercode_set.create(
            customer=friend,
            code=gen_code,
            forwarder=forwarder,
            time_stamp=datetime.now(),
            expiration_time=original_code.expiration_time,
            rtype=3)
        o.save()

        forwarder.customer_friends.add(friend)
        return o, rand_passwd  # for new customer