diff --git a/project/customer/models.py b/project/customer/models.py index bb83fa2..0529c8c 100644 --- a/project/customer/models.py +++ b/project/customer/models.py @@ -11,7 +11,7 @@ from django.db.models import Max from django.contrib.auth.models import User from django.core.urlresolvers import reverse -from . import consts, managers +from . import consts, managers, utils PROFILE_IMAGES_UPLOAD_DIR = 'customer/profile/' # куда сохранять загруженные изображения @@ -383,6 +383,7 @@ class License(models.Model): self.user.profile.active = True self.user.profile.save() self.status = 1 + utils.check_one_profile(self.user.profile, License, datetime.now()) super(License, self).save(*args, **kwargs) diff --git a/project/customer/tasks.py b/project/customer/tasks.py index a173f6a..7be84da 100644 --- a/project/customer/tasks.py +++ b/project/customer/tasks.py @@ -3,11 +3,10 @@ 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 +from .utils import check_one_profile SUPPORT_EMAIL = getattr(settings, 'SUPPORT_EMAIL', '') @@ -25,29 +24,7 @@ def check_license(): 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], deleted=False) - 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=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() + check_one_profile(profile, License, now) return None diff --git a/project/customer/utils.py b/project/customer/utils.py new file mode 100644 index 0000000..8a87b6a --- /dev/null +++ b/project/customer/utils.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +from datetime import timedelta +from django.core.mail import EmailMessage +from django.template.loader import render_to_string + + +def check_one_profile(profile, License, now): + 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) + 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'Документор: срок действия лицензии окончен' + 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) + 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() + + diff --git a/project/docs/views/base_views.py b/project/docs/views/base_views.py index bda2406..a948164 100644 --- a/project/docs/views/base_views.py +++ b/project/docs/views/base_views.py @@ -379,6 +379,7 @@ class BaseViews(object): def as_img(self, *args, **kwargs): """Вывести превью документа.""" try: + obj = self.get_obj(kwargs['id']) pdf = self.get_pdf(*args, **kwargs) _, filename = tempfile.mkstemp() @@ -407,6 +408,7 @@ class BaseViews(object): imgs = ['%stmp/%s/%s' % (MEDIA_URL, tmp_dirname, i) for i in imgs] dictionary = { + 'obj': obj, 'images': imgs, 'padeji': self.PADEJI, 'padeji_mnoj': self.PADEJI_MNOJ, diff --git a/project/static/css/style.css b/project/static/css/style.css index 8d8b4c9..0509c12 100644 --- a/project/static/css/style.css +++ b/project/static/css/style.css @@ -214,4 +214,5 @@ div.blockMsg { width: 100%; height: 100%; top: 0; left: 0; text-align: center; } .header {font-weight:bold; } #menu ul li {display:inline;} -.preview {width:1000px;height:500px;overflow:scroll;} +.preview {width:780px;height:500px;overflow:scroll;float:left;} +.list-col2 {float: left; width: 180px; margin-left: 16px; padding: 0 10px 10px 10px; border-left: solid 1px #797979;} diff --git a/project/templates/docs/_base/base_list.html b/project/templates/docs/_base/base_list.html index 2c06a5c..6f0b2a5 100644 --- a/project/templates/docs/_base/base_list.html +++ b/project/templates/docs/_base/base_list.html @@ -78,61 +78,10 @@ -
+
{% for obj in page.object_list %} - {% url url_prefix|add:'edit' id=obj.pk as url_edit %} - {% url url_prefix|add:'copy' id=obj.pk as url_copy %} - {% url url_prefix|add:'delete' id=obj.pk as url_delete %} - {% url url_prefix|add:'email' id=obj.pk as url_email %} - {% url url_prefix|add:'img' id=obj.pk as url_img %} - {% url url_prefix|add:'pdf' id=obj.pk as url_pdf %} - {% url url_prefix|add:'xls' id=obj.pk as url_xls %} - - {% url 'docs_aktrabot_add_by_invoice' invoice_id=obj.pk as url_aktrabot_by_invoice %} - {% url 'docs_nakladn_add_by_invoice' invoice_id=obj.pk as url_nakladn_by_invoice %} - {% url 'docs_faktura_add_by_invoice' invoice_id=obj.pk as url_faktura_by_invoice %} - - + {% include "docs/parts/doc_actions.html" %} {% endfor %} -
Фильтр списка
diff --git a/project/templates/docs/_base/preview.html b/project/templates/docs/_base/preview.html index ff02922..678469d 100644 --- a/project/templates/docs/_base/preview.html +++ b/project/templates/docs/_base/preview.html @@ -1,7 +1,9 @@ {% extends "base.html" %} +
{% block title %}Просмотр {{ padeji.rodit }}{% endblock %} +
{% block content %} {% url url_prefix|add:'list' as url_list %} {% url url_prefix|add:'delete' id=obj.pk as url_delete %} @@ -10,13 +12,16 @@ Вернуться к списку -

