diff --git a/apps/auth/forms.py b/apps/auth/forms.py index f9017dcb..5b644e87 100644 --- a/apps/auth/forms.py +++ b/apps/auth/forms.py @@ -12,4 +12,4 @@ class LearnerRegistrationForm(forms.Form): class LandingRegistrationForm(forms.Form): name = forms.CharField(required=True) email = forms.EmailField(required=True) - phone = PhoneNumberField(required=True) + phone = forms.CharField(required=True) diff --git a/apps/auth/views.py b/apps/auth/views.py index 34a6eb3f..f670d883 100644 --- a/apps/auth/views.py +++ b/apps/auth/views.py @@ -255,13 +255,13 @@ class LandingRegistrationView(View): name = form.cleaned_data['name'].split() email = form.cleaned_data['email'].lower() - if User.objects.filter(Q(email=email) | Q(phone=phone)).count(): + if User.objects.filter(email=email).count(): return redirect('/p/user-exists') user = User( username=email, email=email, - phone=phone, + phone2=phone, ) user.first_name = name[0] if len(name) > 1: diff --git a/apps/content/views.py b/apps/content/views.py index 4bb8e9fa..2838acc4 100644 --- a/apps/content/views.py +++ b/apps/content/views.py @@ -1,5 +1,8 @@ +import os + +from django.conf import settings from django.contrib.auth.decorators import login_required -from django.http import JsonResponse +from django.http import JsonResponse, HttpResponse from django.shortcuts import get_object_or_404 from django.template import loader from django.utils.decorators import method_decorator @@ -9,6 +12,7 @@ from django.views.generic import TemplateView, DetailView from apps.content.models import Contest, ContestWork, FAQ from apps.course.models import ContestWorkComment +from apps.user.models import Child @method_decorator(login_required, name='dispatch') @@ -124,3 +128,21 @@ class FAQView(TemplateView): } for f in FAQ.objects.all()] return self.render_to_response(context) +from apps.notification.tasks import draw_cert + +@csrf_exempt +def get_certificate(request, cert): + signed_path_pattern = 'signed-user-certificates/%d.jpg' + fn = signed_path_pattern % cert + path = os.path.join(settings.RESOURCES_ROOT, fn) + child_id = request.GET.get('child') + if child_id: + child = get_object_or_404(Child, pk=child_id) + path = draw_cert(path, child.user.email, child.first_name, child.last_name) + f = open(path, 'rb') + response = HttpResponse(f, content_type='image/jpeg') + response['Content-Disposition'] = 'attachment; filename=%s' % fn + f.close() + if child_id: + os.remove(path) + return response diff --git a/apps/notification/tasks.py b/apps/notification/tasks.py index 7b582035..8251b128 100644 --- a/apps/notification/tasks.py +++ b/apps/notification/tasks.py @@ -50,10 +50,9 @@ def draw_cert(path, email, first_name, last_name, x=None, y=900, color=(29, 115, @app.task def send_certificates(email=None, date_end=None, dry_run=False): - path_pattern = 'img/user-certificates/%d.jpg' - signed_path_pattern = 'img/signed-user-certificates/%d.jpg' + signed_path_pattern = 'signed-user-certificates/%d.jpg' if email: - fn = draw_cert(staticfiles_storage.path(signed_path_pattern % 1), email, 'Имя', 'Фамилия') + fn = draw_cert(os.path.join(settings.RESOURCES_ROOT, signed_path_pattern % 1), email, 'Имя', 'Фамилия') file = open(fn, 'rb') try: send_email('Грамота от Lil School', email, 'notification/email/certificate.html', @@ -83,30 +82,19 @@ def send_certificates(email=None, date_end=None, dry_run=False): if dry_run: continue - file_names = [] un.certificate_number = un.certificate_number + 1 \ - if un.certificate_number and staticfiles_storage.exists(path_pattern % (un.certificate_number + 1)) \ + if un.certificate_number and os.path.isfile(os.path.join(settings.RESOURCES_ROOT, + signed_path_pattern % (un.certificate_number + 1))) \ else 1 - if un.user.child_filled: - fn = staticfiles_storage.path(signed_path_pattern % un.certificate_number) - for child in un.user.childs.all(): - file_names.append(draw_cert(fn, un.user.email, child.first_name, child.last_name)) - else: - file_names.append(staticfiles_storage.path(path_pattern % un.certificate_number)) - files = [open(fn, 'rb') for fn in file_names] + un.save() try: send_email('Грамота от Lil School', un.user.email, 'notification/email/certificate.html', - attachments=[(f.name, f.read(), 'image/jpeg') for f in files], user_notification=un, - many_childs=un.user.childs.all().count() > 1) - except: + childs=un.user.childs.all(), user_notification=un, + many_childs=un.user.childs.all().count() > 1, child_filled=un.user.child_filled) + except Exception as e: print('Not OK') + print(e) continue - finally: - for f in files: - f.close() - if un.user.child_filled: - for fn in file_names: - os.remove(fn) un.certificate_last_email = now() un.save() diff --git a/apps/notification/templates/notification/email/certificate.html b/apps/notification/templates/notification/email/certificate.html index 277817e0..9b396841 100644 --- a/apps/notification/templates/notification/email/certificate.html +++ b/apps/notification/templates/notification/email/certificate.html @@ -1,4 +1,5 @@ {% extends "notification/email/_base.html" %} +{% load settings %} {% block content %}
Привет!
@@ -6,7 +7,8 @@ {% if not user_notification or user_notification.certificate_number == 1 %}
Поздравляем! Вы прошли месяц обучения в Lil School.
-К письму {% if many_childs %}прикреплены грамоты. Распечатайте их{% else %}прикреплена грамота. Распечатайте её{% endif %} и вручите вашим детям.
+В письме {% if many_childs %}ссылки на грамоты. Распечатайте их и вручите вашим детям.
+ {% else %}ссылка на грамоту. Распечатайте её{% if not child_filled %}, подпишите{% endif %} и вручите вашему ребенку.{% endif %}
Ждём вас в следующем месяце на наших творческих занятиях!
Вам понравился наш творческий месяц?
-В письме вы найдёте {% if many_childs %}грамоты, они{% else %}грамоту, она{% endif %} для вашей семьи.
+В письме вы найдёте {% if many_childs %}ссылки на грамоты, они{% else %}ссылку на грамоту, она{% endif %} для вашей семьи.
Как здорово, что у нас есть такие ученики!
Ждём вас в следующем месяце.
Прошёл целый месяц обучения на платформе Lil School - месяц творчества, креатива и невероятных идей.
-Во вложении вас {% if many_childs %}ждут грамоты{% else %}ждёт грамота{% endif %}.
+Во письме вас {% if many_childs %}ждут ссылки на грамоты{% else %}ждёт ссылка на грамоту{% endif %}.
До встречи на занятиях!
{% if many_childs %}
- Ваши грамоты за успехи в учебе в Lil School ждут вас во вложении.
+ Ваши грамоты за успехи в учебе в Lil School ждут вас.
Скорее распечатайте их!
{% else %}
- Ваша грамота за успехи в учебе в Lil School ждёт вас во вложении.
+ Ваша грамота за успехи в учебе в Lil School ждёт вас.
Скорее распечатайте её!
{% endif %}
Вам есть чем гордится!
@@ -55,7 +57,7 @@
{% if user_notification and user_notification.certificate_number == 7 %}
Какой классный месяц у нас был! Вместе мы очень здорово и креативно потрудились.
-Во вложении вас {% if many_childs %}ждут заслуженные грамоты{% else %}ждёт заслуженная грамота{% endif %}!
+В письме вас {% if many_childs %}ждут ссылки на заслуженные грамоты{% else %}ждёт ссылка на заслуженную грамоту{% endif %}!
До встречи на уроках!
Месяц творчества и креатива пролетел как один миг! А как много работ мы вместе сделали!
Вы - большие молодцы.
-Во вложении вас {% if many_childs %}ждут грамоты{% else %}ждёт грамота{% endif %}!
+В письме вас {% if many_childs %}ждут ссылки на грамоты{% else %}ждёт ссылка на грамоту{% endif %}!
До встречи на занятиях.
+ {% if many_childs %}
+ Ссылки на грамоты:
+ {% for child in childs %}
+ Грамота ({{ child.full_name }})
+ {% endfor %}
+ {% else %}
+ Ссылка на грамоту:
+ Скачать грамоту
+ {% endif %}
+
diff --git a/apps/school/views.py b/apps/school/views.py index a5621682..f2b407ed 100644 --- a/apps/school/views.py +++ b/apps/school/views.py @@ -114,7 +114,7 @@ class LiveLessonsDetailView(DetailView): user=request.user, date_start__lte=now(), date_end__gte=now() - timedelta(days=30), - package__duration__lte=9, + package__duration=12, ).exists() if not is_purchased and request.user.role not in [User.ADMIN_ROLE, User.TEACHER_ROLE]: raise Http404 diff --git a/apps/user/migrations/0035_auto_20191002_1857.py b/apps/user/migrations/0035_auto_20191002_1857.py new file mode 100644 index 00000000..150ffa23 --- /dev/null +++ b/apps/user/migrations/0035_auto_20191002_1857.py @@ -0,0 +1,19 @@ +# Generated by Django 2.0.7 on 2019-10-02 18:57 + +from django.db import migrations, models +import project.utils.db + + +class Migration(migrations.Migration): + + dependencies = [ + ('user', '0034_auto_20190612_1852'), + ] + + operations = [ + migrations.AddField( + model_name='user', + name='phone2', + field=models.CharField(blank=True, max_length=20, null=True), + ), + ] diff --git a/apps/user/models.py b/apps/user/models.py index f12a2755..ad4b31fd 100644 --- a/apps/user/models.py +++ b/apps/user/models.py @@ -59,6 +59,7 @@ class User(AbstractUser): ) email = models.EmailField(_('email address'), unique=True) phone = PhoneNumberField(null=True, blank=True, unique=True) + phone2 = models.CharField(max_length=20, null=True, blank=True) role = models.PositiveSmallIntegerField( 'Роль', default=0, choices=ROLE_CHOICES) gender = models.CharField( @@ -379,3 +380,7 @@ class Child(models.Model): class Meta: ordering = ('id',) + + @property + def full_name(self): + return ' '.join([self.first_name, self.last_name]) if self.last_name else self.first_name diff --git a/project/context_processors.py b/project/context_processors.py index 2ac5769e..cd2f0140 100644 --- a/project/context_processors.py +++ b/project/context_processors.py @@ -2,7 +2,6 @@ from django.db.models import Func, F from django.utils.timezone import now from paymentwall.pingback import Pingback from django.contrib.auth import get_user_model -from django.conf import settings from apps.config.models import Config from apps.content.models import Banner from apps.payment.models import SchoolPayment @@ -55,4 +54,5 @@ def referrer(request): def settings(request): + from django.conf import settings return {'settings': settings} diff --git a/project/settings.py b/project/settings.py index c06e3a55..76dde627 100644 --- a/project/settings.py +++ b/project/settings.py @@ -329,7 +329,7 @@ CELERY_BEAT_SCHEDULE = { }, 'send_certificates': { 'task': 'apps.notification.tasks.send_certificates', - 'schedule': crontab(minute=0, hour=19), + 'schedule': crontab(minute=00, hour=20), 'args': (), }, 'sendgrid_update_recipients': { diff --git a/project/templates/lilcity/index.html b/project/templates/lilcity/index.html index 8c918a26..783964ff 100644 --- a/project/templates/lilcity/index.html +++ b/project/templates/lilcity/index.html @@ -33,35 +33,12 @@ {% include 'templates/blocks/lil_store_js.html' %} {% block pre_app_js %}{% endblock pre_app_js %} - - {% comment %} ROISTAT {% endcomment %} - - - - {% block foot_js %}{% endblock foot_js %} {% endblock layer_body %} diff --git a/project/templates/lilcity/layer.html b/project/templates/lilcity/layer.html index 34915139..50245a19 100644 --- a/project/templates/lilcity/layer.html +++ b/project/templates/lilcity/layer.html @@ -47,70 +47,39 @@ } } - + {% if settings.DEV_SERVER or settings.DEBUG %} + + + + {% else %} + + + + {% endif %} {% block layer_head %}{% endblock layer_head %}
{% block layer_body %} {% endblock layer_body %} - - - - - - - - - - - - {% include "templates/blocks/mixpanel.html" %} + {% if settings.DEV_SERVER or settings.DEBUG %} + + + + {% else %} + + + + {% endif %}