несолько детей

remotes/origin/feature/childs-11-06-19
gzbender 7 years ago
parent 26888f35b9
commit f6e50efb84
  1. 80
      apps/notification/tasks.py
  2. 4
      apps/notification/templates/notification/email/camp_certificate.html
  3. 25
      apps/notification/templates/notification/email/certificate.html
  4. 29
      apps/user/migrations/0034_auto_20190612_1852.py
  5. 3
      apps/user/models.py
  6. 8
      web/src/sass/_common.sass

@ -3,12 +3,14 @@ from datetime import datetime, date, timedelta
from PIL import Image from PIL import Image
from PIL import ImageFont from PIL import ImageFont
from PIL import ImageDraw from PIL import ImageDraw
from unidecode import unidecode
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.contrib.staticfiles.storage import staticfiles_storage from django.contrib.staticfiles.storage import staticfiles_storage
from django.utils.timezone import now from django.utils.timezone import now
from django.conf import settings from django.conf import settings
from django.utils.text import slugify
from apps.notification.models import UserNotification from apps.notification.models import UserNotification
from apps.notification.utils import send_email from apps.notification.utils import send_email
@ -16,6 +18,7 @@ from apps.payment.models import SchoolPayment, CoursePayment, Payment, UserGiftC
from project.celery import app from project.celery import app
from project.utils.db import format_sql, execute_sql from project.utils.db import format_sql, execute_sql
from project.sengrid import get_sendgrid_client from project.sengrid import get_sendgrid_client
from apps.user.models import Child
User = get_user_model() User = get_user_model()
@ -36,7 +39,11 @@ def draw_cert(path, email, first_name, last_name, x=None, y=900, color=(29, 115,
os.mkdir(fn) os.mkdir(fn)
except: except:
pass pass
fn = os.path.join(fn, '%scertificate-for-%s.jpg' % (fn_prefix, email)) if first_name:
name = '-'.join(filter(None, [first_name, last_name]))
fn = os.path.join(fn, '%scertificate-for-%s-%s.jpg' % (fn_prefix, email, slugify(unidecode(name))))
else:
fn = os.path.join(fn, '%scertificate-for-%s.jpg' % (fn_prefix, email))
img.save(fn) img.save(fn)
img.close() img.close()
return fn return fn
@ -76,25 +83,30 @@ def send_certificates(email=None, date_end=None, dry_run=False):
if dry_run: if dry_run:
continue continue
file_names = []
un.certificate_number = un.certificate_number + 1 \ 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 staticfiles_storage.exists(path_pattern % (un.certificate_number + 1)) \
else 1 else 1
if un.user.child_first_name: if un.user.child_filled:
fn = staticfiles_storage.path(signed_path_pattern % un.certificate_number) fn = staticfiles_storage.path(signed_path_pattern % un.certificate_number)
fn = draw_cert(fn, un.user.email, un.user.child_first_name, un.user.child_last_name) for child in un.user.childs.all():
file_names.append(draw_cert(fn, un.user.email, child.first_name, child.last_name))
else: else:
fn = staticfiles_storage.path(path_pattern % un.certificate_number) file_names.append(staticfiles_storage.path(path_pattern % un.certificate_number))
file = open(fn, 'rb') files = [open(fn, 'rb') for fn in file_names]
try: try:
send_email('Грамота от Lil School', un.user.email, 'notification/email/certificate.html', send_email('Грамота от Lil School', un.user.email, 'notification/email/certificate.html',
attachments=[(file.name, file.read(), 'image/jpeg')], user_notification=un) attachments=[(f.name, f.read(), 'image/jpeg') for f in files], user_notification=un,
many_childs=un.user.childs.all().count() > 1)
except: except:
print('Not OK') print('Not OK')
continue continue
finally: finally:
file.close() for f in files:
if un.user.child_first_name: f.close()
os.remove(fn) if un.user.child_filled:
for fn in file_names:
os.remove(fn)
un.certificate_last_email = now() un.certificate_last_email = now()
un.save() un.save()
@ -148,19 +160,20 @@ def send_gift_certificate(user_gift_certificate):
@app.task @app.task
def send_child_birthday_email_and_bonuses(): def send_child_birthday_email_and_bonuses():
for u in User.objects.exclude(child_first_name='', child_last_name='',).filter(child_birthday=now().date()): for user_id, email in set(Child.objects.filter(birthday=now().date()).select_related('user')
if not UserBonus.objects.filter(user=u, is_service=True, action_name=UserBonus.ACTION_CHILD_BIRTHDAY).count(): .values_list('user_id', 'user__email')):
print('user', u.email) print('user', email)
UserBonus.objects.create(user=u, amount=UserBonus.AMOUNT_CHILD_BIRTHDAY, is_service=True, if not UserBonus.objects.filter(user=user_id, is_service=True, action_name=UserBonus.ACTION_CHILD_BIRTHDAY).count():
UserBonus.objects.create(user=user_id, amount=UserBonus.AMOUNT_CHILD_BIRTHDAY, is_service=True,
action_name=UserBonus.ACTION_CHILD_BIRTHDAY) action_name=UserBonus.ACTION_CHILD_BIRTHDAY)
try: try:
fn = staticfiles_storage.path('img/birthday_postcard.jpg') fn = staticfiles_storage.path('img/birthday_postcard.jpg')
file = open(fn, 'rb') file = open(fn, 'rb')
send_email('С Днем Рождения!', u.email, 'notification/email/birthday_postcard.html', send_email('С Днем Рождения!', email, 'notification/email/birthday_postcard.html',
attachments=[(file.name, file.read(), 'image/jpeg')],) attachments=[(file.name, file.read(), 'image/jpeg')],)
print('email has been sent') print('email has been sent')
finally: finally:
file.close() file.close()
@app.task @app.task
def send_camp_certificates(email=None, dry_run=False, certificate_number=None): def send_camp_certificates(email=None, dry_run=False, certificate_number=None):
@ -178,7 +191,6 @@ def send_camp_certificates(email=None, dry_run=False, certificate_number=None):
font_size=120, y=1000, color=color) font_size=120, y=1000, color=color)
file = open(fn, 'rb') file = open(fn, 'rb')
try: try:
pass
send_email('Грамота от Lil School', email, 'notification/email/camp_certificate.html', send_email('Грамота от Lil School', email, 'notification/email/camp_certificate.html',
attachments=[(file.name, file.read(), 'image/jpeg')], certificate_number=certificate_number) attachments=[(file.name, file.read(), 'image/jpeg')], certificate_number=certificate_number)
except: except:
@ -205,23 +217,27 @@ def send_camp_certificates(email=None, dry_run=False, certificate_number=None):
if dry_run: if dry_run:
continue continue
if un.user.child_first_name: file_names = []
if un.user.child_filled:
fn = staticfiles_storage.path(signed_path_pattern % certificate_number) fn = staticfiles_storage.path(signed_path_pattern % certificate_number)
fn = draw_cert(fn, un.user.email, un.user.child_first_name, un.user.child_last_name, for child in un.user.childs.all():
font_size=120, y=1000, color=color) file_names.append(draw_cert(fn, un.user.email, child.first_name, child.last_name,
font_size=120, y=1000, color=color))
else: else:
fn = staticfiles_storage.path(path_pattern % certificate_number) file_names.append(staticfiles_storage.path(path_pattern % certificate_number))
file = open(fn, 'rb') files = [open(fn, 'rb') for fn in file_names]
try: try:
send_email('Грамота от Lil School', un.user.email, 'notification/email/camp_certificate.html', send_email('Грамота от Lil School', un.user.email, 'notification/email/camp_certificate.html',
attachments=[(file.name, file.read(), 'image/jpeg')], user_notification=un, attachments=[(f.name, f.read(), 'image/jpeg') for f in files], user_notification=un,
certificate_number=certificate_number) certificate_number=certificate_number, many_childs=un.user.childs.all().count() > 1)
except: except:
print('Not OK') print('Not OK')
continue continue
finally: finally:
file.close() for f in files:
if un.user.child_first_name: f.close()
os.remove(fn) if un.user.child_filled:
for fn in file_names:
os.remove(fn)
un.camp_certificate_last_email = date_end un.camp_certificate_last_email = date_end
un.save() un.save()