Просмотр {{ padeji.rodit }}

+

Просмотр {{ padeji.rodit }}

{% for img in images %} - Страница {{ forloop.conter }} + Страница {{ forloop.counter }} {% endfor %}
+
+ {% include "docs/parts/doc_actions.html" %} +
{% endblock %} diff --git a/project/templates/docs/parts/doc_actions.html b/project/templates/docs/parts/doc_actions.html new file mode 100644 index 0000000..d64710c --- /dev/null +++ b/project/templates/docs/parts/doc_actions.html @@ -0,0 +1,55 @@ + + {% url url_prefix|add:'edit' id=obj.pk as url_edit %} + {% url url_prefix|add:'copy' id=obj.pk as url_copy %} + {% url url_prefix|add:'delete' id=obj.pk as url_delete %} + {% url url_prefix|add:'email' id=obj.pk as url_email %} + {% url url_prefix|add:'img' id=obj.pk as url_img %} + {% url url_prefix|add:'pdf' id=obj.pk as url_pdf %} + {% url url_prefix|add:'xls' id=obj.pk as url_xls %} + + {% url 'docs_aktrabot_add_by_invoice' invoice_id=obj.pk as url_aktrabot_by_invoice %} + {% url 'docs_nakladn_add_by_invoice' invoice_id=obj.pk as url_nakladn_by_invoice %} + {% url 'docs_faktura_add_by_invoice' invoice_id=obj.pk as url_faktura_by_invoice %} + +
+
Скачать
+ +
+ + {% if not images %} + + Предпросмотр документаПредпросмотр {{ padeji.rodit }}
+
+ {% endif %} + + Документ в PDFДокумент в PDF
+
+ + Документ в ExcelДокумент в Excel
+ +
+
Создать
+ +
+ + {% block panel_copy %} + Копию {{ padeji.rodit }}
+
+ + {% block panel_copy_extra %}{% endblock %} + {% endblock %} + +
+ +
+ +
+ + РедактироватьРедактировать
+ +
+ + УдалитьУдалить
+
+ diff --git a/project/templates/myauth/license_ended.txt b/project/templates/myauth/license_ended.txt new file mode 100644 index 0000000..4f916b6 --- /dev/null +++ b/project/templates/myauth/license_ended.txt @@ -0,0 +1,7 @@ +Здравствуйте! + +Закончилось действие вашего аккаунта на сайте Документор (http://www.dokumentor.ru). Вы не сможете создавать новые документы. {% if licenses_to_pay %}У Вас есть неоплаченные счета, которые можно оплатить, чтобы продлить действие услуги.{% else %}Чтобы продлить действие услуги, войдите в свой профиль и приобретите лицензию на дальнейшее пользование сайтом.{% endif %} + +Это письмо написано роботом. Отвечать на него не нужно. + +Связаться со службой поддержки сайта Документор Вы можете по адресу {{ support_email }}