Merge branch 'feature/new-certs-1-10-19' into 'master'

Feature/new certs 1 10 19

See merge request lilschool/site!424
remotes/origin/feature/ecommerce-gtag^2
Danil 6 years ago
commit 6b1bc7b0ef
  1. 24
      apps/content/views.py
  2. 23
      apps/notification/tasks.py
  3. 28
      apps/notification/templates/notification/email/certificate.html
  4. 2
      apps/school/views.py
  5. 4
      apps/user/models.py
  6. 4
      project/urls.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

@ -50,7 +50,6 @@ 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 = 'user-certificates/%d.jpg'
signed_path_pattern = 'signed-user-certificates/%d.jpg'
if email:
fn = draw_cert(os.path.join(settings.RESOURCES_ROOT, signed_path_pattern % 1), email, 'Имя', 'Фамилия')
@ -83,31 +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 os.path.isfile(os.path.join(settings.RESOURCES_ROOT,
path_pattern % (un.certificate_number + 1))) \
signed_path_pattern % (un.certificate_number + 1))) \
else 1
if un.user.child_filled:
fn = os.path.join(settings.RESOURCES_ROOT, 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(os.path.join(settings.RESOURCES_ROOT, signed_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,
childs=un.user.childs.all(), user_notification=un,
many_childs=un.user.childs.all().count() > 1, child_filled=un.user.child_filled)
except:
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()

@ -1,4 +1,5 @@
{% extends "notification/email/_base.html" %}
{% load settings %}
{% block content %}
<p style="margin: 0 0 20px">Привет!</p>
@ -6,8 +7,8 @@
{% if not user_notification or user_notification.certificate_number == 1 %}
<p>
Поздравляем! Вы прошли месяц обучения в Lil School.<br>
К письму {% if many_childs %}прикреплены грамоты. Распечатайте их и вручите вашим детям.
{% else %}прикреплена грамота. Распечатайте её{% if not child_filled %}, подпишите{% endif %} и вручите вашему ребенку.{% endif %}<br>
В письме {% if many_childs %}ссылки на грамоты. Распечатайте их и вручите вашим детям.
{% else %}ссылка на грамоту. Распечатайте её{% if not child_filled %}, подпишите{% endif %} и вручите вашему ребенку.{% endif %}<br>
Ждём вас в следующем месяце на наших творческих занятиях!
</p>
{% endif %}
@ -20,7 +21,7 @@
{% if user_notification and user_notification.certificate_number == 3 %}
<p>
Вам понравился наш творческий месяц?<br>
В письме вы найдёте {% if many_childs %}грамоты, они{% else %}грамоту, она{% endif %} для вашей семьи.<br>
В письме вы найдёте {% if many_childs %}ссылки на грамоты, они{% else %}ссылку на грамоту, она{% endif %} для вашей семьи.<br>
Как здорово, что у нас есть такие ученики!<br>
Ждём вас в следующем месяце.
</p>
@ -28,17 +29,17 @@
{% if user_notification and user_notification.certificate_number == 4 %}
<p>
Прошёл целый месяц обучения на платформе Lil School - месяц творчества, креатива и невероятных идей.<br>
Во вложении вас {% if many_childs %}ждут грамоты{% else %}ждёт грамота{% endif %}.<br>
Во письме вас {% if many_childs %}ждут ссылки на грамоты{% else %}ждёт ссылка на грамоту{% endif %}.<br>
До встречи на занятиях!
</p>
{% endif %}
{% if user_notification and user_notification.certificate_number == 5 %}
<p>
{% if many_childs %}
Ваши грамоты за успехи в учебе в Lil School ждут вас во вложении.<br>
Ваши грамоты за успехи в учебе в Lil School ждут вас.<br>
Скорее распечатайте их!<br>
{% else %}
Ваша грамота за успехи в учебе в Lil School ждёт вас во вложении.<br>
Ваша грамота за успехи в учебе в Lil School ждёт вас.<br>
Скорее распечатайте её!<br>
{% endif %}
Вам есть чем гордится!<br>
@ -56,7 +57,7 @@
{% if user_notification and user_notification.certificate_number == 7 %}
<p>
Какой классный месяц у нас был! Вместе мы очень здорово и креативно потрудились.<br>
Во вложении вас {% if many_childs %}ждут заслуженные грамоты{% else %}ждёт заслуженная грамота{% endif %}!<br>
В письме вас {% if many_childs %}ждут ссылки на заслуженные грамоты{% else %}ждёт ссылка на заслуженную грамоту{% endif %}!<br>
До встречи на уроках!
</p>
{% endif %}
@ -64,10 +65,21 @@
<p>
Месяц творчества и креатива пролетел как один миг! А как много работ мы вместе сделали!<br>
Вы - большие молодцы.<br>
Во вложении вас {% if many_childs %}ждут грамоты{% else %}ждёт грамота{% endif %}!<br>
В письме вас {% if many_childs %}ждут ссылки на грамоты{% else %}ждёт ссылка на грамоту{% endif %}!<br>
До встречи на занятиях.
</p>
{% endif %}
<p>
{% if many_childs %}
Ссылки на грамоты:<br>
{% for child in childs %}
<a href="{% setting 'MAIN_HOST' %}{% url 'get-certificate' cert=user_notification.certificate_number %}?child={{ child.id }}">Грамота ({{ child.full_name }})</a><br>
{% endfor %}
{% else %}
Ссылка на грамоту:<br>
<a href="{% setting 'MAIN_HOST' %}{% url 'get-certificate' cert=user_notification.certificate_number %}{% if child_filled %}?child={{ childs.0.id }}{% endif %}">Скачать грамоту</a>
{% endif %}
</p>
</div>
<div style="margin-bottom: 10px;">
<p>

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

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

@ -19,7 +19,8 @@ from django.views.generic import TemplateView
from django.urls import path, include
from apps.auth.views import LandingRegistrationView
from apps.content.views import ContestEditView, ContestView, ContestWorkView, contest_work_comment, FAQView
from apps.content.views import ContestEditView, ContestView, ContestWorkView, contest_work_comment, FAQView, \
get_certificate
from apps.course.views import (
CoursesView, likes, coursecomment,
CourseView, LessonView, SearchView,
@ -106,6 +107,7 @@ urlpatterns = [
path('links', LinksView.as_view(), name='links'),
path('prices', PackagesView.as_view(), name='packages'),
path('landing-registration', LandingRegistrationView.as_view(), name='landing-registration'),
path('certificate/<int:cert>/get', get_certificate, name='get-certificate'),
]

Loading…
Cancel
Save