예제 #1
0
def support_email(request):
    from store_admin.forms import EmailContactForm
    from preferences.models import EmailNotificationHistory
    from django.template.defaultfilters import striptags
    from subscriptions.models import FeaturePayment
    shop = request.shop

    if request.method == "POST":
        txn_id = request.POST.get('txn_id', None)
        payment = FeaturePayment.objects.filter(transaction_id=txn_id,
                                                shop=shop).count()
        if not payment:
            request.flash[
                'message'] = "Your payment is not registered in our system."
            request.flash['severity'] = "error"
            return HttpResponseRedirect(reverse("support"))

        form = EmailContactForm(request.POST)
        if form.is_valid():
            marketplace = request.shop.marketplace
            logging.critical(form.cleaned_data)
            to = marketplace.contact_email
            user_email = form.cleaned_data['email']
            user_question = form.cleaned_data['question']
            user_name = form.cleaned_data['name']

            subject = "Email Support Requested"
            the_message = "%s has request email support from %s <%s>. \n\nUser Email: %s\n\nUser Question: %s" % (
                user_name, shop.name_shop(), shop.default_dns, user_email,
                striptags(user_question))

            mail = EmailMessage(
                subject=subject,
                body=the_message,
                from_email=settings.EMAIL_FROM,
                to=[to],
                headers={
                    'X-SMTPAPI': '{\"category\": \"Email Support Requested\"}'
                })
            mail.send(fail_silently=True)
            #            send_mail(subject, the_message, shop.admin.email, [to], fail_silently=True)

            notification_history = EmailNotificationHistory(
                shop=shop,
                type_notification='CB',
                datetime=datetime.datetime.now(),
                to=to,
                subject=subject,
                body=the_message)
            notification_history.save()

            request.flash['message'] = "Support request sent..."
            request.flash['severity'] = "success"
            return HttpResponseRedirect(reverse("support"))
    else:
        form = EmailContactForm()
    return render_to_response('store_admin/support/email.html', {'form': form},
                              RequestContext(request))
예제 #2
0
    def sold(self):
        from sell.models import Cart
        from preferences.models import EmailNotification, EmailNotificationHistory, TYPE_NOTIFICATION
        from django.core.mail import send_mail, EmailMessage
        from django.conf import settings
        from django.template import Context, Template
        
        self.state = 'S'
        self.save()
        cart = Cart.objects.filter(shop=self.shop, bidder=self.bid_actual.bidder).get()
        cart.add(self, self.current_bid(), 1)
        
        # ------------------------------------------------------------------------
        # Send an email to bidder to notify he/she has won the auction
        c = Context({'bidder_name': self.bid_actual.bidder.get_full_name(),
                     'bid_amount': self.bid_actual.bid_amount,
                     'bid_time': self.bid_actual.bid_time,
                     'shop': self.shop.name,
                     'session_title': self.session.title,
                     'session_description': striptags(self.session.description),
                     'session_start': str(self.session.start),
                     'session_end': str(self.session.end),
                     'lot_title': self.title,
                     'lot_description': striptags(self.description) })
        
        admin_email = self.shop.marketplace.contact_email
        try:
            notification = EmailNotification.objects.filter(type_notification='AWC', shop=self.shop).get()
            type_notification_name = dict(TYPE_NOTIFICATION)[notification.type_notification].title()
            subj_template = Template(notification.subject)
            body_template = Template(notification.body)
            
            subj_text = subj_template.render(c)
            body_text = body_template.render(c)
            
            mail = EmailMessage(subject=subj_text,
                                body=body_text,
                                from_email=settings.EMAIL_FROM,
                                to=[self.bid_actual.bidder.email],
                                headers={'X-SMTPAPI': '{\"category\": \"%s\"}' % type_notification_name})
            mail.send(fail_silently=True)
