diff --git a/emencia/django/newsletter/mailer.py b/emencia/django/newsletter/mailer.py index c02b9d00..aefc3b8d 100644 --- a/emencia/django/newsletter/mailer.py +++ b/emencia/django/newsletter/mailer.py @@ -332,9 +332,12 @@ class NewsLetterSender(object): if obj is not None: logo = getattr(obj, 'logo') if not logo: - return None + logo_path = os.path.join(settings.STATIC_ROOT, 'client/img/no-logo.png') + else: + logo_path = logo.path + try: - ctype, encoding = mimetypes.guess_type(logo.path) + ctype, encoding = mimetypes.guess_type(logo_path) except SuspiciousOperation: return None if ctype is None or encoding is not None: @@ -343,11 +346,11 @@ class NewsLetterSender(object): maintype, subtype = ctype.split('/', 1) try: if resize is not None: - fd = get_thumbnail(logo.path, resize, **kwargs) + fd = get_thumbnail(logo_path, resize, **kwargs) # import pdb; pdb.set_trace() # fd = open(thumb.path, 'rb') else: - fd = open(logo.path, 'rb') + fd = open(logo_path, 'rb') except IOError: return None if maintype == 'image': diff --git a/emencia/django/newsletter/templates/newsletter/AutomaticEmail_web.html b/emencia/django/newsletter/templates/newsletter/AutomaticEmail_web.html index 346da734..d09b1197 100644 --- a/emencia/django/newsletter/templates/newsletter/AutomaticEmail_web.html +++ b/emencia/django/newsletter/templates/newsletter/AutomaticEmail_web.html @@ -131,6 +131,10 @@ {% thumbnail obj.get_logo '281' as im %} + {% empty %} + {% thumbnail no_logo_image '281' as im %} + + {% endthumbnail %} {% endthumbnail %} @@ -204,6 +208,10 @@ {% thumbnail obj.get_logo '109x114' dailymail='russia' hit=obj.expohit as im %} + {% empty %} + {% thumbnail no_logo_image '109x114' dailymail='russia' hit=obj.expohit as im %} + + {% endthumbnail %} {% endthumbnail %} @@ -283,6 +291,10 @@ {% thumbnail obj.get_logo '109x114' dailymail='russia' hit=obj.expohit as im %} + {% empty %} + {% thumbnail no_logo_image '109x114' dailymail='russia' hit=obj.expohit as im %} + + {% endthumbnail %} {% endthumbnail %} @@ -381,6 +393,10 @@ {% thumbnail obj.get_logo '130x130' dailymail='foreign' hit=obj.expohit as im %} + {% empty %} + {% thumbnail no_logo_image '130x130' dailymail='foreign' hit=obj.expohit as im %} + + {% endthumbnail %} {% endthumbnail %} @@ -449,6 +465,10 @@ {% thumbnail news.logo "272" as im %} + {% empty %} + {% thumbnail no_logo_image '272' as im %} + + {% endthumbnail %} {% endthumbnail %} @@ -501,6 +521,10 @@ {% thumbnail blog.logo "272" as im %} + {% empty %} + {% thumbnail no_logo_image '272' as im %} + + {% endthumbnail %} {% endthumbnail %} diff --git a/emencia/django/newsletter/views/admin_views.py b/emencia/django/newsletter/views/admin_views.py index c3974cdf..0685ddd2 100644 --- a/emencia/django/newsletter/views/admin_views.py +++ b/emencia/django/newsletter/views/admin_views.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import os import datetime from django.conf import settings @@ -8,6 +9,7 @@ from django.forms.formsets import formset_factory from django.forms.models import modelformset_factory from django.http import Http404, HttpResponse, HttpResponseRedirect from django.shortcuts import get_object_or_404 +from django.core.files.storage import default_storage from django.utils import translation from django.utils.encoding import force_text from django.utils.translation import ugettext_lazy as _ @@ -86,6 +88,7 @@ class AutomaticEmailTest(ContextMixin, FormView): # 'tracking_image_format': TRACKING_IMAGE_FORMAT, 'uidb36': uidb36, 'token': token, 'name': contact.first_name or contact.last_name or _(u'Подписчик'), + 'no_logo_image': default_storage.open('newsletter/images/no-logo.png'), }) self.extra_ctx.update(contact.get_announce_context_v2(date=form.cleaned_data.get('date'))) return self.form_invalid(form) diff --git a/proj/sorlengine.py b/proj/sorlengine.py index 2a0763ba..490526a2 100644 --- a/proj/sorlengine.py +++ b/proj/sorlengine.py @@ -9,6 +9,7 @@ from sorl.thumbnail.engines.pil_engine import Engine from django.contrib.staticfiles import finders from django.conf import settings +from sorl.thumbnail.conf import settings as solr_settings russia_size = (89, 94) foreign_size = (110, 110) @@ -30,6 +31,9 @@ class SorlEngine(Engine): (thumb.width - image.width) / 2 + image.width, # right (thumb.height - image.height) / 2 + image.height # bottom ) + if image.mode == "P" and 'transparency' in image.info: + image = image.convert('RGBA') + # вставляем if image.mode == "RGBA": # с прозрачностью @@ -50,3 +54,7 @@ class SorlEngine(Engine): 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) + + def write(self, image, options, thumbnail): + options['image_info'] = image.info + super(SorlEngine, self).write(image, options, thumbnail) diff --git a/templates/client/includes/banners/top_head_banner.html b/templates/client/includes/banners/top_head_banner.html index c114c13d..d16ce69a 100644 --- a/templates/client/includes/banners/top_head_banner.html +++ b/templates/client/includes/banners/top_head_banner.html @@ -1,6 +1,6 @@
{% if is_img %} - + {% elif is_html %}