예제 #1
0
파일: views.py 프로젝트: komsihon/Project2
def render_product_event(event, request):
    try:
        product = Product.objects.get(pk=event.object_id)
    except Product.DoesNotExist:
        return ''
    html_template = get_template('kako/events/product_notice.html')
    context = {'event': event, 'product': product}
    context.update(currencies(request))
    c = Context(context)
    return html_template.render(c)
예제 #2
0
파일: utils.py 프로젝트: komsihon/Project8
def render_suggest_payment_template(request, media):
    config = get_service_instance().config
    html_template = get_template('movies/snippets/suggest_payment.html')
    if isinstance(media, SeriesEpisode):
        media = media.series
        media.type = 'series'
    try:
        CURRENCY = currencies(request)['CURRENCY']
    except:
        CURRENCY = None
    d = Context({
        'media':
        media,
        'config':
        config,
        'choose_temp_bundle_url':
        "%s?media_type=%s&media_id=%s" %
        (reverse('sales:choose_temp_bundle'), media.type, media.id),
        'CURRENCY':
        CURRENCY
    })
    return html_template.render(d)
예제 #3
0
def send_order_confirmation_email(request, subject, buyer_name, buyer_email, dara, order, message=None,
                                  reward_pack_list=None):
    service = get_service_instance()
    coupon_count = 0
    if reward_pack_list:
        template_name = 'shopping/mails/order_notice_with_reward.html'
        for pack in reward_pack_list:
            coupon_count += pack.count
    else:
        template_name = 'playground/mails/order_notice.html'
    # invitation_url = 'https://daraja.ikwen.com/daraja/companies/'
    invitation_url = 'https://daraja.ikwen.com/'
    crcy = currencies(request)['CURRENCY']
    sender = 'Daraja Playground <*****@*****.**>'
    extra_context = {'buyer_name': buyer_name, 'order': order, 'message': message,
                     'IS_BANK': getattr(settings, 'IS_BANK', False),
                     'coupon_count': coupon_count, 'crcy': crcy, 'dara': dara}
    if dara:
        extra_context['invitation_url'] = invitation_url
    html_content = get_mail_content(subject, template_name=template_name, extra_context=extra_context)

    msg = XEmailMessage(subject, html_content, sender, [buyer_email])
    bcc = [email.strip() for email in service.config.notification_email.split(',') if email.strip()]
    delcom = order.delivery_option.company
    if service != delcom:
        db = delcom.database
        add_database(db)
        try:
            delcom_config = OperatorProfile.objects.using(db).get(service=delcom)
            bcc += [email.strip() for email in delcom_config.notification_email.split(',') if email.strip()]
            bcc.append(delcom.member.email)
        except:
            pass
    bcc.append(service.member.email)
    msg.bcc = list(set(bcc))
    msg.content_subtype = "html"
    Thread(target=lambda m: m.send(), args=(msg,)).start()
예제 #4
0
파일: utils.py 프로젝트: W1773ND/Afrobit
def send_order_confirmation_email(request, subject, buyer_name, buyer_email, order, media_order=None, message=None,
                                  reward_pack_list=None):
    service = get_service_instance()
    coupon_count = 0
    if reward_pack_list:
        template_name = 'shopping/mails/order_notice_with_reward.html'
        for pack in reward_pack_list:
            coupon_count += pack.count
    else:
        template_name = 'shopping/mails/order_notice.html'

    with transaction.atomic(using=WALLETS_DB_ALIAS):
        try:
            crcy = currencies(request)['CURRENCY']
            html_content = get_mail_content(subject, template_name=template_name,
                                            extra_context={'buyer_name': buyer_name, 'order': order, 'message': message,
                                                           'IS_BANK': getattr(settings, 'IS_BANK', False),
                                                           'coupon_count': coupon_count, 'crcy': crcy})
            sender = '%s <no-reply@%s>' % (service.project_name, service.domain)
            msg = XEmailMessage(subject, html_content, sender, [buyer_email])
            bcc = [email.strip() for email in service.config.notification_email.split(',') if email.strip()]
            delcom = order.delivery_option.company
            if service != delcom:
                db = delcom.database
                add_database(db)
                try:
                    delcom_config = OperatorProfile.objects.using(db).get(service=delcom)
                    bcc += [email.strip() for email in delcom_config.notification_email.split(',') if email.strip()]
                    bcc.append(delcom.member.email)
                except:
                    pass
            bcc.append(service.member.email)
            msg.bcc = list(set(bcc))
            msg.content_subtype = "html"
            Thread(target=lambda m: m.send(), args=(msg,)).start()
        except:
            logger.error("%s - Failed to send order confirmation email." % service, exc_info=True)
