diff --git a/project/customer/admin.py b/project/customer/admin.py index 31b2811..4e36b13 100644 --- a/project/customer/admin.py +++ b/project/customer/admin.py @@ -14,6 +14,8 @@ class LicenseAdmin(admin.ModelAdmin): list_display = ('get_email', 'term', 'status', 'order_date', 'date_from', 'date_to') list_display_links = list_display + search_fields = ('user__email', ) + list_filter = ('status', 'term', 'order_date', 'date_from', 'date_to') #TODO прописать fieldsets # fieldsets = [ diff --git a/project/customer/consts.py b/project/customer/consts.py index 3dde2f5..650503b 100644 --- a/project/customer/consts.py +++ b/project/customer/consts.py @@ -13,7 +13,8 @@ LICENSE_STATUSES = ( (0, u'Не оплачен'), (1, u'Оплачен'), (2, u'Активирован'), - (3, u'Заморожен'), + (3, u'Срок действия истёк'), + (4, u'Заморожен'), ) PAYFORMS = ( diff --git a/project/customer/tasks.py b/project/customer/tasks.py index 3a2a644..1883213 100644 --- a/project/customer/tasks.py +++ b/project/customer/tasks.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -from datetime import datetime +from datetime import datetime, timedelta from celery import shared_task from .models import License, UserProfile @@ -22,6 +22,8 @@ def check_license(): 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) return None diff --git a/project/myauth/emails.py b/project/myauth/emails.py index c878f45..5028834 100644 --- a/project/myauth/emails.py +++ b/project/myauth/emails.py @@ -2,11 +2,13 @@ from django.template.loader import render_to_string from django.core.mail import EmailMessage from django.conf import settings +from celery.decorators import task SUPPORT_EMAIL = getattr(settings, 'SUPPORT_EMAIL', '') +@task def send_registration_email(user_email, confirm_url): """Отправить письмо о регистрации нового пользователя.""" template_name = 'myauth/registration_email.txt' @@ -17,6 +19,7 @@ def send_registration_email(user_email, confirm_url): return email.send() +@task def send_reset_password_email(user_email, confirm_url): """Отправить письмо с ключём для восстановления пароля.""" template_name = 'myauth/reset_key_email.txt' @@ -27,6 +30,7 @@ def send_reset_password_email(user_email, confirm_url): return email.send() +@task def send_new_password_email(user_email, new_password): """Отправить письмо с новым паролем.""" template_name = 'myauth/reset_new_password_email.txt' diff --git a/project/myauth/tasks.py b/project/myauth/tasks.py new file mode 100644 index 0000000..56d16ba --- /dev/null +++ b/project/myauth/tasks.py @@ -0,0 +1 @@ +from emails import send_reset_password_email, send_registration_email, send_new_password_email diff --git a/project/myauth/views.py b/project/myauth/views.py index c116989..4c95998 100644 --- a/project/myauth/views.py +++ b/project/myauth/views.py @@ -16,7 +16,7 @@ from django.conf import settings from project.customer.models import UserProfile, UserProfileFilters, License -from . import forms, models, emails +from . import forms, models, emails REGISTRATION_OPEN = getattr(settings, 'REGISTRATION_OPEN', True) @@ -73,7 +73,7 @@ def register(request): if form.is_valid(): new_user = _create_user(request, **form.cleaned_data) confirm_url = reverse('myauth_confirm_email', args=[new_user.username,]) - emails.send_registration_email(new_user.email, confirm_url) + emails.send_registration_email.delay(new_user.email, confirm_url) messages.add_message(request, messages.INFO, success_msg) return redirect(success_url) else: @@ -123,7 +123,7 @@ def reset(request): user = form.get_user() key = models.ResetKey.objects.create_key(user) confirm_url = reverse('myauth_confirm_reset', args=[key.key,]) - emails.send_reset_password_email(user.email, confirm_url) + emails.send_reset_password_email.delay(user.email, confirm_url) return redirect(success_url) else: form = form_class(prefix=form_prefix) @@ -143,7 +143,7 @@ def confirm_reset(request, key): new_password = User.objects.make_random_password() # новый пароль key.user.set_password(new_password) key.user.save() - emails.send_new_password_email(key.user.email, new_password) + emails.send_new_password_email.delay(key.user.email, new_password) key.delete() # удалить ключ восстановления пароля messages.add_message(request, messages.INFO, success_msg) diff --git a/project/templates/customer/profile/license_list.html b/project/templates/customer/profile/license_list.html index 01748f5..c40d866 100644 --- a/project/templates/customer/profile/license_list.html +++ b/project/templates/customer/profile/license_list.html @@ -19,10 +19,10 @@ {% for license in licenses %}
-
{{ license.id }}
+
{% if license.pay_sum > 0 %}{{ license.id }}{% else %}--{% endif %}
{{ license.order_date }}
{{ license.get_term }}
-
{{ license.pay_sum|get_plural:"рубль,рубля,рублей" }}
+
{% if license.pay_sum > 0 %}{{ license.pay_sum|get_plural:"рубль,рубля,рублей" }}{% else %}Бесплатно{% endif %}
{{ license.get_payform_display }}
{{ license.get_status_display }}
{{ license.get_action_link|safe }}