|
|
|
@ -25,9 +25,9 @@ def draw_cert(path, email, first_name, last_name): |
|
|
|
img = Image.open(path) |
|
|
|
img = Image.open(path) |
|
|
|
draw = ImageDraw.Draw(img) |
|
|
|
draw = ImageDraw.Draw(img) |
|
|
|
font = ImageFont.truetype(os.path.join(settings.STATIC_ROOT, 'ProximaNova-Reg.otf'), 170) |
|
|
|
font = ImageFont.truetype(os.path.join(settings.STATIC_ROOT, 'ProximaNova-Reg.otf'), 170) |
|
|
|
text = first_name |
|
|
|
text = first_name.capitalize() |
|
|
|
if last_name: |
|
|
|
if last_name: |
|
|
|
text += ' ' + last_name |
|
|
|
text += ' ' + last_name.capitalize() |
|
|
|
w, h = draw.textsize(text, font=font) |
|
|
|
w, h = draw.textsize(text, font=font) |
|
|
|
draw.text(((img.width - w) // 2, 900), text, (29, 115, 224), font=font) |
|
|
|
draw.text(((img.width - w) // 2, 900), text, (29, 115, 224), font=font) |
|
|
|
fn = os.path.join(settings.MEDIA_ROOT, 'tmp') |
|
|
|
fn = os.path.join(settings.MEDIA_ROOT, 'tmp') |
|
|
|
@ -43,8 +43,9 @@ def draw_cert(path, email, first_name, last_name): |
|
|
|
@app.task |
|
|
|
@app.task |
|
|
|
def send_certificates(email=None, date=None, dry_run=False): |
|
|
|
def send_certificates(email=None, date=None, dry_run=False): |
|
|
|
path_pattern = 'img/user-certificates/%d.jpg' |
|
|
|
path_pattern = 'img/user-certificates/%d.jpg' |
|
|
|
|
|
|
|
signed_path_pattern = 'img/signed-user-certificates/%d.jpg' |
|
|
|
if email: |
|
|
|
if email: |
|
|
|
fn = draw_cert(staticfiles_storage.path(path_pattern % 1), email, 'Имя', 'Фамилия') |
|
|
|
fn = draw_cert(staticfiles_storage.path(signed_path_pattern % 1), email, 'Имя', 'Фамилия') |
|
|
|
file = open(fn, 'rb') |
|
|
|
file = open(fn, 'rb') |
|
|
|
try: |
|
|
|
try: |
|
|
|
send_email('Грамота от Lil School', email, 'notification/email/certificate.html', |
|
|
|
send_email('Грамота от Lil School', email, 'notification/email/certificate.html', |
|
|
|
@ -77,9 +78,11 @@ def send_certificates(email=None, date=None, dry_run=False): |
|
|
|
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 |
|
|
|
fn = staticfiles_storage.path(path_pattern % un.certificate_number) |
|
|
|
|
|
|
|
if un.user.child_first_name: |
|
|
|
if un.user.child_first_name: |
|
|
|
|
|
|
|
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) |
|
|
|
fn = draw_cert(fn, un.user.email, un.user.child_first_name, un.user.child_last_name) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
fn = staticfiles_storage.path(path_pattern % un.certificate_number) |
|
|
|
file = open(fn, 'rb') |
|
|
|
file = open(fn, 'rb') |
|
|
|
try: |
|
|
|
try: |
|
|
|
send_email('Грамота от Lil School', un.user.email, 'notification/email/certificate.html', |
|
|
|
send_email('Грамота от Lil School', un.user.email, 'notification/email/certificate.html', |
|
|
|
|