예제 #1
0
파일: fb.py 프로젝트: daasara/riba
def send_coupons_by_sms(request, total_coupon_codes, affiliate_name, sms_alert_on, show_avail_coupon):
    t_sms = get_template('notifications/subscriptions/%s.sms' % affiliate_name)
    sms_content = {}
    if show_avail_coupon:
        try:
            sms_content['coupon_code'] = total_coupon_codes[affiliate_name]
        except KeyError:
            pass
        try:
            sms_content['pantaloon'] = total_coupon_codes['pantaloon']
        except KeyError:
            pass
        try:
            sms_content['bigbazaar'] = total_coupon_codes['bigbazaar']
        except KeyError:
            pass
        try:
            sms_content['futurebazaar'] = total_coupon_codes['futurebazaar']
        except KeyError:
            pass
    c_sms = Context(sms_content)
    sms_text = t_sms.render(c_sms)
    sms = SMS()
    sms.text = sms_text
    sms.mask = request.client.client.sms_mask
    sms.to = sms_alert_on.phone
    sms.send()
예제 #2
0
def send_coupons_by_sms(request, total_coupon_codes, affiliate_name, sms_alert_on, show_avail_coupon):
    t_sms = get_template("notifications/subscriptions/%s.sms" % affiliate_name)
    sms_content = {}
    if show_avail_coupon:
        try:
            sms_content["coupon_code"] = total_coupon_codes[affiliate_name]
        except KeyError:
            pass
        try:
            sms_content["pantaloon"] = total_coupon_codes["pantaloon"]
        except KeyError:
            pass
        try:
            sms_content["bigbazaar"] = total_coupon_codes["bigbazaar"]
        except KeyError:
            pass
        try:
            sms_content["futurebazaar"] = total_coupon_codes["futurebazaar"]
        except KeyError:
            pass
    c_sms = Context(sms_content)
    sms_text = t_sms.render(c_sms)
    sms = SMS()
    sms.text = sms_text
    sms.mask = request.client.client.sms_mask
    sms.to = sms_alert_on.phone
    sms.send()
예제 #3
0
    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
예제 #4
0
    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
예제 #5
0
    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
예제 #6
0
def subscribe_email_link(request, alliance):
    form = FBRegisterForm()
    affiliate_name = alliance
    try:
        affiliate_subscription = SubscriptionLink.objects.get(path="/" + affiliate_name)
    except SubscriptionLink.DoesNotExist:
        raise Http404
    affiliate_logo = affiliate_subscription.affiliate.logo
    affiliate_text = affiliate_subscription.affiliate.text
    newsletter = affiliate_subscription.newsletter

    if request.method == "POST":
        form = FBRegisterForm(request.POST)
        error = ""
        already_subscribed = False
        if form.is_valid():
            f = form.cleaned_data
            email_id = f["email"]
            mobile_no = f["mobile"]
            name = f["name"]
            email_user, phone_user, email_alert_on, sms_alert_on = get_user_by_email_or_mobile(
                email_id, mobile_no
            )  # User.objects.get(username = mobile_no)
            if not email_user and not phone_user:  # new user
                user = User.objects.create_user(email_id, email_id, None)
                user.first_name = f["name"]
                user.save()

                profile = Profile(user=user, full_name=user.first_name)
                profile.save()

                email = UserEmail(user=profile, type="primary", email=email_id)
                email.save()
                email_alert_on = email
                phone = Phone(user=profile, type="primary", phone=mobile_no)
                phone.save()
                sms_alert_on = phone
            if not email_user and phone_user:  # user with phone number already exist, update his email address only
                email = UserEmail(user=phone_user, type="primary", email=email_id)
                email.save()
                email_alert_on = email
            if not phone_user and email_user:  # user with email already exist, update his phone number only
                phone = Phone(user=email_user, type="primary", phone=mobile_no)
                phone.save()
                sms_alert_on = phone
            if email_user and phone_user and email_user != phone_user:  # phone user and email user are different
                pass

            existing_subscription = DailySubscription.objects.filter(
                newsletter=newsletter,
                sms_alert_on=sms_alert_on,
                email_alert_on=email_alert_on,
                source="/" + affiliate_name,
            )
            if not existing_subscription:
                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()
            else:
                already_subscribed = True
                return render_to_response(
                    "fb/subscribed.html",
                    {"affiliate_name": affiliate_name, "already_subscribed": already_subscribed},
                    context_instance=RequestContext(request),
                )

            total_coupon_codes, text = assign_coupons(affiliate_subscription.affiliate, email_alert_on, sms_alert_on)
            if alliance == "icici":
                return render_icici_products(request, total_coupon_codes)
            if email_alert_on:
                send_coupons_by_email(total_coupon_codes, affiliate_subscription.affiliate, email_alert_on)

            if sms_alert_on:
                sms_text = text
                sms = SMS()
                sms.text = sms_text
                sms.to = sms_alert_on.phone
                sms.send()

            return render_to_response(
                "fb/discount.html",
                {
                    "affiliate": affiliate_subscription.affiliate,
                    "coupon_codes": total_coupon_codes,
                    "already_subscribed": already_subscribed,
                },
                context_instance=RequestContext(request),
            )
        else:
            return render_to_response(
                "fb/register_for_deals.html",
                {"form": form, "affiliate_logo": affiliate_logo, "affiliate_text": affiliate_text},
                context_instance=RequestContext(request),
            )

    else:
        return render_to_response(
            "fb/register_for_deals.html",
            {"form": form, "affiliate_logo": affiliate_logo, "affiliate_text": affiliate_text},
            context_instance=RequestContext(request),
        )
