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 @@