예제 #5
0
파일: views.py 프로젝트: kiranHR/Project1
 def after_save(self, request, obj, *args, **kwargs):
     object_id = kwargs.get('object_id')
     if object_id:
         return
     number = get_next_invoice_number()
     months_count = get_billing_cycle_months_count(obj.billing_cycle)
     try:
         amount = float(request.POST.get('amount'))
     except:
         amount = obj.monthly_cost * months_count
     product = obj.product
     if product:
         short_description = product.name
     else:
         short_description = request.POST.get('short_description', '---')
     obj.details = short_description
     obj.save()
     invoice_entries = []
     item = InvoiceItem(label=_('Subscription'), amount=amount)
     entry = InvoiceEntry(item=item,
                          short_description=short_description,
                          quantity=months_count,
                          total=amount)
     invoice_entries.append(entry)
     invoice = Invoice.objects.create(number=number,
                                      subscription=obj,
                                      amount=amount,
                                      months_count=months_count,
                                      due_date=obj.expiry,
                                      entries=invoice_entries,
                                      is_one_off=True)
     email = request.POST.get('email')
     member_id = request.POST.get('member_id')
     if member_id:
         member = Member.objects.get(pk=member_id) if member_id else None
     elif email:
         try:
             member = Member.objects.filter(email=email)[0]
         except:
             member = Member.objects.create_user(email,
                                                 DEFAULT_GHOST_PWD,
                                                 email=email,
                                                 is_ghost=True)
     else:
         return
     obj.member = member
     obj.save()
     service = get_service_instance()
     config = service.config
     with transaction.atomic(using=WALLETS_DB_ALIAS):
         from echo.models import Balance
         from echo.utils import notify_for_low_messaging_credit, LOW_MAIL_LIMIT, notify_for_empty_messaging_credit
         balance, update = Balance.objects.using(
             WALLETS_DB_ALIAS).get_or_create(service_id=service.id)
         if 0 < balance.mail_count < LOW_MAIL_LIMIT:
             try:
                 notify_for_low_messaging_credit(service, balance)
             except:
                 logger.error(
                     "Failed to notify %s for low messaging credit." %
                     service,
                     exc_info=True)
         if balance.mail_count == 0 and not getattr(settings,
                                                    'UNIT_TESTING', False):
             try:
                 notify_for_empty_messaging_credit(service, balance)
             except:
                 logger.error(
                     "Failed to notify %s for empty messaging credit." %
                     service,
                     exc_info=True)
             return
         if product:
             subject = _("Your invoice for subscription to %s" %
                         product.name)
         else:
             if short_description != '---':
                 subject = _("Your invoice for " + short_description)
             else:
                 subject = _("Your invoice for subscription")
         try:
             currency = currencies(request)['CURRENCY'].symbol
         except:
             currency = config.currency_symbol
         invoice_url = service.url + reverse('billing:invoice_detail',
                                             args=(invoice.id, ))
         html_content = get_mail_content(
             subject,
             template_name='billing/mails/notice.html',
             extra_context={
                 'invoice': invoice,
                 'member_name': member.first_name,
                 'invoice_url': invoice_url,
                 'cta': _("Pay now"),
                 'currency': currency
             })
         sender = '%s <no-reply@%s>' % (config.company_name, service.domain)
         msg = XEmailMessage(subject, html_content, sender, [email])
         msg.content_subtype = "html"
         balance.mail_count -= 1
         balance.save()
         if getattr(settings, 'UNIT_TESTING', False):
             msg.send()
         else:
             Thread(target=lambda m: m.send(), args=(msg, )).start()