parent
06a500116c
commit
2ea6970fc8
6 changed files with 82 additions and 35 deletions
@ -1,49 +1,81 @@ |
||||
# -*- coding: utf-8 -*- |
||||
from datetime import timedelta |
||||
|
||||
from django.conf import settings |
||||
from django.core.mail import EmailMessage |
||||
from django.template.loader import render_to_string |
||||
|
||||
|
||||
def check_one_profile(profile, License, now): |
||||
SUPPORT_EMAIL = getattr(settings, 'SUPPORT_EMAIL', '') |
||||
|
||||
|
||||
def check_one_profile(profile, License, now, manual=False): |
||||
profile_is_active = profile.active |
||||
licenses = License.objects.filter(user=profile.user, date_from__lte=now, date_to__gte=now, status__in=[-1, 1, 2], deleted=False) |
||||
licenses.filter(status=1).update(status=2) |
||||
|
||||
if licenses: |
||||
profile.active = True |
||||
else: |
||||
profile.active = False |
||||
profile.save() |
||||
licenses.filter(status=1).update(status=2) |
||||
|
||||
licenses = License.objects.filter(user=profile.user, date_to__lt=now, status=2, deleted=False) |
||||
licenses.update(status=3) |
||||
licenses_to_pay = License.objects.filter(user=profile.user, status=0, deleted=False) |
||||
|
||||
if licenses: |
||||
template_name = 'myauth/license_ended.txt' |
||||
subject = u'Документор: срок действия лицензии окончен' |
||||
if profile.active and not profile_is_active: |
||||
template_name = 'myauth/license_activated.txt' |
||||
subject = u'Документор: Профиль активирован' |
||||
dict_context = {'user_email': licenses[0].user, |
||||
'support_email': SUPPORT_EMAIL, |
||||
'license_starts': licenses[0].date_from, |
||||
'license_ends': licenses[0].date_to, |
||||
'licenses_to_pay': licenses_to_pay, |
||||
} |
||||
email_body = render_to_string(template_name, dict_context) |
||||
email = EmailMessage(subject=subject, to=(licenses[0].user.email,), body=email_body) |
||||
email.send() |
||||
|
||||
licenses = License.objects.filter(user=profile.user, date_to=now + timedelta(1), status__in=[-1, 2], deleted=False) |
||||
licenses_remain = License.objects.filter(user=profile.user, date_from__gt=now + timedelta(1), status=1, deleted=False) |
||||
licenses_to_pay = License.objects.filter(user=profile.user, status=0, deleted=False) |
||||
|
||||
if licenses and not licenses_remain: |
||||
template_name = 'myauth/license_ends.txt' |
||||
subject = u'Документор: окончание срока действия лицензии' |
||||
dict_context = {'user_email': licenses[0].user, |
||||
'support_email': SUPPORT_EMAIL, |
||||
'license_ends': licenses[0].date_to, |
||||
'licenses_to_pay': licenses_to_pay, |
||||
} |
||||
email_body = render_to_string(template_name, dict_context) |
||||
email = EmailMessage(subject=subject, to=(licenses[0].user.email,), body=email_body) |
||||
email.send() |
||||
if not licenses_remain and not manual: |
||||
licenses = License.objects.filter(user=profile.user, date_to__lt=now, status__in=[-1, 2], deleted=False) |
||||
licenses.update(status=3) |
||||
|
||||
if licenses: |
||||
template_name = 'myauth/license_ended.txt' |
||||
subject = u'Документор: срок действия лицензии окончен' |
||||
dict_context = {'user_email': licenses[0].user, |
||||
'support_email': SUPPORT_EMAIL, |
||||
'license_ends': licenses[0].date_to, |
||||
'licenses_to_pay': licenses_to_pay, |
||||
} |
||||
email_body = render_to_string(template_name, dict_context) |
||||
email = EmailMessage(subject=subject, to=(licenses[0].user.email,), body=email_body) |
||||
email.send() |
||||
|
||||
licenses = License.objects.filter(user=profile.user, date_to=now + timedelta(1), status__in=[-1, 2], deleted=False) |
||||
|
||||
if licenses: |
||||
template_name = 'myauth/license_ends.txt' |
||||
subject = u'Документор: окончание срока действия лицензии' |
||||
dict_context = {'user_email': licenses[0].user, |
||||
'support_email': SUPPORT_EMAIL, |
||||
'license_ends': licenses[0].date_to, |
||||
'licenses_to_pay': licenses_to_pay, |
||||
} |
||||
email_body = render_to_string(template_name, dict_context) |
||||
email = EmailMessage(subject=subject, to=(licenses[0].user.email,), body=email_body) |
||||
email.send() |
||||
|
||||
if not manual: |
||||
|
||||
licenses = License.objects.filter(user=profile.user, order_date=now - timedelta(9), status=0, deleted=False) |
||||
|
||||
if licenses: |
||||
template_name = 'myauth/license_to_pay.txt' |
||||
subject = u'Документор: есть неоплаченные счета' |
||||
dict_context = {'user_email': licenses[0].user, |
||||
'support_email': SUPPORT_EMAIL, |
||||
} |
||||
email_body = render_to_string(template_name, dict_context) |
||||
email = EmailMessage(subject=subject, to=(licenses[0].user.email,), body=email_body) |
||||
email.send() |
||||
|
||||
|
||||
@ -0,0 +1,9 @@ |
||||
Здравствуйте! |
||||
|
||||
|
||||
Ваш профиль на сайте Документор (http://www.dokumentor.ru) был активирован. |
||||
Срок действия лицензии с {{ license_starts }} по {{ license_ends }}. |
||||
|
||||
Это письмо написано роботом. Отвечать на него не нужно. |
||||
|
||||
Связаться со службой поддержки сайта Документор Вы можете по адресу {{ support_email }} |
||||
@ -0,0 +1,8 @@ |
||||
Здравствуйте! |
||||
|
||||
У вас есть неоплаченный счёт, который можно оплатить до завтра. Через 1 день этот счёт оплатить будет невозможно. |
||||
|
||||
Это письмо написано роботом. Отвечать на него не нужно. |
||||
|
||||
|
||||
Связаться со службой поддержки сайта Документор Вы можете по адресу {{ support_email }} |
||||
Loading…
Reference in new issue