diff --git a/project/customer/tasks.py b/project/customer/tasks.py index 1883213..a173f6a 100644 --- a/project/customer/tasks.py +++ b/project/customer/tasks.py @@ -2,17 +2,30 @@ from __future__ import absolute_import from datetime import datetime, timedelta +from django.conf import settings +from django.template.loader import render_to_string +from django.core.mail import EmailMessage + from celery import shared_task from .models import License, UserProfile +SUPPORT_EMAIL = getattr(settings, 'SUPPORT_EMAIL', '') + + @shared_task def check_license(): profiles = UserProfile.objects.all() now = datetime.now() + licenses = License.objects.filter(date_to__lt=now, status__in=[-1, 2], deleted=False) + licenses.update(status=3) + + licenses = License.objects.filter(order_date__lt=now - timedelta(10), status=0, deleted=False) + licenses.update(status=4) + for profile in profiles: - licenses = License.objects.filter(user=profile.user, date_from__lte=now, date_to__gte=now, status__in=[-1, 1, 2]) + licenses = License.objects.filter(user=profile.user, date_from__lte=now, date_to__gte=now, status__in=[-1, 1, 2], deleted=False) if licenses: profile.active = True else: @@ -20,10 +33,21 @@ def check_license(): profile.save() licenses.filter(status=1).update(status=2) - licenses = License.objects.filter(user=profile.user, date_to__lt=now, status__in=[-1, 2]) - licenses.update(status=3) - licenses = License.objects.filter(user=profile.user, order_date__lt=now - timedelta(10), status=0) - licenses.update(status=4) + 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) + return email.send() return None diff --git a/project/customer/views/license.py b/project/customer/views/license.py index 9935884..860f209 100644 --- a/project/customer/views/license.py +++ b/project/customer/views/license.py @@ -70,7 +70,7 @@ def paid_list(request): """ template_name = 'customer/profile/paid_list.html' licenses = License.objects.filter(user=request.user, - status__in=[-1, 1, 2, 3], deleted=False).order_by('-id') + status__in=[-1, 1, 2, 3, 4], deleted=False).order_by('-id') dictionary = { 'licenses': licenses, } diff --git a/project/static/css/style.css b/project/static/css/style.css index caaad46..3978f94 100644 --- a/project/static/css/style.css +++ b/project/static/css/style.css @@ -212,3 +212,5 @@ div.blockMsg { width: 100%; height: 100%; top: 0; left: 0; text-align: center; } .w100 {width:100px;min-height:5px;} .w200 {width:200px;min-height:5px;} .header {font-weight:bold; } + +#menu ul li {display:inline;} diff --git a/project/templates/base.html b/project/templates/base.html index c0ee793..09f03a2 100644 --- a/project/templates/base.html +++ b/project/templates/base.html @@ -1,5 +1,5 @@ {# spaceless #} -{% load cms_tags sekizai_tags %} +{% load cms_tags sekizai_tags menu_tags %} @@ -25,7 +25,13 @@
Документор - {% static_placeholder "phone" %} + {% static_placeholder "header_phone" %} + {% static_placeholder "header_address" %} +
+ {% if user.is_authenticated %} diff --git a/project/templates/cms/menu/main.html b/project/templates/cms/menu/main.html new file mode 100644 index 0000000..89e9311 --- /dev/null +++ b/project/templates/cms/menu/main.html @@ -0,0 +1,10 @@ +{% load cms_tags %} +{% for child in children %} +
  • + {% if child.selected %} + {{ child.get_menu_title }} + {% else %} + {{ child.get_menu_title }} + {% endif %} +
  • +{% endfor %} \ No newline at end of file diff --git a/project/templates/customer/profile/paid_list.html b/project/templates/customer/profile/paid_list.html index 3f5ae6d..a67805c 100644 --- a/project/templates/customer/profile/paid_list.html +++ b/project/templates/customer/profile/paid_list.html @@ -18,11 +18,11 @@
    {% for license in licenses %}
    -
    {{ license.paid_date|default:license.date_from }}
    -
    {{ license.id }}
    -
    {{ license.pay_sum }}
    +
    {{ license.paid_date|default:'-' }}
    +
    {% if license.pay_sum %}{{ license.id }}{% else %}-{% endif %}
    +
    {% if license.pay_sum %}{{ license.pay_sum }}{% else %}-{% endif %}
    {{ license.get_term }}
    -
    {{ license.date_from }} - {{ license.date_to }}
    +
    {% if license.date_from %}{{ license.date_from }} - {{ license.date_to }}{% else %}-{% endif %}
    {{ license.get_status_display }}
    {{ license.get_paid_status|default:'' }}
    Разные документы
    diff --git a/project/templates/myauth/license_ends.txt b/project/templates/myauth/license_ends.txt new file mode 100644 index 0000000..9fb20e3 --- /dev/null +++ b/project/templates/myauth/license_ends.txt @@ -0,0 +1,7 @@ +Здравствуйте! + +Через 1 день заканчивается действие вашего аккаунта на сайте Документор (http://www.dokumentor.ru). Вы не сможете создавать новые документы. {% if licenses_to_pay %}У Вас есть неоплаченные счета, которые можно оплатить, чтобы продлить действие услуги.{% else %}Чтобы продлить действие услуги, войдите в свой профиль и приобретите лицензию на дальнейшее пользование сайтом.{% endif %} + +Это письмо написано роботом. Отвечать на него не нужно. + +Связаться со службой поддержки сайта Документор Вы можете по адресу {{ support_email }}