@ -6,13 +6,13 @@
{% if certificate_number == 1 %} {% if certificate_number == 1 %}
<p> <p>
Поздравляем! Вы прошли месяц обучения в лагере Lil School.<br> Поздравляем! Вы прошли месяц обучения в лагере Lil School.<br>
К письму прикреплена грамота. Распечатайте её и вручите вашим детям.<br> К письму {% if many_childs %}прикреплены грамоты. Распечатайте их{% else %}прикреплена грамота. Распечатайте её{% endif %} и вручите вашим детям.<br>
Ждём вас в следующем месяце на наших творческих занятиях! Ждём вас в следующем месяце на наших творческих занятиях!
</p> </p>
{% endif %} {% endif %}
{% if certificate_number == 2 %} {% if certificate_number == 2 %}
<p> <p>
Вы помните, что каждый месяц вам приходит грамота за прекрасную учебу в рсиовальном лагере?<br> Вы помните, что каждый месяц вам {% if many_childs %}приходят грамоты{% else %}приходит грамота{% endif %} за прекрасную учебу в рисовальном лагере?<br>
Скачивайте. Распечатывайте. И соберите свою коллекцию! Скачивайте. Распечатывайте. И соберите свою коллекцию!
</p> </p>
{% endif %} {% endif %}

@ -6,20 +6,20 @@
{% if not user_notification or user_notification.certificate_number == 1 %} {% if not user_notification or user_notification.certificate_number == 1 %}
<p> <p>
Поздравляем! Вы прошли месяц обучения в Lil School.<br> Поздравляем! Вы прошли месяц обучения в Lil School.<br>
К письму прикреплена грамота. Распечатайте её и вручите вашим детям.<br> К письму {% if many_childs %}прикреплены грамоты. Распечатайте их{% else %}прикреплена грамота. Распечатайте её{% endif %} и вручите вашим детям.<br>
Ждём вас в следующем месяце на наших творческих занятиях! Ждём вас в следующем месяце на наших творческих занятиях!
</p> </p>
{% endif %} {% endif %}
{% if user_notification and user_notification.certificate_number == 2 %} {% if user_notification and user_notification.certificate_number == 2 %}
<p> <p>
Вы помните, что каждый месяц вам приходит грамота за прекрасную учебу в нашей творческой школе?<br> Вы помните, что каждый месяц вам {% if many_childs %}приходят грамоты{% else %}приходит грамота{% endif %} за прекрасную учебу в нашей творческой школе?<br>
Скачивайте. Распечатывайте. И соберите свою коллекцию! Скачивайте. Распечатывайте. И соберите свою коллекцию!
</p> </p>
{% endif %} {% endif %}
{% if user_notification and user_notification.certificate_number == 3 %} {% if user_notification and user_notification.certificate_number == 3 %}
<p> <p>
Вам понравился наш творческий месяц?<br> Вам понравился наш творческий месяц?<br>
В письме вы найдёте грамоту, она для вашей семьи.<br> В письме вы найдёте {% if many_childs %}грамоты, они{% else %}грамоту, она{% endif %} для вашей семьи.<br>
Как здорово, что у нас есть такие ученики!<br> Как здорово, что у нас есть такие ученики!<br>
Ждём вас в следующем месяце. Ждём вас в следующем месяце.
</p> </p>
@ -27,22 +27,27 @@
{% if user_notification and user_notification.certificate_number == 4 %} {% if user_notification and user_notification.certificate_number == 4 %}
<p> <p>
Прошёл целый месяц обучения на платформе Lil School - месяц творчества, креатива и невероятных идей.<br> Прошёл целый месяц обучения на платформе Lil School - месяц творчества, креатива и невероятных идей.<br>
Во вложении вас ждёт грамота.<br> Во вложении вас {% if many_childs %}ждут грамоты{% else %}ждёт грамота{% endif %}.<br>
До встречи на занятиях! До встречи на занятиях!
</p> </p>
{% endif %} {% endif %}
{% if user_notification and user_notification.certificate_number == 5 %} {% if user_notification and user_notification.certificate_number == 5 %}
<p> <p>
{% if many_childs %}
Ваши грамоты за успехи в учебе в Lil School ждут вас во вложении.<br>
Скорее распечатайте их!<br>
{% else %}
Ваша грамота за успехи в учебе в Lil School ждёт вас во вложении.<br> Ваша грамота за успехи в учебе в Lil School ждёт вас во вложении.<br>
Скорее распечатайте её!<br> Скорее распечатайте её!<br>
Вам есть чем гордится!<br> {% endif %}
До встречи в следующем месяце! Вам есть чем гордится!<br>
До встречи в следующем месяце!
</p> </p>
{% endif %} {% endif %}
{% if user_notification and user_notification.certificate_number == 6 %} {% if user_notification and user_notification.certificate_number == 6 %}
<p> <p>
Как здорово вы потрудились на занятиях в этом месяце!<br> Как здорово вы потрудились на занятиях в этом месяце!<br>
И наша грамота уже ждёт вас!<br> И {% if many_childs %}наши грамоты уже ждут{% else %}наша грамота уже ждёт{% endif %} вас!<br>
Спасибо за творчество и креатив.<br> Спасибо за творчество и креатив.<br>
Ждём вас в следующем месяце! Ждём вас в следующем месяце!
</p> </p>
@ -50,7 +55,7 @@
{% if user_notification and user_notification.certificate_number == 7 %} {% if user_notification and user_notification.certificate_number == 7 %}
<p> <p>
Какой классный месяц у нас был! Вместе мы очень здорово и креативно потрудились.<br> Какой классный месяц у нас был! Вместе мы очень здорово и креативно потрудились.<br>
Во вложении вас ждёт заслуженная грамота!<br> Во вложении вас {% if many_childs %}ждут заслуженные грамоты{% else %}ждёт заслуженная грамота{% endif %}!<br>
До встречи на уроках! До встречи на уроках!
</p> </p>
{% endif %} {% endif %}
@ -58,7 +63,7 @@
<p> <p>
Месяц творчества и креатива пролетел как один миг! А как много работ мы вместе сделали!<br> Месяц творчества и креатива пролетел как один миг! А как много работ мы вместе сделали!<br>
Вы - большие молодцы.<br> Вы - большие молодцы.<br>
Во вложении ваш ждёт грамота!<br> Во вложении вас {% if many_childs %}ждут грамоты{% else %}ждёт грамота{% endif %}!<br>
До встречи на занятиях. До встречи на занятиях.
</p> </p>
{% endif %} {% endif %}