#            send_mail(subj_text, body_text, settings.EMAIL_FROM, [self.bid_actual.bidder.email], fail_silently=True)

            notification_history = EmailNotificationHistory(shop=self.shop,
                                                        type_notification=notification.type_notification,
                                                        datetime= datetime.datetime.now(),
                                                        to=self.bid_actual.bidder.email,
                                                        subject=subj_text,
                                                        body=body_text)
            notification_history.save()
        except EmailNotification.DoesNotExist:
            msg = "You made a bid u$s %s for %s and have won the auction!. Please contact %s to get more details about this purchase. Thanks" % (self.bid_actual.bid_amount, self.title, self.shop.admin.email)
            mail = EmailMessage(subject="Congratulations!!",
                                body=msg,
                                from_email=settings.EMAIL_FROM,
                                to=[self.bid_actual.bidder.email],
                                headers={'X-SMTPAPI': '{\"category\": \"%s\"}' % dict(TYPE_NOTIFICATION)['AWC'].title()})
            mail.send(fail_silently=True)
#            send_mail("Congratulations!!", msg, settings.EMAIL_FROM,  [self.bid_actual.bidder.email], fail_silently=True)
        except Exception, e:
            mail = EmailMessage(subject="Could not send email to lot winner!",
                                body="Message could not be delivered to %s" % self.bid_actual.bidder.email,
                                from_email=settings.EMAIL_FROM,
                                to=[mail for (name, mail) in settings.STAFF]+[admin_email],
                                headers={'X-SMTPAPI': '{\"category\": \"Error\"}'})
            mail.send(fail_silently=True)
예제 #3
0
    def close(self, payment_method):
        from django.conf import settings
        from django.core.mail import send_mail, EmailMessage
        from django.template import Context, Template
        from preferences.models import EmailNotification, EmailNotificationHistory, TYPE_NOTIFICATION

        if self.shippingdata is None:
            raise Exception(
                "Cart Shipping address should never be empty. Something is wrong!"
            )
        sell = Sell.new_sell(self.shop, self.bidder, self.shippingdata, self)
        items = []
        for cart_item in self.cartitem_set.all():
            sell_item = SellItem(sell=sell,
                                 product=cart_item.product,
                                 qty=cart_item.qty,
                                 price=cart_item.price)
            sell_item.save()

            cart_item.product.decrease_qty(cart_item.qty)
            cart_item.product.save()

            host_name = sell_item.product.shop.default_dns
            link = "http://%s/admin/for_sale/item_details/%s" % (
                host_name, sell_item.product.id)

            item = {
                'id': sell_item.product.id,
                'title': sell_item.product.title,
                'qty': sell_item.qty,
                'price': sell_item.price,
                'total': sell_item.get_total(),
                'link': link,
            }

            items.append(item)

            cart_item.delete()

        sell.payment_method = payment_method
        sell.save()

        #Why is this put to None!!!
        # there is only one cart for user so the cart has to be clean
        self.shippingdata = None
        self.save()

        # -----------------------------
        # Send notification to Shop that new order has been created
        c = Context({
            'buyer_name':
            '%s %s' %
            (sell.shippingdata.first_name,
             sell.shippingdata.last_name),  #self.bidder.get_full_name(),
            'buyer_email':
            self.bidder.email,
            'buyer_phone':
            self.bidder.profile.phone,
            'gateway':
            sell.payment_method,
            'shop':
            self.shop,
            'shipping_street_address':
            sell.shippingdata.street_address,
            'shipping_city':
            sell.shippingdata.city,
            'shipping_state':
            sell.shippingdata.state,
            'shipping_zip':
            sell.shippingdata.zip,
            'shipping_country':
            sell.shippingdata.country,
            'sell_date':
            sell.date_time,
            'sell_total':
            sell.total,
            'sell_without_taxes':
            sell.total_without_taxes,
            'sell_total_taxes':
            sell.total_taxes,
            'sell_total_shipping':
            sell.total_shipping,
            'items':
            items
        })

        # SEND NEW ORDER NOTIFICATION TO SHOP OWNER
        try:
            notification = EmailNotification.objects.filter(
                type_notification='NON', shop=self.shop).get()
            type_notification_name = dict(TYPE_NOTIFICATION)[
                notification.type_notification].title()

            subj_template = Template(notification.subject)
            body_template = Template(notification.body)

            subj_text = subj_template.render(c)
            body_text = body_template.render(c)
            #            send_mail(subj_text, body_text, settings.EMAIL_FROM, [self.shop.admin.email], fail_silently=True)

            mail = EmailMessage(subject=subj_text,
                                body=body_text,
                                from_email=settings.EMAIL_FROM,
                                to=[self.shop.admin.email],
                                headers={
                                    'X-SMTPAPI':
                                    '{\"category\": \"%s\"}' %
                                    type_notification_name
                                })
            mail.send(fail_silently=True)

            notification_history = EmailNotificationHistory(
                shop=self.shop,
                type_notification=notification.type_notification,
                datetime=datetime.datetime.now(),
                to=self.shop.admin.email,
                subject=subj_text,
                body=body_text)
            notification_history.save()

        except EmailNotification.DoesNotExist:
            msg = "New Order Notification"

            mail = EmailMessage(subject="New Order Notification",
                                body=msg,
                                from_email=settings.EMAIL_FROM,
                                to=[self.shop.admin.email],
                                headers={
                                    'X-SMTPAPI':
                                    '{\"category\": \"%s\"}' %
                                    dict(TYPE_NOTIFICATION)['NON'].title()
                                })
            mail.send(fail_silently=True)
