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

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

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

@ -6,20 +6,20 @@
{% if not user_notification or user_notification.certificate_number == 1 %}
<p>
Поздравляем! Вы прошли месяц обучения в Lil School.<br>
К письму прикреплена грамота. Распечатайте её и вручите вашим детям.<br>
К письму {% if many_childs %}прикреплены грамоты. Распечатайте их{% else %}прикреплена грамота. Распечатайте её{% endif %} и вручите вашим детям.<br>
Ждём вас в следующем месяце на наших творческих занятиях!
</p>
{% endif %}
{% if user_notification and user_notification.certificate_number == 2 %}
<p>
Вы помните, что каждый месяц вам приходит грамота за прекрасную учебу в нашей творческой школе?<br>
Вы помните, что каждый месяц вам {% if many_childs %}приходят грамоты{% else %}приходит грамота{% endif %} за прекрасную учебу в нашей творческой школе?<br>
Скачивайте. Распечатывайте. И соберите свою коллекцию!
</p>
{% endif %}
{% if user_notification and user_notification.certificate_number == 3 %}
<p>
Вам понравился наш творческий месяц?<br>
В письме вы найдёте грамоту, она для вашей семьи.<br>
В письме вы найдёте {% if many_childs %}грамоты, они{% else %}грамоту, она{% endif %} для вашей семьи.<br>
Как здорово, что у нас есть такие ученики!<br>
Ждём вас в следующем месяце.
</p>
@ -27,22 +27,27 @@
{% if user_notification and user_notification.certificate_number == 4 %}
<p>
Прошёл целый месяц обучения на платформе Lil School - месяц творчества, креатива и невероятных идей.<br>
Во вложении вас ждёт грамота.<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>
Скорее распечатайте их!<br>
{% else %}
Ваша грамота за успехи в учебе в Lil School ждёт вас во вложении.<br>
Скорее распечатайте её!<br>
Вам есть чем гордится!<br>
До встречи в следующем месяце!
Скорее распечатайте её!<br>
{% endif %}
Вам есть чем гордится!<br>
До встречи в следующем месяце!
</p>
{% endif %}
{% if user_notification and user_notification.certificate_number == 6 %}
<p>
Как здорово вы потрудились на занятиях в этом месяце!<br>
И наша грамота уже ждёт вас!<br>
И {% if many_childs %}наши грамоты уже ждут{% else %}наша грамота уже ждёт{% endif %} вас!<br>
Спасибо за творчество и креатив.<br>
Ждём вас в следующем месяце!
</p>
@ -50,7 +55,7 @@
{% if user_notification and user_notification.certificate_number == 7 %}
<p>
Какой классный месяц у нас был! Вместе мы очень здорово и креативно потрудились.<br>
Во вложении вас ждёт заслуженная грамота!<br>
Во вложении вас {% if many_childs %}ждут заслуженные грамоты{% else %}ждёт заслуженная грамота{% endif %}!<br>
До встречи на уроках!
</p>
{% endif %}
@ -58,7 +63,7 @@
<p>
Месяц творчества и креатива пролетел как один миг! А как много работ мы вместе сделали!<br>
Вы - большие молодцы.<br>
Во вложении ваш ждёт грамота!<br>
Во вложении вас {% if many_childs %}ждут грамоты{% else %}ждёт грамота{% endif %}!<br>
До встречи на занятиях.
</p>
{% 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(
'Пол ребенка', max_length=1, default='n', choices=GENDER_CHOICES)
birthday = models.DateField('День рождения ребенка', null=True, blank=True)
class Meta:
ordering = ('id',)

@ -4705,6 +4705,14 @@ a
border-radius: 20px
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
margin-bottom: 40px
margin-top: -20px

Loading…
Cancel
Save