@ -0,0 +1,29 @@
# Generated by Django 2.0.7 on 2019-06-12 18:52
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('user', '0033_add_childs'),
]
operations = [
migrations.RemoveField(
model_name='user',
name='child_birthday',
),
migrations.RemoveField(
model_name='user',
name='child_first_name',
),
migrations.RemoveField(
model_name='user',
name='child_gender',
),
migrations.RemoveField(
model_name='user',
name='child_last_name',
),
]

@ -357,3 +357,6 @@ class Child(models.Model):
gender = models.CharField( gender = models.CharField(
'Пол ребенка', max_length=1, default='n', choices=GENDER_CHOICES) 'Пол ребенка', max_length=1, default='n', choices=GENDER_CHOICES)
birthday = models.DateField('День рождения ребенка', null=True, blank=True) birthday = models.DateField('День рождения ребенка', null=True, blank=True)
class Meta:
ordering = ('id',)

@ -4705,6 +4705,14 @@ a
border-radius: 20px border-radius: 20px
box-shadow: 0 10px 24px 0 rgba(0, 0, 0, 0.05) box-shadow: 0 10px 24px 0 rgba(0, 0, 0, 0.05)
+t
margin: 30px -80px 30px -60px
+m
background: white
margin: 30px -80px 30px -60px
padding: 30px 80px 40px 60px
&__description &__description
margin-bottom: 40px margin-bottom: 40px
margin-top: -20px margin-top: -20px

Loading…
Cancel
Save