#            send_mail("New order has been generated!", msg, settings.EMAIL_FROM, [self.shop.admin.email], fail_silently=True)

        except Exception, e:
            mail = EmailMessage(
                subject="Fail when trying to send email!",
                body=e,
                from_email=settings.EMAIL_FROM,
                to=[mail for (name, mail) in settings.STAFF],
                headers={'X-SMTPAPI': '{\"category\": \"Error\"}'})
            mail.send(fail_silently=True)
예제 #4
0
def notify_to_buyer(request, cart_id):
    from sell.models import Cart
    from django.template import Context, Template
    from preferences.models import EmailNotification, EmailNotificationHistory, TYPE_NOTIFICATION

    shop = request.shop
    cart = get_object_or_404(Cart, shop=shop, pk=cart_id)

    items = []
    for cart_item in cart.cartitem_set.all():
        item = {
            'title': cart_item.product.title,
            'qty': cart_item.qty,
            'price': cart_item.price,
            'total': cart_item.sub_total(),
        }
        items.append(item)

    c = Context({
        'bidder_name':
        '%s %s' % (cart.bidder.first_name, cart.bidder.last_name),
        'shop':
        shop.name,
        'cart_date':
        cart.creation_date,
        'cart_total':
        cart.total(),
        'items':
        items,
    })

    try:
        notification = EmailNotification.objects.filter(
            type_notification='BCN', shop=shop).get()
        type_notification_name = dict(TYPE_NOTIFICATION)[
            notification.type_notification].title()
        subj_template = Template(notification.subject)
        body_template = Template(notification.body)

        subj_text = subj_template.render(c)
        body_text = body_template.render(c)

        mail = EmailMessage(subject=subj_text,
                            body=body_text,
                            from_email=settings.EMAIL_FROM,
                            to=[cart.bidder.email],
                            headers={
                                'X-SMTPAPI':
                                '{\"category\": \"%s\"}' %
                                type_notification_name
                            })
        mail.send(fail_silently=True)
        #        send_mail(subj_text, body_text, settings.EMAIL_FROM, [cart.bidder.email], fail_silently=True)
        notification_history = EmailNotificationHistory(
            shop=shop,
            type_notification=notification.type_notification,
            datetime=datetime.datetime.now(),
            to=cart.bidder.email,
            subject=subj_text,
            body=body_text)
        notification_history.save()

        request.flash['message'] = unicode(
            _("Notification sent to %s" % cart.bidder.email))
        request.flash['severity'] = "success"
    except:
        request.flash['message'] = unicode(
            _("Fail Notification sent to %s" % cart.bidder.email))
        request.flash['severity'] = "error"

    return HttpResponseRedirect(reverse("inventory_carts"))