예제 #7
0
    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
예제 #8
0
    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
예제 #9
0
    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
예제 #10
0
from notifications.email import Email as EmailAddress
from notifications.sms import SMS
from django.template import Context, Template
from django.template.loader import get_template


for data in datas:
    t_body = get_template('notifications/subscriptions/win_winner.email')
    email_body = {}
    email_body['gift'] = data['gift']
    c_body = Context(email_body)
    email_from = {}
    mail_obj = EmailAddress()
    mail_obj.isHtml = True
    mail_obj._from = "promotions.futurebazaar.com"
    mail_obj.body = t_body.render(c_body)
    mail_obj.subject = "Winner"
    u_emails = ""
    email = str(data['email'])
    mail_obj.to = email
    mail_obj.send()
    sms_text = 'Congratulations!! You are the winner of "Scratch in a Flash or Miss the Bash" Contest. Visit win.futurebazaar.com / Call 0922-222-1947 for details'
    sms = SMS()
    sms.text = sms_text
    phone = str(data['mobile'])
    sms.to = phone
    sms.send()

    print "SENT EMAIL TO: %s, SMS TO: %s, GIFT: %s" % (email, data['mobile'], data['gift'])
예제 #11
0
파일: fb_backup_1.py 프로젝트: daasara/riba
def subscribe_email_link(request, alliance):
    form = FBRegisterForm()
    affiliate_name = alliance
    try:
        affiliate_subscription = SubscriptionLink.objects.get(path='/' +
                                                              affiliate_name)
    except SubscriptionLink.DoesNotExist:
        raise Http404
    affiliate_logo = affiliate_subscription.affiliate.logo
    affiliate_text = affiliate_subscription.affiliate.text
    newsletter = affiliate_subscription.newsletter

    if request.method == 'POST':
        form = FBRegisterForm(request.POST)
        error = ''
        already_subscribed = False
        if form.is_valid():
            f = form.cleaned_data
            email_id = f['email']
            mobile_no = f['mobile']
            name = f['name']
            email_user, phone_user, email_alert_on, sms_alert_on = get_user_by_email_or_mobile(
                email_id, mobile_no)  #User.objects.get(username = mobile_no)
            if not email_user and not phone_user:  #new user
                user = User.objects.create_user(email_id, email_id, None)
                user.first_name = f['name']
                user.save()

                profile = Profile(user=user, full_name=user.first_name)
                profile.save()

                email = UserEmail(user=profile, type='primary', email=email_id)
                email.save()
                email_alert_on = email
                phone = Phone(user=profile, type='primary', phone=mobile_no)
                phone.save()
                sms_alert_on = phone
            if not email_user and phone_user:  #user with phone number already exist, update his email address only
                email = UserEmail(user=phone_user,
                                  type='primary',
                                  email=email_id)
                email.save()
                email_alert_on = email
            if not phone_user and email_user:  #user with email already exist, update his phone number only
                phone = Phone(user=email_user, type='primary', phone=mobile_no)
                phone.save()
                sms_alert_on = phone
            if email_user and phone_user and email_user != phone_user:  #phone user and email user are different
                pass

            existing_subscription = DailySubscription.objects.filter(
                newsletter=newsletter,
                sms_alert_on=sms_alert_on,
                email_alert_on=email_alert_on,
                source='/' + affiliate_name)
            if not existing_subscription:
                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()
            else:
                already_subscribed = True
                return render_to_response(
                    'fb/subscribed.html', {
                        'affiliate_name': affiliate_name,
                        'already_subscribed': already_subscribed
                    },
                    context_instance=RequestContext(request))

            total_coupon_codes, text = assign_coupons(
                affiliate_subscription.affiliate, email_alert_on, sms_alert_on)
            if alliance == 'icici':
                return render_icici_products(request, total_coupon_codes)
            if email_alert_on:
                send_coupons_by_email(total_coupon_codes,
                                      affiliate_subscription.affiliate,
                                      email_alert_on)

            if sms_alert_on:
                sms_text = text
                sms = SMS()
                sms.text = sms_text
                sms.to = sms_alert_on.phone
                sms.send()

            return render_to_response('fb/discount.html', {
                'affiliate': affiliate_subscription.affiliate,
                'coupon_codes': total_coupon_codes,
                'already_subscribed': already_subscribed
            },
                                      context_instance=RequestContext(request))
        else:
            return render_to_response('fb/register_for_deals.html', {
                'form': form,
                'affiliate_logo': affiliate_logo,
                'affiliate_text': affiliate_text
            },
                                      context_instance=RequestContext(request))

    else:
        return render_to_response('fb/register_for_deals.html', {
            'form': form,
            'affiliate_logo': affiliate_logo,
            'affiliate_text': affiliate_text
        },
                                  context_instance=RequestContext(request))