dailymail special images done

remotes/origin/stage6
Alexander Burdeinyi 9 years ago
parent 1e753eec6b
commit 29f80b3f64
  1. 6
      emencia/django/newsletter/mailer.py
  2. 6
      emencia/django/newsletter/templates/newsletter/AutomaticEmail_web.html
  3. 49
      proj/sorlengine.py
  4. BIN
      static/newsletter/images/dailymail_foreign_background.png
  5. BIN
      static/newsletter/images/dailymail_russia_background.png
  6. BIN
      static/newsletter/images/hitmark.png
  7. 2
      support/d_dev/settings.py
  8. 2
      support/dev/settings.py
  9. 2
      support/prod/settings.py

@ -264,7 +264,7 @@ class NewsLetterSender(object):
resize = context_attachments_size.get(section)
for event in objects:
prefix = '{}_{}_'.format(section, event.object.event_type)
msg_attachment = self.gen_attachment_logo(event.object, prefix=prefix, resize=resize)
msg_attachment = self.gen_attachment_logo(event.object, prefix=prefix, resize=resize, dailymail=section)
if msg_attachment:
attachments.append(msg_attachment)
return attachments
@ -328,7 +328,7 @@ class NewsLetterSender(object):
message_attachment.add_header('Content-ID', '<{}>'.format(cid))
return message_attachment
def gen_attachment_logo(self, obj=None, prefix='logo_', resize=None, logo=None):
def gen_attachment_logo(self, obj=None, prefix='logo_', resize=None, logo=None, **kwargs):
if obj is not None:
logo = getattr(obj, 'logo')
if not logo:
@ -343,7 +343,7 @@ class NewsLetterSender(object):
maintype, subtype = ctype.split('/', 1)
try:
if resize is not None:
fd = get_thumbnail(logo.path, resize)
fd = get_thumbnail(logo.path, resize, **kwargs)
# import pdb; pdb.set_trace()
# fd = open(thumb.path, 'rb')
else:

@ -202,7 +202,7 @@
<tr {% if not forloop.last %}style="border-bottom: 1px solid #eaeaea;"{% endif %}>
<td valign="top" style="width: 110px;">
<a href="http://{{ domain }}{{ obj.get_permanent_url }}" class="event_image">
{% thumbnail obj.get_logo '90x90' as im %}
{% thumbnail obj.get_logo '109x114' dailymail='russia' hit=obj.expohit as im %}
<img style="" src="{{ im.url }}"/>
{% endthumbnail %}
</a>
@ -281,7 +281,7 @@
<tr {% if not forloop.last %}style="border-bottom: 1px solid #eaeaea;"{% endif %}>
<td valign="top" style="width: 110px;">
<a href="https://{{ domain }}{{ obj.get_permanent_url }}" class="event_image">
{% thumbnail obj.get_logo '100x100' as im %}
{% thumbnail obj.get_logo '109x114' dailymail='russia' hit=obj.expohit as im %}
<img src="{{ im.url }}"/>
{% endthumbnail %}
</a>
@ -379,7 +379,7 @@
<tr>
<td style="padding-bottom: 15px; text-align: center;">
<a href="http://{{ domain }}{{ obj.get_permanent_url }}" class="foreign_image">
{% thumbnail obj.get_logo '120x120' as im %}
{% thumbnail obj.get_logo '130x130' dailymail='foreign' hit=obj.expohit as im %}
<img src="{{ im.url }}"/>
{% endthumbnail %}
</a>

@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
"""
Sorl Thumbnail Engine that create special mailing thumbnails
"""
from PIL import Image # , ImageColor
from sorl.thumbnail.engines.pil_engine import Engine
from django.contrib.staticfiles import finders
russia_size = (89, 94)
foreign_size = (110, 110)
russia_background = finders.find('newsletter/images/dailymail_russia_background.png')
foreign_background = finders.find('newsletter/images/dailymail_foreign_background.png')
hit_mark = finders.find('newsletter/images/hitmark.png')
class SorlEngine(Engine):
def create_dailymail_thumb(self, image, size, background, hit=False):
# берем фон
thumb = Image.open(background)
# берем ресайз картинки
image.thumbnail(size, resample=4)
# считаем положение
box = (
(thumb.width - image.width) / 2, # left
(thumb.height - image.height) / 2, # top
(thumb.width - image.width) / 2 + image.width, # right
(thumb.height - image.height) / 2 + image.height # bottom
)
# вставляем
if image.mode == "RGBA":
# с прозрачностью
thumb.paste(image, box, image)
else:
# без
thumb.paste(image, box)
# вставляем отметку "ХИТ"
if hit:
hit_mark_image = Image.open(hit_mark)
thumb.paste(hit_mark_image, (0, 0), hit_mark_image)
return thumb
def create(self, image, geometry, options):
if options.get('dailymail') in ['russia', 'moscow']:
return self.create_dailymail_thumb(image, russia_size, russia_background, options.get('hit', False))
if options.get('dailymail') == 'foreign':
return self.create_dailymail_thumb(image, foreign_size, foreign_background, options.get('hit', False))
return super(SorlEngine, self).create(image, geometry, options)

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

@ -475,6 +475,8 @@ LOGGING = {
"""
THUMBNAIL_DEBUG = DEBUG
THUMBNAIL_ENGINE = "proj.sorlengine.SorlEngine"
THUMBNAIL_FORMAT = "PNG"
CALLBACK_EMAIL = 'kotzilla@ukr.net'

@ -474,6 +474,8 @@ LOGGING = {
"""
THUMBNAIL_DEBUG = DEBUG
THUMBNAIL_ENGINE = "proj.sorlengine.SorlEngine"
THUMBNAIL_FORMAT = "PNG"
CALLBACK_EMAIL = 'kotzilla@ukr.net'

@ -473,6 +473,8 @@ LOGGING = {
"""
THUMBNAIL_DEBUG = DEBUG
THUMBNAIL_ENGINE = "proj.sorlengine.SorlEngine"
THUMBNAIL_FORMAT = "PNG"
CALLBACK_EMAIL = 'kotzilla@ukr.net'

Loading…
Cancel
Save