Beispiel #1
0
def user_win(auction_id):
    from auction.models import Auction, Constant
    translation.activate('uk')

    auction = Auction.objects.get(id=auction_id)

    templates = {
        'banks things': 'auction/email/user_win_bank.html',
        'company things': 'auction/email/user_win.html'
    }
    text = loader.render_to_string(templates[auction.lot.bidding_type], {'auction': auction})

    mail = EmailMultiAlternatives(
        _('User win'), text,
        from_email=Constant.get_value('no_reply'),
        to=[auction.winner.email]
    )

    attach_text = loader.render_to_string(
        'auction/email/protocol_.html', {'auction': auction}
    )

    res = NamedTemporaryFile(delete=False, suffix='.html')
    res.write(attach_text.encode('utf8'))
    res.close()

    mail.attach_file(res.name)
    mail.send()

    os.unlink(res.name)
Beispiel #2
0
def password_recovery(user_id, password):
    from auction.models import Constant
    user = User.objects.get(id=user_id)
    text = loader.render_to_string('auction/email/recovery.html', {'user':user, 'password': password})
    send_mail(
        'Відновленні пароля', message='', html_message=text,
        from_email=Constant.get_value('no_reply'), recipient_list=[user.email],
        fail_silently=False
    )
Beispiel #3
0
def user_approved(user_id):
    from auction.models import Constant
    translation.activate('uk')

    customer = User.objects.get(id=user_id)
    text = loader.render_to_string('auction/email/user_approved.html', {'customer': customer})
    send_mail(
        u'Реєстрацію підтверджено', message='', html_message=text, from_email=Constant.get_value('no_reply'),
        recipient_list=[customer.email], fail_silently=False
    )
Beispiel #4
0
def send_protocol(auction_id):
    from auction.models import Auction, Constant
    translation.activate('uk')

    auction = Auction.objects.get(id=auction_id)
    text = loader.render_to_string('auction/email/protocol.html', {'auction': auction})
    send_mail(
        _('auction finished'), message='', html_message=text, from_email=Constant.get_value('no_reply'),
        recipient_list=[auction.winner], fail_silently=False
    )
Beispiel #5
0
def auction_published(auction_id):
    translation.activate('uk')
    from auction.models import Auction, Constant

    auction = Auction.objects.get(id=auction_id)

    text = loader.render_to_string('auction/email/auction_created.html', {'auction': auction})
    send_mail(
        _('Auction published'), message='', html_message=text, from_email=Constant.get_value('no_reply'),
        recipient_list=[auction.lot.customer.email], fail_silently=False
    )
Beispiel #6
0
def send_not_behavior(auction_id):
    from auction.models import Auction, Constant
    translation.activate('uk')

    auction = Auction.objects.get(id=auction_id)

    text = loader.render_to_string('auction/email/not_behavior.html', {'auction': auction})
    send_mail(
        _('Auction not behavior'), message='', html_message=text,
        from_email=Constant.get_value('no_reply'),
        recipient_list=[auction.lot.customer.email], fail_silently=False
    )
Beispiel #7
0
def spam(auction_id, event):
    from auction.models import Auction
    from auction.models import Constant
    translation.activate('uk')

    auction = Auction.objects.get(id=auction_id)

    templates = {
        'start': {'subject': u'Аукціон розпочато',  'path': 'auction/email/start.html'},
        'not_win': {'subject': u'Аукціон завершено',  'path': 'auction/email/not_win.html',
                    'continue_cond': lambda u: u.id == auction.winner.id},
    }

    continue_cond = templates[event].get('continue_cond')
    for customer in auction.users:
        if continue_cond and continue_cond(customer):
            continue
        text = loader.render_to_string(templates[event]['path'], {'auction': auction, 'customer': customer})
        send_mail(
            templates[event]['subject'], message='', html_message=text, from_email=Constant.get_value('no_reply'),
            recipient_list=[customer.email], fail_silently=False
        )
Beispiel #8
0
def order_changed(order_id):
    from auction.models import Order, Constant
    translation.activate('uk')

    TEMPLATES = {
        Order.WAITING: 'auction/email/order_created.html',
        Order.ACCEPTED: 'auction/email/order_accepted.html',
        Order.DECLINED: 'auction/email/order_declined.html',
    }

    order_instance = Order.objects.get(id=order_id)
    text = loader.render_to_string(TEMPLATES[order_instance.accepted], {'order': order_instance})

    mail = EmailMultiAlternatives(
        u'Статус заяви змінено', text,
        from_email=Constant.get_value('no_reply'),
        to=[order_instance.user.email]
    )
    file_names = []

    if order_instance.accepted == Order.WAITING:
        if order_instance.user.profile.is_phis and order_instance.auction.lot.bidding_type == 'company things':
            file_names = bankrut_fiz(order_instance)
        if order_instance.user.profile.is_phis and order_instance.auction.lot.bidding_type == 'banks things':
            file_names = activ_fiz(order_instance)
        if not order_instance.user.profile.is_phis and order_instance.auction.lot.bidding_type == 'company things':
            file_names = bankrut_jur(order_instance)
        if not order_instance.user.profile.is_phis and order_instance.auction.lot.bidding_type == 'banks things':
            file_names = activ_jur(order_instance)

        for f in file_names:
            mail.attach_file(f)

        mail.attach_file(settings.BASE_DIR + '/auction/pdf_template/dogovor.doc')

    mail.send()
    for f in file_names:
        os.unlink(f)