def offer_forward(request): """ :param offer_code: the code that is forwarded :param phones: list of phone numbers :param emails: list of emails :param note: a note for the friend """ data = {} u = request.user customer = u.shoppleyuser.customer offer_code = request.POST.get("offer_code", None) phones = request.POST.getlist("phones") emails = request.POST.getlist("emails") notes = request.POST.get("note", "") if offer_code and len(phones) > 0: if OfferCode.objects.filter(code__iexact=offer_code).exists(): original_code = OfferCode.objects.filter(code__iexact=offer_code)[0] offer = original_code.offer for phone in phones: new_code, random_pw = offer.gen_forward_offercode(original_code, phone) # text the user the user name and password customer_msg = _("%(customer)s forwarded you an offer!\n*from: %(merchant)s\n*title: %(description)s\n*expires: %(expiration)s\nCome redeem w/ [%(code)s]\n")%{ "customer": customer.phone, "merchant": offer.merchant, "expiration": pretty_date(original_code.expiration_time), "description": offer.description, "dollar_off": offer.dollar_off, "code": new_code.code, } #TODO: if the person do not mind receiving txt sms_notify(phone,customer_msg, SMS_DEBUG) if random_pw: new_customer = new_code.customer #print "created a customer for %s" % friend_num account_msg = _("Welcome to Shoppley! shoppley.com login info:\n-username: %(name)s\n-password: %(password)s\nTxt #help to %(shoppley)s to get started.")%{"name":new_customer.user.username,"password":random_pw, "shoppley": settings.SHOPPLEY_NUM} sms_notify(phone,account_msg, SMS_DEBUG) forwarder_msg= _('Offer by "%s" was forwarded to ') % offer_code forwarder_msg= forwarder_msg+ ''.join([str(i)+' ' for i in phones]) + "\nYou will receive points when they redeem their offers." data["confirm_msg"] = forwarder_msg data["result"] = 1 data["result_msg"] = "Offers have been forwarded." else: # ERROR: offer code is invalid data["result"] = -2 data["result_msg"] = "Offer code is invalid." else: # ERROR: no offer code POSTed data["result"] = -1 data["result_msg"] = "Offer code has not been specified in POST parameter." return JSONHttpResponse(data)
def offer_detail(self): """ Used to report to customer mobile phone """ location = self.offer.merchant.location.location offer_detail = { "offer_code_id": self.id, "offer_id": self.offer.id, "code": self.code, "name": self.offer.title, "merchant_name": self.offer.merchant.business_name, "description": self.offer.description, "expires": pretty_date(self.expiration_time - datetime.now()), "expires_time": int(time.mktime(self.expiration_time.timetuple())), "phone": self.offer.merchant.phone, "address1": self.offer.merchant.address_1, "citystatezip": self.offer.merchant.zipcode.citystate(), "lat": location.y, "lon": location.x, "img": self.offer.get_image(), "banner": self.offer.merchant.get_banner() } if self.offer.percentage: offer_detail["percentage"] = self.offer.percentage elif self.offer.dollar_off: offer_detail["dollar_off"] = self.offer.dollar_off if self.forwarder: offer_detail["forwarder"] = str(self.forwarder) return offer_detail
def offer_detail(self): """ Used to report to customer mobile phone """ location = self.offer.merchant.location.location offer_detail = {"offer_code_id": self.id, "offer_id": self.offer.id, "code": self.code, "name": self.offer.title, "merchant_name": self.offer.merchant.business_name, "description": self.offer.description, "expires": pretty_date(self.expiration_time-datetime.now()), "expires_time": int(time.mktime(self.expiration_time.timetuple())), "phone": self.offer.merchant.phone, "address1": self.offer.merchant.address_1, "citystatezip": self.offer.merchant.zipcode.citystate(), "lat": location.y, "lon": location.x, "img": self.offer.get_image(), "banner": self.offer.merchant.get_banner() } if self.offer.percentage: offer_detail["percentage"] = self.offer.percentage elif self.offer.dollar_off: offer_detail["dollar_off"] = self.offer.dollar_off if self.forwarder: offer_detail["forwarder"] = str(self.forwarder) return offer_detail
def forward_info(self, offercode): print "forward expiration:", offercode.expiration_time return t.render(templates["CUSTOMER"]["FORWARD_INFO"], { "description": offercode.offer.description, "merchant": offercode.offer.merchant, "expires": pretty_date(offercode.expiration_time, True), })
def info(self,offercode): #print "description", offercode.offer.description, "title:" , offercode.offer.title return t.render(templates["CUSTOMER"]["INFO"], { "offercode": offercode.code, "description": offercode.offer.title, "merchant": offercode.offer.merchant, "expiration": pretty_date(offercode.expiration_time, True), })
def customer_offercode_side_tag(offercode): offer = offercode.offer return { "title": offer.title, "description": offer.description, "location": offer.merchant.print_address(), "biz_name": offer.merchant.business_name, "time_left": pretty_date(offer.expired_time, True), "STATIC_URL": settings.STATIC_URL, "redeem_time": pretty_datetime(offercode.redeem_time), }
def customer_offer_side_tag(offer): offer = offercode.offer return { "title": offer.title, "description": offer.description, "location": offer.merchant.print_address(), "biz_name" : offer.merchant.business_name, "time_left": pretty_date(offer.expired_time, True), "STATIC_URL": settings.STATIC_URL, #"redeem_time": pretty_datetime(offer.redeem_time), }
def customer_offer_tag(offer): return {"title": offer.title, "description": offer.description, "location": offer.merchant.print_address(), "biz_name" : offer.merchant.business_name, "time_left": pretty_date(offer.expired_time, True), "STATIC_URL": settings.STATIC_URL, "gmap_src": offer.merchant.get_gmap_src(), "id": offer.id, "site": "http://" + Site.objects.get(id=3).domain , }
def customer_offer_tag(offer): return { "title": offer.title, "description": offer.description, "location": offer.merchant.print_address(), "biz_name": offer.merchant.business_name, "time_left": pretty_date(offer.expired_time, True), "STATIC_URL": settings.STATIC_URL, "gmap_src": offer.merchant.get_gmap_src(), "id": offer.id, "site": "http://" + Site.objects.get(id=3).domain, }
def merchant_offer_side_tag(offer): duration = offer.duration init_sent = offer.num_init_sentto forwarded = offer.offercode_set.filter(forwarder__isnull=False).count() redeemed = offer.offercode_set.filter(redeem_time__isnull=False).count() return {"title": offer.title, "description": offer.description, "init_sent": init_sent, "forwarded": forwarded, "redeemed": redeemed, "time_left": pretty_date(offer.expired_time, True), "STATIC_URL": settings.STATIC_URL, }
def merchant_offer_side_tag(offer): duration = offer.duration init_sent = offer.num_init_sentto forwarded = offer.offercode_set.filter(forwarder__isnull=False).count() redeemed = offer.offercode_set.filter(redeem_time__isnull=False).count() return { "title": offer.title, "description": offer.description, "init_sent": init_sent, "forwarded": forwarded, "redeemed": redeemed, "time_left": pretty_date(offer.expired_time, True), "STATIC_URL": settings.STATIC_URL, }
def customer_offer_detail(self, user): """ Used to report to customer mobile phone """ location = self.merchant.location.location offer_detail = { "offer_id": self.id, "name": self.title, "merchant_name": self.merchant.business_name, "description": self.description, # expires for older version only "expires": pretty_date(self.expired_time - datetime.now()), "expires_time": int(time.mktime(self.expired_time.timetuple())), "phone": self.merchant.phone, "address1": self.merchant.address_1, "citystatezip": self.merchant.zipcode.citystate(), "lat": location.y, "lon": location.x, "img": self.get_image(), "banner": self.merchant.get_banner(), } if self.percentage: offer_detail["percentage"] = self.percentage elif self.dollar_off: offer_detail["dollar_off"] = self.dollar_off try: offercode = OfferCode.objects.get(offer=self, customer=user) offer_detail["offer_code_id"] = offercode.id offer_detail["code"] = offercode.code if offercode.forwarder: offer_detail["forwarder"] = str(offercode.forwarder) except OfferCode.DoesNotExist: pass return offer_detail