def create(self, user, recipient, recipient_name, recipient_surname, text=None, site=None): """Creates a new invite. Use this and don't instantiate ``Invite`` classes directly and then save them, as this will not send any mail. """ if site is None: site = Site.objects.get_current() invites_sent = self.all().filter(site=site, inviter=user, countable=True).count() max_invites = config_value('INVITES_SETTINGS', 'MAX_INVITES') if invites_sent > max_invites: raise self.model.OverQuota(user) # XXX: on linux system uuid1 returns less than 34 chars code = "%x-%x-%x-%x%x-%x" % uuid1().fields code = code[:32] invite = self.model(site=site, code=code, inviter=user, recipient=recipient, recipient_name=recipient_name, recipient_surname=recipient_surname, text=text, used=False, countable=True) invite.save(from_manager=True) shop_config = Config.objects.get_current() send_store_mail(subject=_(u'You have been invited to join' u' by %(first_name)s %(last_name)s') % { 'first_name': invite.inviter.first_name, 'last_name': invite.inviter.last_name }, context={ 'site_domain': site.domain, 'recipient_name': invite.recipient_name, 'inviter_name': invite.inviter.first_name, 'inviter_surname': invite.inviter.last_name, 'inviter_email': invite.inviter.email, 'shop_description': shop_config.store_description, 'registration_url': reverse('invites_register', kwargs={'invite_code': invite.code}) }, template='invites/mail/invite.txt', recipients_list=[invite.recipient], template_html='invites/mail/invite.html') return invite
def send_order_notice(order, template='', template_html=''): """Send an order confirmation mail to the owner. """ if config_value("PAYMENT", "ORDER_EMAIL_OWNER"): try: sale = Discount.objects.by_code(order.discount_code, raises=True) except Discount.DoesNotExist: sale = None c = {'order': order, 'sale': sale} subject = _("New order on %(shop_name)s") eddresses = [] more = config_value("PAYMENT", "ORDER_EMAIL_EXTRA") if more: eddresses = set([m.strip() for m in more.split(',')]) eddresses = [e for e in eddresses if e] try: send_store_mail(subject, c, template, eddresses, template_html=template_html, format_subject=True, send_to_store=True, sender=order_notice_sender) except NoRecipientsException: log.warn("No shop owner email specified, skipping owner_email") return
def send_order_notice(order, template='', template_html=''): """Send an order confirmation mail to the owner. """ if config_value("PAYMENT", "ORDER_EMAIL_OWNER"): try: sale = Discount.objects.by_code(order.discount_code, raises=True) except Discount.DoesNotExist: sale = None c = {'order': order, 'sale' : sale} subject = _("New order on %(shop_name)s") eddresses = [] more = config_value("PAYMENT", "ORDER_EMAIL_EXTRA") if more: eddresses = set([m.strip() for m in more.split(',')]) eddresses = [e for e in eddresses if e] try: send_store_mail(subject, c, template, eddresses, template_html=template_html, format_subject=True, send_to_store=True, sender=order_notice_sender) except NoRecipientsException: log.warn("No shop owner email specified, skipping owner_email") return
def contact_form(request): if request.method == "POST": form = ContactForm(request.POST) if form.is_valid(): new_data = form.cleaned_data c = { 'request_type': new_data['inquiry'], 'name': new_data['name'], 'email': new_data['sender'], 'request_text': new_data['contents']} subject = new_data['subject'] send_store_mail(subject, c, 'shop/email/contact_us.txt', send_to_store=True, sender=contact_sender) url = urlresolvers.reverse('satchmo_contact_thanks') return http.HttpResponseRedirect(url) else: #Not a post so create an empty form initialData = {} if request.user.is_authenticated(): initialData['sender'] = request.user.email initialData['name'] = request.user.first_name + " " + \ request.user.last_name form = ContactForm(initial=initialData) return render_to_response('shop/contact_form.html', {'form': form}, context_instance=RequestContext(request))
def get_rates(self, cart, contact): from satchmo_store.shop.models import Config error_ret = False, None, [] shop_details = Config.objects.get_current() # always use production api keys for get_rates, you don't get charged # anyways cpa_kwargs = canada_post_api_kwargs(self.settings, production=True) cpa = CanadaPostAPI(**cpa_kwargs) # parcels is a list of (Parcel, pack(dimensions)) parcels, rest = self.make_parcels(cart) if rest: from django.contrib.sites.models import Site site = Site.objects.get_current() error_message = (u"There's not boxes big enough for some of these " u"products: ({})").format(u", ".join( u"Package({})".format(unicode(p)) for p in rest)) subject = u"There's not boxes big enough for some products" send_store_mail(subject, context={ 'site': site, 'product_list': rest }, template=("canada_post_dp_shipping/admin/mail/" "add_boxes.txt"), send_to_store=True) raise ParcelDimensionError, error_message log.debug(u"Calculated Parcels: [%s]", u",".join(u"({},[{}])".format( pr, u",".join(unicode(pk) for pk in pks)) for pr, pks in parcels)) origin = get_origin(shop_details) destination = get_destination(contact) services = [] for parcel, packs in parcels: # rates depend on dimensions + origin + destination only cache_key = "CP-GetRates-{W}-{l}x{w}x{h}-{fr}-{to}".format( W=parcel.weight, w=parcel.width, h=parcel.height, l=parcel.length, fr=origin.postal_code, to=destination.postal_code ) parcel_services = cache.get(cache_key) if parcel_services is None: try: parcel_services = time_f( cpa.get_rates, 'canada-post-dp-shipping.get-rates', parcel, origin, destination) except CanadaPostError, e: if self.settings.RAISE_TOO_LARGE.value and e.code == 9111: raise ParcelDimensionError, e.message else: log.error(u"Canada Post returned with error: %s|%s", e.code, e.message) parcel_services = [] cache.set(cache_key, parcel_services) # so services is [(Service, parcel, [packs]),...] services.extend(product(filter(lambda s: s.code == self.service_code, parcel_services), [parcel], [packs]))
def send_ship_notice(order, template='shop/email/order_shipped.txt', template_html=''): """Send an order shipped mail to the customer. """ log.debug('ship notice on %s', order) c = {'order': order} subject = _("Your order from %(shop_name)s has shipped") send_store_mail(subject, c, template, [order.contact.email], format_subject=True, template_html=template_html, sender=ship_notice_sender)
def create(self, user, recipient, recipient_name, recipient_surname, text=None, site=None): """Creates a new invite. Use this and don't instantiate ``Invite`` classes directly and then save them, as this will not send any mail. """ if site is None: site = Site.objects.get_current() invites_sent = self.all().filter( site=site, inviter=user, countable=True).count() max_invites = config_value('INVITES_SETTINGS', 'MAX_INVITES') if invites_sent > max_invites: raise self.model.OverQuota(user) # XXX: on linux system uuid1 returns less than 34 chars code = "%x-%x-%x-%x%x-%x" % uuid1().fields code = code[:32] invite = self.model( site=site, code=code, inviter=user, recipient=recipient, recipient_name=recipient_name, recipient_surname=recipient_surname, text=text, used=False, countable=True) invite.save(from_manager=True) shop_config = Config.objects.get_current() send_store_mail( subject=_(u'You have been invited to join' u' by %(first_name)s %(last_name)s') % { 'first_name': invite.inviter.first_name, 'last_name': invite.inviter.last_name}, context={ 'site_domain': site.domain, 'recipient_name': invite.recipient_name, 'inviter_name': invite.inviter.first_name, 'inviter_surname': invite.inviter.last_name, 'inviter_email': invite.inviter.email, 'shop_description': shop_config.store_description, 'registration_url': reverse( 'invites_register', kwargs={ 'invite_code': invite.code } ) }, template='invites/mail/invite.txt', recipients_list=[invite.recipient], template_html='invites/mail/invite.html') return invite
def form_valid(self, form): c = { 'request_type': form.cleaned_data['inquiry'], 'name': form.cleaned_data['name'], 'email': form.cleaned_data['sender'], 'request_text': form.cleaned_data['contents'] } send_store_mail(form.cleaned_data.get("subject", "Request"), c, 'shop/email/contact_us.txt', send_to_store=True, sender=contact_sender) return super(ContactFormView, self).form_valid(form)
def send_welcome_email(email, first_name, last_name): """Send a store new account welcome mail to `email`.""" shop_config = Config.objects.get_current() subject = ugettext("Welcome to %(shop_name)s") c = { 'first_name': first_name, 'last_name': last_name, 'site_url': shop_config.site.domain, 'login_url': settings.LOGIN_URL, } send_store_mail(subject, c, 'registration/welcome.txt', [email], format_subject=True, sender=registration_sender)
def _activate(self, user): today = datetime.utcnow().date() code = "%x%x%x%x%x" % uuid1().fields[0:5] discount = Discount( site=self.site, description=_(u"Invite discount " u"for %(last_name)s %(first_name)s") % { 'last_name': user.last_name, 'first_name': user.first_name}, code=code, active=True, amount=self.amount, percentage=self.percentage, automatic=False, allowedUses=1, minOrder=self.minOrder, startDate=today, endDate=today + timedelta(days=self.daysValid), shipping=self.shipping, allValid=self.allValid) discount.save() for product in self.valid_products.all(): discount.valid_products.add(product) for category in self.valid_categories.all(): discount.valid_categories.add(category) discount.save() discount_amount = None if self.amount is not None: discount_amount = moneyfmt(self.amount) else: discount_amount = "%s%%" % self.percentage send_store_mail( subject=_(u"A discount coupon for you"), context={ 'first_name': user.first_name, 'invites_number': self.invites_target, 'discount_amount': discount_amount, 'coupon_code': discount.code, 'end_date': discount.endDate}, template='invites/mail/discount.txt', recipients_list=[user.email], template_html='invites/mail/discount.html') # create new InviterDiscount inviter_discount = InviterDiscount( user=user, coupon=discount, template=self) inviter_discount.save() return True
def _activate(self, user): today = datetime.utcnow().date() code = "%x%x%x%x%x" % uuid1().fields[0:5] discount = Discount( site=self.site, description=_(u"Invite discount " u"for %(last_name)s %(first_name)s") % { 'last_name': user.last_name, 'first_name': user.first_name }, code=code, active=True, amount=self.amount, percentage=self.percentage, automatic=False, allowedUses=1, minOrder=self.minOrder, startDate=today, endDate=today + timedelta(days=self.daysValid), shipping=self.shipping, allValid=self.allValid) discount.save() for product in self.valid_products.all(): discount.valid_products.add(product) for category in self.valid_categories.all(): discount.valid_categories.add(category) discount.save() discount_amount = None if self.amount is not None: discount_amount = moneyfmt(self.amount) else: discount_amount = "%s%%" % self.percentage send_store_mail(subject=_(u"A discount coupon for you"), context={ 'first_name': user.first_name, 'invites_number': self.invites_target, 'discount_amount': discount_amount, 'coupon_code': discount.code, 'end_date': discount.endDate }, template='invites/mail/discount.txt', recipients_list=[user.email], template_html='invites/mail/discount.html') # create new InviterDiscount inviter_discount = InviterDiscount(user=user, coupon=discount, template=self) inviter_discount.save() return True
def send_reward_email(email, first_name, last_name, invitees_number, discount): """Send a store new account welcome mail to `email`.""" shop_config = Config.objects.get_current() subject = ugettext("Thanks for your invitation of your friends to %(shop_name)s") c = { 'first_name': first_name, 'last_name': last_name, 'site_url': shop_config.site and shop_config.site.domain or 'localhost', 'login_url': settings.LOGIN_URL, 'invitees_number': invitees_number, 'discount': discount } send_store_mail(subject, c, 'campaign/invite-reward.txt', [email], format_subject=True)
def send_order_confirmation(order, template='', template_html=''): """Send an order confirmation mail to the customer. """ try: sale = Discount.objects.by_code(order.discount_code, raises=True) except Discount.DoesNotExist: sale = None c = {'order': order, 'sale' : sale} subject = _("Thank you for your order from %(shop_name)s") send_store_mail(subject, c, template, [order.contact.email], template_html=template_html, format_subject=True, sender=order_confirmation_sender)
def send_activation_email(self, site): """Send the activation mail""" ctx_dict = {'activation_key': self.activation_key, 'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS, 'site': site} subject = render_to_string('registration/activation_email_subject.txt', ctx_dict) # Email subject *must not* contain newlines subject = ''.join(subject.splitlines()) send_store_mail( subject=subject, context=ctx_dict, template='registration/activation_email.txt', recipients_list=[self.user.email], template_html='registration/activation_email.html')
def send_activation_email(self, site): """Send the activation mail""" ctx_dict = { 'activation_key': self.activation_key, 'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS, 'site': site } subject = render_to_string('registration/activation_email_subject.txt', ctx_dict) # Email subject *must not* contain newlines subject = ''.join(subject.splitlines()) send_store_mail(subject=subject, context=ctx_dict, template='registration/activation_email.txt', recipients_list=[self.user.email], template_html='registration/activation_email.html')
def send_order_confirmation(order, template='', template_html=''): """Send an order confirmation mail to the customer. """ try: sale = Discount.objects.by_code(order.discount_code, raises=True) except Discount.DoesNotExist: sale = None c = {'order': order, 'sale': sale} subject = _("Thank you for your order from %(shop_name)s") send_store_mail(subject, c, template, [order.contact.email], template_html=template_html, format_subject=True, sender=order_confirmation_sender)
def send_welcome_email(email, first_name, last_name): """Send a store new account welcome mail to `email`.""" shop_config = Config.objects.get_current() subject = ugettext("Welcome to %(shop_name)s") c = { 'first_name': first_name, 'last_name': last_name, 'site_url': shop_config.site and shop_config.site.domain or 'localhost', 'login_url': settings.LOGIN_URL, } send_store_mail( subject=subject, context=c, template='registration/welcome.txt', recipients_list=[email], format_subject=True, sender=registration_sender, template_html='registration/welcome.html')
def send_gift_certificate_by_email(gc): """ Helper function to send email messages to gift certificate recipients """ ctx = { 'message': gc.message, 'addressee': gc.recipient_email, 'code': gc.code, 'balance':gc.balance, 'purchased_by': gc.purchased_by } subject = _('Your Gift Certificate') send_store_mail( subject, ctx, template = 'shop/email/gift_certificate_recipient.txt', template_html='shop/email/gift_certificate_recipient.html', recipients_list=[gc.recipient_email,], fail_silently=True, )
except Shipment.DoesNotExist: log.error("Requested shipment does not exist") manifests.append(manifest) except Exception, e: log.error("Error processing manifest: %s", e, exc_info=True) subject_template = get_template( 'canada_post_dp_shipping/admin/mail/manifests_subject.txt') subject = subject_template.render(Context({'manifests': manifests})).strip() site = Site.objects.get_current() send_store_mail(subject, context={ 'site': site, 'manifests': manifests }, template=("canada_post_dp_shipping/admin/mail/" "manifests_body.txt"), send_to_store=True) def transmit_shipments(queryset=None, send_msg=None): log.info("transmit_shipments invoked") log.debug("queryset: %s", str(queryset)) if send_msg is None: send_msg = lambda x: x if queryset is None: queryset = OrderShippingService.objects.all() from satchmo_store.shop.models import Config
shipping_detail.save() except Shipment.DoesNotExist: log.error("Requested shipment does not exist") manifests.append(manifest) except Exception, e: log.error("Error processing manifest: %s", e, exc_info=True) subject_template = get_template( 'canada_post_dp_shipping/admin/mail/manifests_subject.txt') subject = subject_template.render(Context({ 'manifests': manifests })).strip() site = Site.objects.get_current() send_store_mail(subject, context={ 'site': site, 'manifests': manifests }, template=("canada_post_dp_shipping/admin/mail/" "manifests_body.txt"), send_to_store=True) def transmit_shipments(queryset=None, send_msg=None): log.info("transmit_shipments invoked") log.debug("queryset: %s", str(queryset)) if send_msg is None: send_msg = lambda x: x if queryset is None: queryset = OrderShippingService.objects.all() from satchmo_store.shop.models import Config shop_details = Config.objects.get_current() settings = config_get_group('canada_post_dp_shipping') cpa_kwargs = canada_post_api_kwargs(settings)