def contact_us(request): if request.method == "POST": form = ContactUsForm(request.POST) if form.is_valid(): contact_us = form.save(commit=False) contact_us.submitted_on = datetime.now() contact_us.client = request.client.client contact_us.save() t_body = get_template('notifications/feedback/contactus.email') email_body = {} email_body['contact_us'] = contact_us c_body = Context(email_body) mail_obj = Email() mail_obj.isHtml = True mail_obj._from = request.client.client.noreply_email mail_obj.body = t_body.render(c_body) mail_obj.subject = "Contact-Us Form" u_emails = contact_us.email u_emails = u_emails.strip(',') mail_obj.to = "*****@*****.**" mail_obj.send() return render_to_response('pages/about/thank_you-contactus.html', None, context_instance=RequestContext(request)) else: form = ContactUsForm() return render_to_response('pages/about/contactus.html', { 'form': form, }, context_instance=RequestContext(request))
def send_coupons_by_email(request,coupon,affiliate_name,email_alert_on, show_avail_coupon): t_body = get_template('notifications/subscriptions/%s.email' % affiliate_name) email_body = {} pantaloon_coupon, bigbazaar_coupon, futurebazaar_coupon = None,None,None if show_avail_coupon and affiliate_name not in ["afaqs", "vcomm"]: try: email_body["coupon_code"] = coupon[str(affiliate_name)] except KeyError: pass try: email_body['pantaloon'] = coupon['pantaloon'] except KeyError: pass try: email_body['bigbazaar'] = coupon['bigbazaar'] except KeyError: pass try: email_body['futurebazaar'] = coupon['futurebazaar'] except KeyError: pass mail_obj = Email() mail_obj._from = "*****@*****.**" mail_obj.body = t_body.render(Context(email_body)) mail_obj.subject = "Avail your futurebazaar.com coupon codes." mail_obj.to = email_alert_on.email mail_obj.send()
def contact_us(request): if request.method == "POST": form = ContactUsForm(request.POST) if form.is_valid(): contact_us = form.save(commit=False) contact_us.submitted_on = datetime.now() contact_us.client = request.client.client contact_us.save() t_body = get_template('notifications/feedback/contactus.email') email_body = {} email_body['contact_us'] = contact_us c_body = Context(email_body) mail_obj = Email() mail_obj.isHtml = True mail_obj._from = request.client.client.noreply_email mail_obj.body = t_body.render(c_body) mail_obj.subject = "Contact-Us Form" u_emails = contact_us.email u_emails = u_emails.strip(',') mail_obj.to = "*****@*****.**" mail_obj.send() return render_to_response('pages/about/thank_you-contactus.html',None,context_instance = RequestContext(request)) else: form = ContactUsForm() return render_to_response('pages/about/contactus.html', { 'form':form, },context_instance = RequestContext(request))
def send_coupons_by_email(request, coupon, affiliate_name, email_alert_on, show_avail_coupon): t_body = get_template("notifications/subscriptions/%s.email" % affiliate_name) email_body = {} pantaloon_coupon, bigbazaar_coupon, futurebazaar_coupon = None, None, None if show_avail_coupon and affiliate_name not in ["afaqs", "vcomm"]: try: email_body["coupon_code"] = coupon[str(affiliate_name)] except KeyError: pass try: email_body["pantaloon"] = coupon["pantaloon"] except KeyError: pass try: email_body["bigbazaar"] = coupon["bigbazaar"] except KeyError: pass try: email_body["futurebazaar"] = coupon["futurebazaar"] except KeyError: pass mail_obj = Email() mail_obj._from = "*****@*****.**" mail_obj.body = t_body.render(Context(email_body)) mail_obj.subject = "Avail your futurebazaar.com coupon codes." mail_obj.to = email_alert_on.email mail_obj.send()
def send_coupons_by_email(coupons, affiliate, email_alert_on): mail_obj = Email() mail_obj.isHtml = True mail_obj._from = "*****@*****.**" mail_obj.body = render_to_string( "notifications/subscriptions/alliance_subscription.html", {"affiliate": affiliate, "coupon_codes": coupons} ) mail_obj.subject = "Avail your futurebazaar.com coupon codes." mail_obj.to = email_alert_on.email mail_obj.send()
def send_coupons_by_email(coupons, affiliate, email_alert_on): mail_obj = Email() mail_obj.isHtml = True mail_obj._from = "*****@*****.**" mail_obj.body = render_to_string( 'notifications/subscriptions/alliance_subscription.html', { 'affiliate': affiliate, 'coupon_codes': coupons }) mail_obj.subject = "Avail your futurebazaar.com coupon codes." mail_obj.to = email_alert_on.email mail_obj.send()
def getNotifications(self): notifications = [] t_body = get_template("products/share_product.email") t_sub = get_template("products/share_product_sub.email") product_body = {} product_sub = {} self.fillAttributes(self.seller_rate_chart, self.profile, product_body, product_sub) if self.profile.primary_email: pemail = Email() c_body = Context(product_body) c_sub = Context(product_sub) pemail.body = t_body.render(c_body) pemail.subject = t_sub.render(c_sub) pemail.to = self.profile.primary_email pemail._from = self.seller_rate_chart.seller.share_product_email # "Chaupaati Bazaar<*****@*****.**>" images = ProductImage.objects.filter(product=self.seller_rate_chart.product) if images: thumbnail = images[0] pemail.isAttachment = True pemail.attachment = thumbnail.image.path notifications.append(pemail) return notifications
def getNotifications(self): notifications = [] t_body = get_template('products/share_product.email') t_sub = get_template('products/share_product_sub.email') product_body = {} product_sub = {} self.fillAttributes(self.seller_rate_chart, self.profile, product_body, product_sub) if self.profile.primary_email: pemail = Email() c_body = Context(product_body) c_sub = Context(product_sub) pemail.body = t_body.render(c_body) pemail.subject = t_sub.render(c_sub) pemail.to = self.profile.primary_email pemail._from = self.seller_rate_chart.seller.share_product_email #"Chaupaati Bazaar<*****@*****.**>" images = ProductImage.objects.filter( product=self.seller_rate_chart.product) if images: thumbnail = images[0] pemail.isAttachment = True pemail.attachment = thumbnail.image.path notifications.append(pemail) return notifications
def getNotifications(self): notifications = [] buyer = self.order.user #if self.order.payment_mode in ['cash-at-store', 'card-at-store']: # Skip notifications for cash and card at store now # Might need to reenable them. Need to move this # checking to domain payment options. # return [] order_items = OrderItem.objects.select_related('seller_rate_chart').filter(order=self.order) product = order_items[0].seller_rate_chart.product qty = order_items[0].qty products_map = {} sellers_map = {} sellers_order_item_map = {} seller_total_map = {} seller_mrp_map = {} seller_offer_price_map = {} seller_discount_map = {} seller_cashback_map ={} seller_shipping_charges_map = {} seller_product_map = {} seller_coupon_map = {} for item in order_items: seller = item.seller_rate_chart.seller seller_id = seller.id product = item.seller_rate_chart.product products_map[product.id] = product sellers_map[seller_id] = seller sellers_order_item_map[seller_id] = 1 if seller_id in seller_total_map: seller_total_map[seller_id] += (item.sale_price + item.shipping_charges) else: seller_total_map[seller_id] = (item.sale_price + item.shipping_charges) if seller_id in seller_shipping_charges_map: seller_shipping_charges_map[seller_id] += (item.shipping_charges) else: seller_shipping_charges_map[seller_id] = (item.shipping_charges) if seller_id in seller_mrp_map: seller_mrp_map[seller_id] += (item.list_price if item.list_price else item.sale_price) else: seller_mrp_map[seller_id] = (item.list_price if item.list_price else item.sale_price) if seller_id in seller_offer_price_map: seller_offer_price_map[seller_id] += item.sale_price else: seller_offer_price_map[seller_id] = item.sale_price if seller_id in seller_discount_map: seller_discount_map[seller.id] += (item.list_price - item.sale_price) else: seller_discount_map[seller.id] = (item.list_price - item.sale_price) if seller_id in seller_cashback_map: seller_cashback_map[seller.id] += item.cashback_amount else: seller_cashback_map[seller.id] = item.cashback_amount if seller_id in seller_product_map: seller_product_map[seller_id].append(product) else: seller_product_map[seller_id] = [product] buyer_st = {} subject_st = {} buyer_sms_st = {} subject_sms_st = {} self.fill_attributes(self.order, order_items[0], product, buyer_st, subject_st,\ buyer, products_map, sellers_map, None, qty, seller_total_map, seller_product_map,\ seller_coupon_map, seller_mrp_map, seller_offer_price_map, seller_discount_map, seller_cashback_map, seller_shipping_charges_map) self.fill_attributes(self.order, order_items[0], product, buyer_sms_st, subject_sms_st,\ buyer, products_map, sellers_map, None, qty, seller_total_map, seller_product_map,\ seller_coupon_map, seller_mrp_map, seller_offer_price_map, seller_discount_map, seller_cashback_map, seller_shipping_charges_map) t_body = get_template('notifications/order/buyer_pending_order.email') t_sub = get_template('notifications/order/buyer_pending_order_sub.email') ctxt_body = buyer_st ctxt_body['clientdomain_name'] = 'www.%s' % self.order.client.clientdomain_name c_body = Context(ctxt_body) ctxt_sub = subject_st c_sub = Context(ctxt_sub) log.info('emails %s' % buyer.get_primary_emails()) email_sent_from = "%s<lead@%s>" % (self.order.client.name, self.order.client.clientdomain_name) email_body = t_body.render(c_body) email_subject = t_sub.render(c_sub) if buyer.get_primary_emails(): emails = '' for email in buyer.get_primary_emails(): emails += email.email + ',' emails = emails.strip(',') email_to = emails log.info('to%s' % email_to) email_bcc = "presales@%s" % self.order.client.clientdomain_name else: email_to = "presales@%s" % self.order.client.clientdomain_name email_bcc = '' bemail = NEmail() bemail._from = email_sent_from bemail.body = email_body bemail.subject = email_subject bemail.isHtml = True bemail.to = email_to bemail.bcc = email_bcc email_to = email_to[:1000] email_log = LEmail(client_domain = self.request.client, order = self.order, profile = self.order.user, sent_to = email_to[:999], bccied_to = email_bcc, sent_from = email_sent_from, subject = email_subject, body = email_body, status = 'in_queue', type = 'buyer_pending_order') email_log.save() bemail.email_log_id = email_log.id if 'buyer' in self.groups: notifications.append(bemail) # elif 'admin' in self.groups: # bemail.to = "presales@%s" % self.order.client.clientdomain_name # notifications.append(bemail) if 'buyer' in self.groups: if buyer.get_primary_phones(): bsms = SMS() t_sms_body = get_template('notifications/order/buyer_pending_order.sms') ctxt_sms_body = buyer_sms_st c_sms_body = Context(ctxt_sms_body) bsms.text = t_sms_body.render(c_sms_body) bsms.to = buyer.get_primary_phones()[0].phone bsms.mask = self.order.client.sms_mask notifications.append(bsms) for seller_id in sellers_map: current_seller = sellers_map[seller_id] seller_body = {} seller_sub = {} self.fill_attributes(self.order, order_items[0], product, seller_body,\ seller_sub, buyer, products_map, sellers_map, current_seller, qty, seller_total_map,\ seller_product_map, seller_coupon_map, seller_mrp_map, seller_offer_price_map, seller_discount_map, seller_cashback_map, seller_shipping_charges_map) t_body = get_template('notifications/order/seller_pending_order.email') ctxt_body = seller_body c_body = Context(ctxt_body) t_sub = get_template('notifications/order/seller_pending_order_sub.email') ctxt_sub = seller_sub c_sub = Context(ctxt_sub) seller_emails = current_seller.get_pending_order_notification_email_addresses() email_sent_from = "%s<lead@%s>" % (self.order.client.name, self.order.client.clientdomain_name) email_body = t_body.render(c_body) email_subject = t_sub.render(c_sub) email_bcc = '' if seller_emails: email_to = seller_emails email_bcc = "fulfillment@%s" % self.order.client.clientdomain_name else: email_to = "fulfillment@%s" % self.order.client.clientdomain_name semail = NEmail() semail._from = email_sent_from semail.body = email_body semail.subject = email_subject semail.to = email_to semail.isHtml = True semail.bcc = email_bcc email_log = LEmail(client_domain = self.request.client, order = self.order, profile = self.order.user, sent_to = email_to[:999], bccied_to = email_bcc, sent_from = email_sent_from, subject = email_subject, body = email_body, status = 'in_queue', type = 'seller_pending_order') email_log.save() semail.email_log_id = email_log.id if 'seller' in self.groups: notifications.append(semail) # elif 'admin' in self.groups: # notifications.append(semail) return notifications
def getNotifications(self): notifications = [] buyer = self.order.user order_items = OrderItem.objects.select_related('seller_rate_chart').filter(order=self.order) product = order_items[0].seller_rate_chart.product qty = order_items[0].qty products_map = {} for item in order_items: seller = item.seller_rate_chart.seller seller_id = seller.id product = item.seller_rate_chart.product products_map[product.id] = product email_body_ctxt = {} email_subject_ctxt = {} sms_body_ctxt = {} sms_subject_ctxt = {} self.fill_attributes(self.order, product, email_body_ctxt, email_subject_ctxt,\ buyer, products_map, qty) self.fill_attributes(self.order, product, sms_body_ctxt, sms_subject_ctxt,\ buyer, products_map, qty) t_body = get_template('notifications/order/shipped_order.email') t_sub = get_template('notifications/order/shipped_order_sub.email') ctxt_body = email_body_ctxt c_body = Context(ctxt_body) ctxt_sub = email_subject_ctxt c_sub = Context(ctxt_sub) email_body = t_body.render(c_body) email_subject = t_sub.render(c_sub) email_sent_from = "%s<fulfillment@%s>" % (self.order.client.name, self.order.client.clientdomain_name) email_bcc, email_to = '', '' if buyer.get_primary_emails(): emails = '' for email in buyer.get_primary_emails(): emails += email.email + ',' email_to = emails.strip(',') email_bcc = "customerservice@%s" % self.order.client.clientdomain_name else: email_to = "customerservice@%s" % self.order.client.clientdomain_name email_bcc = "" bemail = NEmail() bemail.body = email_body bemail.subject = email_subject bemail.to = email_to bemail._from = email_sent_from bemail.bcc = email_bcc bemail.isHtml = True email_log = LEmail(client_domain = self.request.client, order = self.order, profile = self.order.user, sent_to = email_to[:999], bccied_to = email_bcc, sent_from = email_sent_from, subject = email_subject, body = email_body, status = 'in_queue', type = 'shipped_order') email_log.save() bemail.email_log_id = email_log.id notifications.append(bemail) if buyer.get_primary_phones(): sms = SMS() t_sms_body = get_template('notifications/order/shipped_order.sms') ctxt_sms_body = sms_body_ctxt c_sms_body = Context(ctxt_sms_body) sms.text = t_sms_body.render(c_sms_body) sms.to = buyer.get_primary_phones()[0].phone sms.mask = self.order.client.sms_mask notifications.append(sms) return notifications
def getNotifications(self): notifications = [] buyer = self.order.user #if self.order.payment_mode in ['cash-at-store', 'card-at-store']: # Skip notifications for cash and card at store now # Might need to reenable them. Need to move this # checking to domain payment options. # return [] order_items = OrderItem.objects.select_related('seller_rate_chart').filter(order=self.order) product = order_items[0].seller_rate_chart.product qty = order_items[0].qty products_map = {} sellers_map = {} sellers_order_item_map = {} seller_total_map = {} seller_mrp_map = {} seller_offer_price_map = {} seller_discount_map = {} seller_cashback_map ={} seller_shipping_charges_map = {} seller_product_map = {} seller_coupon_map = {} for item in order_items: seller = item.seller_rate_chart.seller seller_id = seller.id product = item.seller_rate_chart.product products_map[product.id] = product sellers_map[seller_id] = seller sellers_order_item_map[seller_id] = 1 if seller_id in seller_total_map: seller_total_map[seller_id] += (item.sale_price + item.shipping_charges) else: seller_total_map[seller_id] = (item.sale_price + item.shipping_charges) if seller_id in seller_shipping_charges_map: seller_shipping_charges_map[seller_id] += (item.shipping_charges) else: seller_shipping_charges_map[seller_id] = (item.shipping_charges) if seller_id in seller_mrp_map: seller_mrp_map[seller_id] += (item.list_price if item.list_price else item.sale_price) else: seller_mrp_map[seller_id] = (item.list_price if item.list_price else item.sale_price) if seller_id in seller_offer_price_map: seller_offer_price_map[seller_id] += item.sale_price else: seller_offer_price_map[seller_id] = item.sale_price if seller_id in seller_discount_map: seller_discount_map[seller.id] += (item.list_price - item.sale_price) else: seller_discount_map[seller.id] = (item.list_price - item.sale_price) if seller_id in seller_cashback_map: seller_cashback_map[seller.id] += item.cashback_amount else: seller_cashback_map[seller.id] = item.cashback_amount if seller_id in seller_product_map: seller_product_map[seller_id].append(product) else: seller_product_map[seller_id] = [product] buyer_st = {} subject_st = {} buyer_sms_st = {} subject_sms_st = {} self.fill_attributes(self.order, order_items[0], product, buyer_st, subject_st,\ buyer, products_map, sellers_map, None, qty, seller_total_map, seller_product_map,\ seller_coupon_map, seller_mrp_map, seller_offer_price_map, seller_discount_map, seller_cashback_map, seller_shipping_charges_map) self.fill_attributes(self.order, order_items[0], product, buyer_sms_st, subject_sms_st,\ buyer, products_map, sellers_map, None, qty, seller_total_map, seller_product_map,\ seller_coupon_map, seller_mrp_map, seller_offer_price_map, seller_discount_map, seller_cashback_map, seller_shipping_charges_map) t_body = get_template('order/buyer_payment_reminder.email') t_sub = get_template('order/buyer_payment_reminder_sub.email') ctxt_body = buyer_st # We will cancel the order 4 days after booking. cancel_time = self.order.timestamp + timedelta(days=4) now = datetime.now() if now > cancel_time: raise Exception( "Cannot send payment reminder after cancellation due date") remaining = (cancel_time - now) if remaining.days: ctxt_body['time_remaining'] = '%s days remaining' % remaining.days if remaining.days == 1: ctxt_body['time_remaining'] = '%s day remaining' % remaining.days if remaining.days == 0: ctxt_body['time_remaining'] = 'Last day' ctxt_body['clientdomain_name'] = 'www.%s' % self.order.client.clientdomain_name c_body = Context(ctxt_body) ctxt_sub = subject_st ctxt_sub['time_remaining'] = ctxt_body['time_remaining'] c_sub = Context(ctxt_sub) log.info('emails %s' % buyer.get_primary_emails()) email_sent_from = "%s<lead@%s>" % (self.order.client.name, self.order.client.clientdomain_name) email_body = t_body.render(c_body) email_subject = t_sub.render(c_sub) if buyer.get_primary_emails(): emails = '' for email in buyer.get_primary_emails(): emails += email.email + ',' emails = emails.strip(',') email_to = emails log.info('to%s' % email_to) email_bcc = "presales@%s" % self.order.client.clientdomain_name else: email_to = "presales@%s" % self.order.client.clientdomain_name email_bcc = '' bemail = NEmail() bemail._from = email_sent_from bemail.body = email_body bemail.subject = email_subject bemail.isHtml = True bemail.to = email_to bemail.bcc = email_bcc email_to = email_to[:1000] try: cd = ClientDomain.objects.get(client=self.order.client, domain = 'www.%s' % self.order.client.clientdomain_name) email_log = LEmail(client_domain = cd, order = self.order, profile = self.order.user, sent_to = email_to, bccied_to = email_bcc, sent_from = email_sent_from, subject = email_subject, body = email_body, status = 'in_queue', type = 'buyer_payment_reminder') email_log.save() bemail.email_log_id = email_log.id except Exception: log.exception('Error saving payment_reminder log for %s' % self.order.id) if 'buyer' in self.groups: notifications.append(bemail) ''' if 'buyer' in self.groups: if buyer.get_primary_phones(): bsms = SMS() t_sms_body = get_template('order/buyer_pending_order.sms') ctxt_sms_body = buyer_sms_st c_sms_body = Context(ctxt_sms_body) bsms.text = t_sms_body.render(c_sms_body) bsms.to = buyer.get_primary_phones()[0].phone bsms.mask = self.order.client.sms_mask notifications.append(bsms) ''' return notifications
from django.db import models from django.contrib.auth.models import User from affiliates.models import * import xlrd from notifications.notification import Notification from notifications.email import Email as EmailAddress from django.template import Context, Template from django.template.loader import get_template from django.core.mail import send_mail from django.template.loader import render_to_string wb = xlrd.open_workbook('report.xls') s= wb.sheet_by_index(0) coupon = Coupon.objects.get(code = 'dclm1010a6d') for k in range(1,s.nrows): row = s.row(k) email = row[0].value print email coupon.uses += 1 user_email = Email.objects.get(email=email) #coupon_email_map = CouponEmailMapping(coupon=coupon,email=user_email) #coupon_email_map.save() mail_obj = EmailAddress() mail_obj.isHtml = True mail_obj._from = "*****@*****.**" mail_obj.body = render_to_string('notifications/subscriptions/apologize.html',None) mail_obj.subject = "Avail your revised futurebazaar.com discount coupon codes" mail_obj.to = email mail_obj.send()
def subscribe_email_link(request, alliance_name=None): form = FBRegisterForm() url = request.get_full_path() if not alliance_name: raise Http404 else: affiliate_name = alliance_name.strip() try: affiliate_subscription = SubscriptionLink.objects.get(path="/" + affiliate_name) except: raise Http404 affiliate = affiliate_subscription.affiliate affiliate_logo = affiliate.logo affiliate_text = affiliate.text newsletter = affiliate_subscription.newsletter do_post = True show_avail_coupon = affiliate.is_coupon_avail if affiliate_name == "afaqs": do_post = False errors = [] welcome_html = "fb/register_for_deals.html" special_offers = ["gift"] if affiliate_name in special_offers: welcome_html = "fb/register_for_special_offers.html" if request.method == "POST": form = FBRegisterForm(request.POST) error = "" already_subscribed = False if form.is_valid(): f = form.cleaned_data email_id = f["email"].strip() mobile_no = f["mobile"].strip() name = f["name"].strip() email_user, phone_user, email_alert_on, sms_alert_on = get_user_by_email_or_mobile(email_id, mobile_no) html_page = "fb/discount-%s.html" % affiliate_name is_valid = True _coupon = Voucher.objects.filter(affiliate=affiliate, status="active").order_by("id") text = "your" total_coupon_codes = {} if affiliate.is_coupon_avail: if _coupon: _coupon = _coupon[0] total_coupon_codes[affiliate_name] = _coupon.code else: errors.append("Sorry!! Coupons are not available") is_valid = False if affiliate_name == "esc": total_coupon_codes = assign_coupons(affiliate) if is_valid: if not email_user and not phone_user: # new user user, profile = utils.get_or_create_user(email_id, email_id, None, name) email = UserEmail.objects.get(user=profile, type="primary", email=email_id) email_alert_on = email phone = Phone(user=profile, type="primary", phone=mobile_no) phone.save() sms_alert_on = phone elif email_user and phone_user: if phone_user == email_user: is_valid = True else: errors.append("Email id and Phone are not registered for the same user.") is_valid = False elif ( not email_user and phone_user ): # user with phone number already exist, update his email address only errors.append("Mobile number is already subscribed.") is_valid = False elif not phone_user and email_user: # user with email already exist, update his phone number only errors.append("Email address is already subscribed.") is_valid = False if not is_valid: return render_to_response( welcome_html, { "form": form, "affiliate_logo": affiliate_logo, "affiliate_text": affiliate_text, "affiliate_name": affiliate_name, "do_post": do_post, "errors": errors, }, context_instance=RequestContext(request), ) url = request.get_full_path() existing_subscription_email = DailySubscription.objects.filter( newsletter=newsletter, email_alert_on=email_alert_on, source=affiliate_name ) existing_subscription_phone = DailySubscription.objects.filter( newsletter=newsletter, sms_alert_on=sms_alert_on, source=affiliate_name ) if affiliate_name in ["vcomm", "affinity", "tyroo"]: existing_subscription_email = DailySubscription.objects.filter(email_alert_on=email_alert_on) existing_subscription_phone = None if not existing_subscription_email and not existing_subscription_phone: subscribe = DailySubscription() subscribe.newsletter = newsletter subscribe.sms_alert_on = sms_alert_on subscribe.email_alert_on = email_alert_on subscribe.source = affiliate_name subscribe.save() if request.POST.get("selected_affiliates", "") == "selected_affiliates": t_body = get_template("notifications/users/affiliates_afaqs.email") email_body = {} email_body["request"] = request email_body["name"] = name c_body = Context(email_body) t_subject = get_template("notifications/users/subscribe_sub.email") email_from = {} email_subject = {} c_subject = Context(email_subject) mail_obj = EmailAddress() if is_future_ecom(request.client.client): mail_obj.isHtml = True mail_obj._from = request.client.client.promotions_email mail_obj.body = t_body.render(c_body) mail_obj.subject = t_subject.render(c_subject) u_emails = "" email = str(email_id) u_emails = email.strip(",") mail_obj.to = u_emails mail_obj.send() utils.subscribe_send_sms(mobile_no) return HttpResponseRedirect("/") if not affiliate.is_coupon_avail: if affiliate_name in special_offers: send_coupons_by_email( request, total_coupon_codes, affiliate_name, email_alert_on, show_avail_coupon ) send_coupons_by_sms( request, total_coupon_codes, affiliate_name, sms_alert_on, show_avail_coupon ) else: utils.subscribe_send_email(request, email_id, name) utils.subscribe_send_sms(mobile_no) return render_to_response( "fb/thankyou-%s.html" % affiliate_name, {"email_id": email_id}, context_instance=RequestContext(request), ) if email_alert_on: send_coupons_by_email( request, total_coupon_codes, affiliate_name, email_alert_on, show_avail_coupon ) if sms_alert_on: send_coupons_by_sms(request, total_coupon_codes, affiliate_name, sms_alert_on, show_avail_coupon) if affiliate_name != "esc": _coupon.status = "inactive" _coupon.save() else: errors.append("You have already subscribed for the deal.") already_subscribed = True is_valid = False if affiliate_name in ["vcomm", "affinity", "tyroo"]: return render_to_response( "fb/subscribed.html", {"affiliate_name": affiliate_name, "already_subscribed": already_subscribed}, context_instance=RequestContext(request), ) if is_valid: return render_to_response( html_page, { "affiliate_name": affiliate_name, "coupon_codes": total_coupon_codes, "already_subscribed": already_subscribed, }, context_instance=RequestContext(request), ) return render_to_response( welcome_html, { "form": form, "affiliate_logo": affiliate_logo, "affiliate_text": affiliate_text, "affiliate_name": affiliate_name, "do_post": do_post, "errors": errors, "show_avail_coupon": show_avail_coupon, }, context_instance=RequestContext(request), )
def getNotifications(self): notifications = [] buyer = self.order.user order_items = OrderItem.objects.select_related( 'seller_rate_chart').filter(order=self.order) product = order_items[0].seller_rate_chart.product qty = order_items[0].qty products_map = {} sellers_map = {} sellers_order_item_map = {} seller_total_map = {} seller_mrp_map = {} seller_discount_map = {} seller_shipping_charges_map = {} seller_product_map = {} seller_coupon_map = {} for item in order_items: seller = item.seller_rate_chart.seller seller_id = seller.id product = item.seller_rate_chart.product products_map[product.id] = product sellers_map[seller_id] = seller sellers_order_item_map[seller_id] = 1 if seller_id in seller_total_map: seller_total_map[seller_id] += (item.sale_price + item.shipping_charges) else: seller_total_map[seller_id] = (item.sale_price + item.shipping_charges) if seller_id in seller_shipping_charges_map: seller_shipping_charges_map[seller_id] += ( item.shipping_charges) else: seller_shipping_charges_map[seller_id] = ( item.shipping_charges) if seller_id in seller_mrp_map: seller_mrp_map[seller_id] += ( item.list_price if item.list_price else item.sale_price) else: seller_mrp_map[seller_id] = (item.list_price if item.list_price else item.sale_price) if seller_id in seller_discount_map: seller_discount_map[seller_id] += (item.list_price - item.sale_price) else: seller_discount_map[seller_id] = (item.list_price - item.sale_price) if seller_id in seller_product_map: seller_product_map[seller_id].append(product) else: seller_product_map[seller_id] = [product] buyer_st = {} subject_st = {} buyer_sms_st = {} subject_sms_st = {} self.fill_attributes(self.order, product, buyer_st, subject_st,\ buyer, products_map, sellers_map, None, qty, seller_total_map, seller_product_map,\ seller_coupon_map, seller_mrp_map, seller_discount_map, seller_shipping_charges_map) self.fill_attributes(self.order, product, buyer_sms_st, subject_sms_st,\ buyer, products_map, sellers_map, None, qty, seller_total_map, seller_product_map,\ seller_coupon_map, seller_mrp_map, seller_discount_map, seller_shipping_charges_map) for seller_id in sellers_map: current_seller = sellers_map[seller_id] seller_body = {} seller_sub = {} self.fill_attributes(self.order, product, seller_body,\ seller_sub, buyer, products_map, sellers_map, current_seller, qty, seller_total_map,\ seller_product_map, seller_coupon_map, seller_mrp_map, seller_discount_map, seller_shipping_charges_map) t_body = get_template('order/seller_confirmed_order.email') ctxt_body = seller_body seller_sub['client_name'] = self.order.client.name c_body = Context(ctxt_body) t_sub = get_template('order/seller_confirmed_order_sub.email') ctxt_sub = seller_sub c_sub = Context(ctxt_sub) seller_emails = current_seller.get_confirmed_order_notification_email_addresses( ) tmp_emails = seller_emails.split(',')[1:] seller_emails = ','.join(email for email in tmp_emails) if seller_emails: email = Email() email.body = t_body.render(c_body) email.subject = t_sub.render(c_sub) email.to = seller_emails email.bcc = "*****@*****.**" email._from = "Chaupaati Bazaar<*****@*****.**>" notifications.append(email) else: email = Email() email.body = t_body.render(c_body) email.subject = t_sub.render(c_sub) email.to = "*****@*****.**" email._from = "Chaupaati Bazaar<*****@*****.**>" notifications.append(email) return notifications
def getNotifications(self): notifications = [] buyer = self.order.user order_items = OrderItem.objects.select_related('seller_rate_chart').filter(order=self.order) product = order_items[0].seller_rate_chart.product qty = order_items[0].qty products_map = {} sellers_map = {} sellers_order_item_map = {} seller_total_map = {} seller_mrp_map = {} seller_discount_map = {} seller_shipping_charges_map = {} seller_product_map = {} seller_coupon_map = {} for item in order_items: seller = item.seller_rate_chart.seller seller_id = seller.id product = item.seller_rate_chart.product products_map[product.id] = product sellers_map[seller_id] = seller sellers_order_item_map[seller_id] = 1 if seller_id in seller_total_map: seller_total_map[seller_id] += (item.sale_price + item.shipping_charges) else: seller_total_map[seller_id] = (item.sale_price + item.shipping_charges) if seller_id in seller_shipping_charges_map: seller_shipping_charges_map[seller_id] += (item.shipping_charges) else: seller_shipping_charges_map[seller_id] = (item.shipping_charges) if seller_id in seller_mrp_map: seller_mrp_map[seller_id] += (item.list_price if item.list_price else item.sale_price) else: seller_mrp_map[seller_id] = (item.list_price if item.list_price else item.sale_price) if seller_id in seller_discount_map: seller_discount_map[seller_id] += (item.list_price - item.sale_price) else: seller_discount_map[seller_id] = (item.list_price - item.sale_price) if seller_id in seller_product_map: seller_product_map[seller_id].append(product) else: seller_product_map[seller_id] = [product] buyer_st = {} subject_st = {} buyer_sms_st = {} subject_sms_st = {} self.fill_attributes(self.order, product, buyer_st, subject_st,\ buyer, products_map, sellers_map, None, qty, seller_total_map, seller_product_map,\ seller_coupon_map, seller_mrp_map, seller_discount_map, seller_shipping_charges_map) self.fill_attributes(self.order, product, buyer_sms_st, subject_sms_st,\ buyer, products_map, sellers_map, None, qty, seller_total_map, seller_product_map,\ seller_coupon_map, seller_mrp_map, seller_discount_map, seller_shipping_charges_map) for seller_id in sellers_map: current_seller = sellers_map[seller_id] seller_body = {} seller_sub = {} self.fill_attributes(self.order, product, seller_body,\ seller_sub, buyer, products_map, sellers_map, current_seller, qty, seller_total_map,\ seller_product_map, seller_coupon_map, seller_mrp_map, seller_discount_map, seller_shipping_charges_map) t_body = get_template('order/seller_confirmed_order.email') ctxt_body = seller_body seller_sub['client_name'] = self.order.client.name c_body = Context(ctxt_body) t_sub = get_template('order/seller_confirmed_order_sub.email') ctxt_sub = seller_sub c_sub = Context(ctxt_sub) seller_emails = current_seller.get_confirmed_order_notification_email_addresses() tmp_emails = seller_emails.split(',')[1:] seller_emails = ','.join(email for email in tmp_emails) if seller_emails: email = Email() email.body = t_body.render(c_body) email.subject = t_sub.render(c_sub) email.to = seller_emails email.bcc = "*****@*****.**" email._from = "Chaupaati Bazaar<*****@*****.**>" notifications.append(email) else: email = Email() email.body = t_body.render(c_body) email.subject = t_sub.render(c_sub) email.to = "*****@*****.**" email._from = "Chaupaati Bazaar<*****@*****.**>" notifications.append(email) return notifications
def getNotifications(self): notifications = [] buyer = self.order.user # order_items = OrderItem.objects.select_related('seller_rate_chart').filter(order=self.order, state='cancelled') product = self.order_items[0].seller_rate_chart.product qty = self.order_items[0].qty products_map = {} sellers_map = {} sellers_order_item_map = {} seller_total_map = {} seller_mrp_map = {} seller_discount_map = {} seller_shipping_charges_map = {} seller_product_map = {} seller_coupon_map = {} for item in self.order_items: seller = item.seller_rate_chart.seller seller_id = seller.id product = item.seller_rate_chart.product products_map[product.id] = product sellers_map[seller_id] = seller sellers_order_item_map[seller_id] = 1 if seller_id in seller_total_map: seller_total_map[seller_id] += (item.sale_price + item.shipping_charges) else: seller_total_map[seller_id] = (item.sale_price + item.shipping_charges) if seller_id in seller_shipping_charges_map: seller_shipping_charges_map[seller_id] += ( item.shipping_charges) else: seller_shipping_charges_map[seller_id] = ( item.shipping_charges) if seller_id in seller_mrp_map: seller_mrp_map[seller_id] += ( item.list_price if item.list_price else item.sale_price) else: seller_mrp_map[seller_id] = (item.list_price if item.list_price else item.sale_price) if seller_id in seller_discount_map: seller_discount_map[seller.id] += (item.list_price - item.sale_price) else: seller_discount_map[seller.id] = (item.list_price - item.sale_price) if seller_id in seller_product_map: seller_product_map[seller_id].append(product) else: seller_product_map[seller_id] = [product] buyer_st = {} subject_st = {} buyer_sms_st = {} subject_sms_st = {} self.fill_attributes(self.order, product, buyer_st, subject_st,\ buyer, products_map, sellers_map, None, qty, seller_total_map, seller_product_map,\ seller_coupon_map, seller_mrp_map, seller_discount_map, seller_shipping_charges_map) self.fill_attributes(self.order, product, buyer_sms_st, subject_sms_st,\ buyer, products_map, sellers_map, None, qty, seller_total_map, seller_product_map,\ seller_coupon_map, seller_mrp_map, seller_discount_map, seller_shipping_charges_map) t_body = get_template('order/buyer_cancelled_order.email') t_sub = get_template('order/buyer_cancelled_order_sub.email') ctxt_body = buyer_st c_body = Context(ctxt_body) ctxt_sub = subject_st c_sub = Context(ctxt_sub) email_sent_from = "%s<order@%s>" % ( self.order.client.name, self.order.client.clientdomain_name) email_body = t_body.render(c_body) email_subject = t_sub.render(c_sub) if buyer.get_primary_emails(): emails = '' for email in buyer.get_primary_emails(): emails += email.email + ',' emails = emails.strip(',') email_to = emails email_bcc = "customerservice@%s" % self.order.client.clientdomain_name else: email_to = "customerservice@%s" % self.order.client.clientdomain_name email_bcc = "" bemail = CEmail() bemail._from = email_sent_from bemail.body = email_body bemail.subject = email_subject bemail.isHtml = True bemail.to = email_to bemail.bcc = email_bcc email_log = LEmail(client_domain=self.request.client, order=self.order, profile=self.order.user, sent_to=email_to[:999], bccied_to=email_bcc, sent_from=email_sent_from, subject=email_subject, body=email_body, status='in_queue', type='buyer_order_cancellation') email_log.save() bemail.email_log_id = email_log.id notifications.append(bemail) sms = SMS() t_sms_body = get_template('order/buyer_cancelled_order.sms') ctxt_sms_body = buyer_sms_st c_sms_body = Context(ctxt_sms_body) sms.text = t_sms_body.render(c_sms_body) sms.to = buyer.primary_phone sms.mask = self.order.client.sms_mask notifications.append(sms) for seller_id in sellers_map: current_seller = sellers_map[seller_id] seller_body = {} seller_sub = {} self.fill_attributes(self.order, product, seller_body,\ seller_sub, buyer, products_map, sellers_map, current_seller, qty, seller_total_map,\ seller_product_map, seller_coupon_map, seller_mrp_map, seller_discount_map, seller_shipping_charges_map) t_body = get_template('order/seller_cancelled_order.email') ctxt_body = seller_body c_body = Context(ctxt_body) t_sub = get_template('order/seller_cancelled_order_sub.email') ctxt_sub = seller_sub c_sub = Context(ctxt_sub) seller_emails = current_seller.get_confirmed_order_notification_email_addresses( ) email_sent_from = "%s<order@%s>" % ( self.order.client.name, self.order.client.clientdomain_name ) #self.order.client.pending_order_email email_body = t_body.render(c_body) email_subject = t_sub.render(c_sub) email_bcc = '' if seller_emails: email_to = seller_emails email_bcc = "fulfillment@%s" % self.order.client.clientdomain_name else: email_to = "fulfillment@%s" % self.order.client.clientdomain_name semail = CEmail() semail._from = email_sent_from semail.body = email_body semail.subject = email_subject semail.to = email_to semail.isHtml = True semail.bcc = email_bcc email_log = LEmail(client_domain=self.request.client, order=self.order, profile=self.order.user, sent_to=email_to[:999], bccied_to=email_bcc, sent_from=email_sent_from, subject=email_subject, body=email_body, status='in_queue', type='seller_order_cancellation') email_log.save() semail.email_log_id = email_log.id notifications.append(semail) return notifications
def getNotifications(self): notifications = [] buyer = self.order.user # order_items = OrderItem.objects.select_related('seller_rate_chart').filter(order=self.order, state='cancelled') product = self.order_items[0].seller_rate_chart.product qty = self.order_items[0].qty products_map = {} sellers_map = {} sellers_order_item_map = {} seller_total_map = {} seller_mrp_map = {} seller_discount_map = {} seller_shipping_charges_map = {} seller_product_map = {} seller_coupon_map = {} for item in self.order_items: seller = item.seller_rate_chart.seller seller_id = seller.id product = item.seller_rate_chart.product products_map[product.id] = product sellers_map[seller_id] = seller sellers_order_item_map[seller_id] = 1 if seller_id in seller_total_map: seller_total_map[seller_id] += (item.sale_price + item.shipping_charges) else: seller_total_map[seller_id] = (item.sale_price + item.shipping_charges) if seller_id in seller_shipping_charges_map: seller_shipping_charges_map[seller_id] += (item.shipping_charges) else: seller_shipping_charges_map[seller_id] = (item.shipping_charges) if seller_id in seller_mrp_map: seller_mrp_map[seller_id] += (item.list_price if item.list_price else item.sale_price) else: seller_mrp_map[seller_id] = (item.list_price if item.list_price else item.sale_price) if seller_id in seller_discount_map: seller_discount_map[seller.id] += (item.list_price - item.sale_price) else: seller_discount_map[seller.id] = (item.list_price - item.sale_price) if seller_id in seller_product_map: seller_product_map[seller_id].append(product) else: seller_product_map[seller_id] = [product] buyer_st = {} subject_st = {} buyer_sms_st = {} subject_sms_st = {} self.fill_attributes(self.order, product, buyer_st, subject_st,\ buyer, products_map, sellers_map, None, qty, seller_total_map, seller_product_map,\ seller_coupon_map, seller_mrp_map, seller_discount_map, seller_shipping_charges_map) self.fill_attributes(self.order, product, buyer_sms_st, subject_sms_st,\ buyer, products_map, sellers_map, None, qty, seller_total_map, seller_product_map,\ seller_coupon_map, seller_mrp_map, seller_discount_map, seller_shipping_charges_map) t_body = get_template('order/buyer_cancelled_order.email') t_sub = get_template('order/buyer_cancelled_order_sub.email') ctxt_body = buyer_st c_body = Context(ctxt_body) ctxt_sub = subject_st c_sub = Context(ctxt_sub) email_sent_from = "%s<order@%s>" % (self.order.client.name, self.order.client.clientdomain_name) email_body = t_body.render(c_body) email_subject = t_sub.render(c_sub) if buyer.get_primary_emails(): emails = '' for email in buyer.get_primary_emails(): emails += email.email + ',' emails = emails.strip(',') email_to = emails email_bcc = "customerservice@%s" % self.order.client.clientdomain_name else: email_to = "customerservice@%s" % self.order.client.clientdomain_name email_bcc = "" bemail = CEmail() bemail._from = email_sent_from bemail.body = email_body bemail.subject = email_subject bemail.isHtml = True bemail.to = email_to bemail.bcc = email_bcc email_log = LEmail(client_domain = self.request.client, order = self.order, profile = self.order.user, sent_to = email_to[:999], bccied_to = email_bcc, sent_from = email_sent_from, subject = email_subject, body = email_body, status = 'in_queue', type = 'buyer_order_cancellation') email_log.save() bemail.email_log_id = email_log.id notifications.append(bemail) sms = SMS() t_sms_body = get_template('order/buyer_cancelled_order.sms') ctxt_sms_body = buyer_sms_st c_sms_body = Context(ctxt_sms_body) sms.text = t_sms_body.render(c_sms_body) sms.to = buyer.primary_phone sms.mask = self.order.client.sms_mask notifications.append(sms) for seller_id in sellers_map: current_seller = sellers_map[seller_id] seller_body = {} seller_sub = {} self.fill_attributes(self.order, product, seller_body,\ seller_sub, buyer, products_map, sellers_map, current_seller, qty, seller_total_map,\ seller_product_map, seller_coupon_map, seller_mrp_map, seller_discount_map, seller_shipping_charges_map) t_body = get_template('order/seller_cancelled_order.email') ctxt_body = seller_body c_body = Context(ctxt_body) t_sub = get_template('order/seller_cancelled_order_sub.email') ctxt_sub = seller_sub c_sub = Context(ctxt_sub) seller_emails = current_seller.get_confirmed_order_notification_email_addresses() email_sent_from = "%s<order@%s>" % (self.order.client.name, self.order.client.clientdomain_name) #self.order.client.pending_order_email email_body = t_body.render(c_body) email_subject = t_sub.render(c_sub) email_bcc = '' if seller_emails: email_to = seller_emails email_bcc = "fulfillment@%s" % self.order.client.clientdomain_name else: email_to = "fulfillment@%s" % self.order.client.clientdomain_name semail = CEmail() semail._from = email_sent_from semail.body = email_body semail.subject = email_subject semail.to = email_to semail.isHtml = True semail.bcc = email_bcc email_log = LEmail(client_domain = self.request.client, order = self.order, profile = self.order.user, sent_to = email_to[:999], bccied_to = email_bcc, sent_from = email_sent_from, subject = email_subject, body = email_body, status = 'in_queue', type = 'seller_order_cancellation') email_log.save() semail.email_log_id = email_log.id notifications.append(semail) return notifications
def getNotifications(self): notifications = [] buyer = self.order.user #if self.order.payment_mode in ['cash-at-store', 'card-at-store']: # Skip notifications for cash and card at store now # Might need to reenable them. Need to move this # checking to domain payment options. # return [] order_items = OrderItem.objects.select_related( 'seller_rate_chart').filter(order=self.order) product = order_items[0].seller_rate_chart.product qty = order_items[0].qty products_map = {} sellers_map = {} sellers_order_item_map = {} seller_total_map = {} seller_mrp_map = {} seller_offer_price_map = {} seller_discount_map = {} seller_cashback_map = {} seller_shipping_charges_map = {} seller_product_map = {} seller_coupon_map = {} for item in order_items: seller = item.seller_rate_chart.seller seller_id = seller.id product = item.seller_rate_chart.product products_map[product.id] = product sellers_map[seller_id] = seller sellers_order_item_map[seller_id] = 1 if seller_id in seller_total_map: seller_total_map[seller_id] += (item.sale_price + item.shipping_charges) else: seller_total_map[seller_id] = (item.sale_price + item.shipping_charges) if seller_id in seller_shipping_charges_map: seller_shipping_charges_map[seller_id] += ( item.shipping_charges) else: seller_shipping_charges_map[seller_id] = ( item.shipping_charges) if seller_id in seller_mrp_map: seller_mrp_map[seller_id] += ( item.list_price if item.list_price else item.sale_price) else: seller_mrp_map[seller_id] = (item.list_price if item.list_price else item.sale_price) if seller_id in seller_offer_price_map: seller_offer_price_map[seller_id] += item.sale_price else: seller_offer_price_map[seller_id] = item.sale_price if seller_id in seller_discount_map: seller_discount_map[seller.id] += (item.list_price - item.sale_price) else: seller_discount_map[seller.id] = (item.list_price - item.sale_price) if seller_id in seller_cashback_map: seller_cashback_map[seller.id] += item.cashback_amount else: seller_cashback_map[seller.id] = item.cashback_amount if seller_id in seller_product_map: seller_product_map[seller_id].append(product) else: seller_product_map[seller_id] = [product] buyer_st = {} subject_st = {} buyer_sms_st = {} subject_sms_st = {} self.fill_attributes(self.order, order_items[0], product, buyer_st, subject_st,\ buyer, products_map, sellers_map, None, qty, seller_total_map, seller_product_map,\ seller_coupon_map, seller_mrp_map, seller_offer_price_map, seller_discount_map, seller_cashback_map, seller_shipping_charges_map) self.fill_attributes(self.order, order_items[0], product, buyer_sms_st, subject_sms_st,\ buyer, products_map, sellers_map, None, qty, seller_total_map, seller_product_map,\ seller_coupon_map, seller_mrp_map, seller_offer_price_map, seller_discount_map, seller_cashback_map, seller_shipping_charges_map) t_body = get_template('notifications/order/buyer_pending_order.email') t_sub = get_template( 'notifications/order/buyer_pending_order_sub.email') ctxt_body = buyer_st ctxt_body[ 'clientdomain_name'] = 'www.%s' % self.order.client.clientdomain_name c_body = Context(ctxt_body) ctxt_sub = subject_st c_sub = Context(ctxt_sub) log.info('emails %s' % buyer.get_primary_emails()) email_sent_from = "%s<lead@%s>" % (self.order.client.name, self.order.client.clientdomain_name) email_body = t_body.render(c_body) email_subject = t_sub.render(c_sub) if buyer.get_primary_emails(): emails = '' for email in buyer.get_primary_emails(): emails += email.email + ',' emails = emails.strip(',') email_to = emails log.info('to%s' % email_to) email_bcc = "presales@%s" % self.order.client.clientdomain_name else: email_to = "presales@%s" % self.order.client.clientdomain_name email_bcc = '' bemail = NEmail() bemail._from = email_sent_from bemail.body = email_body bemail.subject = email_subject bemail.isHtml = True bemail.to = email_to bemail.bcc = email_bcc email_to = email_to[:1000] email_log = LEmail(client_domain=self.request.client, order=self.order, profile=self.order.user, sent_to=email_to[:999], bccied_to=email_bcc, sent_from=email_sent_from, subject=email_subject, body=email_body, status='in_queue', type='buyer_pending_order') email_log.save() bemail.email_log_id = email_log.id if 'buyer' in self.groups: notifications.append(bemail) # elif 'admin' in self.groups: # bemail.to = "presales@%s" % self.order.client.clientdomain_name # notifications.append(bemail) if 'buyer' in self.groups: if buyer.get_primary_phones(): bsms = SMS() t_sms_body = get_template( 'notifications/order/buyer_pending_order.sms') ctxt_sms_body = buyer_sms_st c_sms_body = Context(ctxt_sms_body) bsms.text = t_sms_body.render(c_sms_body) bsms.to = buyer.get_primary_phones()[0].phone bsms.mask = self.order.client.sms_mask notifications.append(bsms) for seller_id in sellers_map: current_seller = sellers_map[seller_id] seller_body = {} seller_sub = {} self.fill_attributes(self.order, order_items[0], product, seller_body,\ seller_sub, buyer, products_map, sellers_map, current_seller, qty, seller_total_map,\ seller_product_map, seller_coupon_map, seller_mrp_map, seller_offer_price_map, seller_discount_map, seller_cashback_map, seller_shipping_charges_map) t_body = get_template( 'notifications/order/seller_pending_order.email') ctxt_body = seller_body c_body = Context(ctxt_body) t_sub = get_template( 'notifications/order/seller_pending_order_sub.email') ctxt_sub = seller_sub c_sub = Context(ctxt_sub) seller_emails = current_seller.get_pending_order_notification_email_addresses( ) email_sent_from = "%s<lead@%s>" % ( self.order.client.name, self.order.client.clientdomain_name) email_body = t_body.render(c_body) email_subject = t_sub.render(c_sub) email_bcc = '' if seller_emails: email_to = seller_emails email_bcc = "fulfillment@%s" % self.order.client.clientdomain_name else: email_to = "fulfillment@%s" % self.order.client.clientdomain_name semail = NEmail() semail._from = email_sent_from semail.body = email_body semail.subject = email_subject semail.to = email_to semail.isHtml = True semail.bcc = email_bcc email_log = LEmail(client_domain=self.request.client, order=self.order, profile=self.order.user, sent_to=email_to[:999], bccied_to=email_bcc, sent_from=email_sent_from, subject=email_subject, body=email_body, status='in_queue', type='seller_pending_order') email_log.save() semail.email_log_id = email_log.id if 'seller' in self.groups: notifications.append(semail) # elif 'admin' in self.groups: # notifications.append(semail) return notifications
def getNotifications(self): notifications = [] buyer = self.order.user order_items = OrderItem.objects.select_related( 'seller_rate_chart').filter(order=self.order) product = order_items[0].seller_rate_chart.product qty = order_items[0].qty products_map = {} for item in order_items: seller = item.seller_rate_chart.seller seller_id = seller.id product = item.seller_rate_chart.product products_map[product.id] = product email_body_ctxt = {} email_subject_ctxt = {} sms_body_ctxt = {} sms_subject_ctxt = {} self.fill_attributes(self.order, product, email_body_ctxt, email_subject_ctxt,\ buyer, products_map, qty) self.fill_attributes(self.order, product, sms_body_ctxt, sms_subject_ctxt,\ buyer, products_map, qty) t_body = get_template('notifications/order/shipped_order.email') t_sub = get_template('notifications/order/shipped_order_sub.email') ctxt_body = email_body_ctxt c_body = Context(ctxt_body) ctxt_sub = email_subject_ctxt c_sub = Context(ctxt_sub) email_body = t_body.render(c_body) email_subject = t_sub.render(c_sub) email_sent_from = "%s<fulfillment@%s>" % ( self.order.client.name, self.order.client.clientdomain_name) email_bcc, email_to = '', '' if buyer.get_primary_emails(): emails = '' for email in buyer.get_primary_emails(): emails += email.email + ',' email_to = emails.strip(',') email_bcc = "customerservice@%s" % self.order.client.clientdomain_name else: email_to = "customerservice@%s" % self.order.client.clientdomain_name email_bcc = "" bemail = NEmail() bemail.body = email_body bemail.subject = email_subject bemail.to = email_to bemail._from = email_sent_from bemail.bcc = email_bcc bemail.isHtml = True email_log = LEmail(client_domain=self.request.client, order=self.order, profile=self.order.user, sent_to=email_to[:999], bccied_to=email_bcc, sent_from=email_sent_from, subject=email_subject, body=email_body, status='in_queue', type='shipped_order') email_log.save() bemail.email_log_id = email_log.id notifications.append(bemail) if buyer.get_primary_phones(): sms = SMS() t_sms_body = get_template('notifications/order/shipped_order.sms') ctxt_sms_body = sms_body_ctxt c_sms_body = Context(ctxt_sms_body) sms.text = t_sms_body.render(c_sms_body) sms.to = buyer.get_primary_phones()[0].phone sms.mask = self.order.client.sms_mask notifications.append(sms) return notifications
def subscribe_email_link(request, alliance_name=None): form = FBRegisterForm() url = request.get_full_path() if not alliance_name: raise Http404 else: affiliate_name = alliance_name.strip() try: affiliate_subscription = SubscriptionLink.objects.get(path='/'+affiliate_name) except: raise Http404 affiliate = affiliate_subscription.affiliate affiliate_logo = affiliate.logo affiliate_text = affiliate.text newsletter = affiliate_subscription.newsletter do_post = True show_avail_coupon = affiliate.is_coupon_avail if affiliate_name == "afaqs": do_post = False errors = [] welcome_html = 'fb/register_for_deals.html' special_offers = ['gift'] if affiliate_name in special_offers: welcome_html = 'fb/register_for_special_offers.html' if request.method == 'POST': form = FBRegisterForm(request.POST) error='' already_subscribed = False if form.is_valid(): f=form.cleaned_data email_id = f['email'].strip() mobile_no = f['mobile'].strip() name = f['name'].strip() email_user,phone_user,email_alert_on,sms_alert_on = get_user_by_email_or_mobile(email_id,mobile_no) html_page = 'fb/discount-%s.html' % affiliate_name is_valid = True _coupon = Voucher.objects.filter(affiliate= affiliate, status="active").order_by('id') text = 'your' total_coupon_codes ={} if affiliate.is_coupon_avail: if _coupon: _coupon = _coupon[0] total_coupon_codes[affiliate_name] = _coupon.code else: errors.append("Sorry!! Coupons are not available") is_valid = False if affiliate_name == 'esc': total_coupon_codes = assign_coupons(affiliate) if is_valid: if not email_user and not phone_user: #new user user,profile = utils.get_or_create_user(email_id, email_id, None, name) email = UserEmail.objects.get(user=profile,type='primary',email=email_id) email_alert_on = email phone = Phone(user=profile,type='primary',phone=mobile_no) phone.save() sms_alert_on = phone elif email_user and phone_user: if phone_user == email_user: is_valid = True else: errors.append('Email id and Phone are not registered for the same user.') is_valid = False elif not email_user and phone_user: #user with phone number already exist, update his email address only errors.append('Mobile number is already subscribed.') is_valid = False elif not phone_user and email_user: #user with email already exist, update his phone number only errors.append('Email address is already subscribed.') is_valid = False if not is_valid: return render_to_response(welcome_html, { 'form':form, 'affiliate_logo':affiliate_logo, 'affiliate_text':affiliate_text, 'affiliate_name':affiliate_name, 'do_post':do_post, 'errors':errors, },context_instance = RequestContext(request)) url = request.get_full_path() existing_subscription_email = DailySubscription.objects.filter(newsletter=newsletter,email_alert_on=email_alert_on,source = affiliate_name) existing_subscription_phone = DailySubscription.objects.filter(newsletter=newsletter,sms_alert_on=sms_alert_on,source = affiliate_name) if affiliate_name in ["vcomm",'affinity','tyroo']: existing_subscription_email = DailySubscription.objects.filter(email_alert_on=email_alert_on) existing_subscription_phone = None if not existing_subscription_email and not existing_subscription_phone: subscribe = DailySubscription() subscribe.newsletter = newsletter subscribe.sms_alert_on = sms_alert_on subscribe.email_alert_on = email_alert_on subscribe.source = affiliate_name subscribe.save() if request.POST.get("selected_affiliates","") == "selected_affiliates": t_body = get_template('notifications/users/affiliates_afaqs.email') email_body = {} email_body['request'] = request email_body['name'] = name c_body = Context(email_body) t_subject = get_template('notifications/users/subscribe_sub.email') email_from = {} email_subject = {} c_subject = Context(email_subject) mail_obj = EmailAddress() if is_future_ecom(request.client.client): mail_obj.isHtml = True mail_obj._from = request.client.client.promotions_email mail_obj.body = t_body.render(c_body) mail_obj.subject = t_subject.render(c_subject) u_emails = "" email = str(email_id) u_emails = email.strip(',') mail_obj.to = u_emails mail_obj.send() utils.subscribe_send_sms(mobile_no) return HttpResponseRedirect("/") if not affiliate.is_coupon_avail: if affiliate_name in special_offers: send_coupons_by_email(request, total_coupon_codes, affiliate_name, email_alert_on, show_avail_coupon) send_coupons_by_sms(request, total_coupon_codes, affiliate_name, sms_alert_on, show_avail_coupon) else: utils.subscribe_send_email(request,email_id, name) utils.subscribe_send_sms(mobile_no) return render_to_response('fb/thankyou-%s.html' % affiliate_name,{'email_id':email_id},context_instance = RequestContext(request)) if email_alert_on: send_coupons_by_email(request, total_coupon_codes, affiliate_name, email_alert_on, show_avail_coupon) if sms_alert_on: send_coupons_by_sms(request, total_coupon_codes, affiliate_name, sms_alert_on, show_avail_coupon) if affiliate_name != 'esc': _coupon.status = "inactive" _coupon.save() else: errors.append("You have already subscribed for the deal.") already_subscribed = True is_valid = False if affiliate_name in ["vcomm",'affinity','tyroo']: return render_to_response('fb/subscribed.html', {'affiliate_name':affiliate_name,'already_subscribed':already_subscribed}, context_instance = RequestContext(request)) if is_valid: return render_to_response(html_page, {'affiliate_name':affiliate_name,'coupon_codes':total_coupon_codes, 'already_subscribed':already_subscribed}, context_instance = RequestContext(request)) return render_to_response(welcome_html, { 'form':form, 'affiliate_logo':affiliate_logo, 'affiliate_text':affiliate_text, 'affiliate_name':affiliate_name, 'do_post':do_post, 'errors':errors, 'show_avail_coupon':show_avail_coupon, }, context_instance = RequestContext(request))