1462: Этап №5: Рассылка - Гео фильтры

Переписана генерация контекста для анонсов.
remotes/origin/stage5
Alexander Burdeiny 10 years ago
parent 2b9f071d77
commit 9fad05e86a
  1. 4
      emencia/django/newsletter/mailer.py
  2. 66
      emencia/django/newsletter/models.py
  3. 48
      emencia/django/newsletter/templates/newsletter/announce_template.html

@ -469,10 +469,10 @@ class Mailer(NewsLetterSender):
if self.announce:
# check if events for this newsletter exists
announce_context = contact.get_announce_context()
if not announce_context:
send = False
else:
announce_context = None
if not announce_context:
send = False
try:
# pass

@ -6,20 +6,21 @@ from datetime import timedelta
from email.MIMEImage import MIMEImage
import copy
from django.core.mail import EmailMessage
from django.core.validators import MaxValueValidator, MinValueValidator
from django.template import Context
from django.db import models
from django.contrib.sites.models import Site
from django.conf import settings
from django.db.models import Q
from django.utils.encoding import smart_str
from django.core.urlresolvers import reverse
from django.utils.encoding import force_unicode
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from django.core.mail import EmailMessage
from django.core.validators import MaxValueValidator, MinValueValidator
from django.core.urlresolvers import reverse
from django.contrib.sites.models import Site
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import Group
from django.utils.encoding import force_unicode
from django.template.loader import render_to_string, get_template
from django.template import Context
from emencia.django.newsletter.managers import ContactManager
@ -155,38 +156,55 @@ class Contact(models.Model):
def get_announce_context(self):
from exposition.models import Exposition
from conference.models import Conference
from article.models import Article
from django.utils.translation import activate
activate('ru')
events = Exposition.enable.upcoming()
expo = Exposition.enable.upcoming()
conf = Conference.enable.upcoming()
themes = list(self.contactsettings.theme.all())
try:
country = self.contactsettings.country.all()[0]
except IndexError:
country = None
if themes:
theme_ids = [item.id for item in themes]
events = events.filter(theme__in=theme_ids)
else:
return None
if country:
events = events.filter(country=country)
events = list(events[:5])
# making query
params = Q()
countries = self.contactsettings.country.all().values_list('pk', flat=True)
if countries:
params |= Q(country__in=countries)
cities = self.contactsettings.city.all().values_list('pk', flat=True)
if cities:
params |= Q(country__in=cities)
if events:
context = {'themes': themes, 'place': country, 'events': events}
if themes:
theme_ids = set([item.id for item in themes])
params &= Q(theme__in=theme_ids)
expo = list(expo.filter(params)[:5])
conf = list(conf.filter(params)[:5])
if expo or conf:
context = {
'themes': themes,
'expo': expo,
'conf': conf,
}
if expo:
context['expo_places'] = ', '.join(set([x.country.inflect for x in expo]))
if conf:
context['conf_places'] = ', '.join(set([x.country.inflect for x in conf]))
else:
# no events for announce
return None
news = list(Article.objects.news()
.filter(publish_date__gt=datetime.now()-timedelta(days=30), theme__in=theme_ids)
.filter(publish_date__gt=datetime.now()-timedelta(days=7), theme__in=theme_ids)
.distinct()[:3])
if news:
context['news'] = news
blogs = list(Article.objects.blogs()[:1])
blogs = list(Article.objects.blogs()
.filter(publish_date__gt=datetime.now()-timedelta(days=7))
.distinct()[:3])
if blogs:
context['blogs'] = blogs
return context

@ -33,10 +33,10 @@
{# end header #}
{# events #}
{% with events=events %}
{% with events=expo place=expo_places %}
<table cellpadding="0" cellspacing="0" border="0" width="600" style="width: 600px; margin-bottom: 10px;">
<tr>
<td style="padding: 20px 0 0;"><a style="display: block; padding: 25px 30px; text-decoration: none; background: #ff6600; color: #ffffff; font-size: 20px; line-height: 26px;" href="/expo/search/?{% for th in themes %}th={{ th.id }}&{% endfor %}{% if place %}co={{ place.id }}&{% endif %}">{% trans "Выставки" %}{% if place %} {{ place.inflect }}{% endif %} {% if themes|length == 1 %}{% trans "по тематике" %}:<b style="display: block; font-size: 26px;">{{ themes.0.name }}</b>{% endif %}</a></td>
<td style="padding: 20px 0 0;"><a style="display: block; padding: 25px 30px; text-decoration: none; background: #ff6600; color: #ffffff; font-size: 20px; line-height: 26px;" href="/expo/search/?{% for th in themes %}th={{ th.id }}&{% endfor %}{% if place %}co={{ place.id }}&{% endif %}">{% trans "Выставки" %} {{ place }} {% if themes|length == 1 %}{% trans "по тематике" %}:<b style="display: block; font-size: 26px;">{{ themes.0.name }}</b>{% endif %}</a></td>
</tr>
<tr>
<td style="padding: 10px 30px 15px; background: #faf9f7;">
@ -75,6 +75,49 @@
{% endwith %}
{# end events #}
{# conferencies #}
{% with events=conf place=conf_places %}
<table cellpadding="0" cellspacing="0" border="0" width="600" style="width: 600px; margin-bottom: 10px;">
<tr>
<td style="padding: 20px 0 0;"><a style="display: block; padding: 25px 30px; text-decoration: none; background: #ff6600; color: #ffffff; font-size: 20px; line-height: 26px;" href="/expo/search/?{% for th in themes %}th={{ th.id }}&{% endfor %}{% if place %}co={{ place.id }}&{% endif %}">{% trans "Конференции" %} {{ place }} {% if themes|length == 1 %}{% trans "по тематике" %}:<b style="display: block; font-size: 26px;">{{ themes.0.name }}</b>{% endif %}</a></td>
</tr>
<tr>
<td style="padding: 10px 30px 15px; background: #faf9f7;">
<table cellpadding="0" cellspacing="0" border="0" width="540" style="margin-bottom: 15px;">
{% for event in events %}
<tr valign="top">
<td style="padding: 15px 15px 15px 0; width: 76px; border-bottom: 1px dotted #cccccc;">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="background: #ffffff; padding: 3px; width: 70px; height: 70px; vertical-align: middle; text-align: center; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px;"><a href="http://{{ domain }}{{ event.get_permanent_url }}"><img src="cid:mail_expo_logo_{{ event.id }}" style="width: 100%;" alt="" /></a></td>
</tr>
</table>
</td>
<td style="padding: 15px 15px 15px 0; border-bottom: 1px dotted #cccccc;">
<h2 style="margin: 0 0 5px; font-family: Tahoma, Arial, sans-serif; font-size: 18px; line-height: 21px;"><a style="color: #464646; text-decoration: none;" href="http://{{ domain }}{{ event.get_permanent_url }}">{{ event.name }}</a></h2>
<p style="margin: 0 0 7px; font-size: 12px; line-height: 15px; color: #a2a2a2"><a style="color: #a2a2a2; text-decoration: none;" href="http://{{ domain }}{{ event.get_permanent_url }}">{{ event.main_title|safe }}</a></p>
<a class="button" style="display: inline-block; padding: 4px 10px 3px; text-decoration: none; color: #ff6600; font-size: 11px; font-weight: bold; line-height: 14px; border: 1px solid #feb17d; text-transform: uppercase; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px;" href="http://{{ domain }}{{ event.get_permanent_url }}">{% trans "добавить в расписание" %}</a>
<div class="addr" style="margin-top: 10px; font-size: 13px; line-height: 15px;"><img src="cid:pin" width="10" height="15" alt="" style="vertical-align: middle; margin-top: -1px;" /> {{ event.country.name }}, {{ event.city.name }}{% if event.place %}, {{ event.place.name }}{% endif %}</div>
</td>
<td style="padding: 17px 0; text-align: right; font-size: 13px; line-height: 16px; color: #ff6600; width: 140px; border-bottom: 1px dotted #cccccc;">
<img src="cid:clock" width="14" height="15" style="vertical-align: middle; margin-top: -1px;" alt="" /> {% include 'client/includes/show_date_block.html' with obj=event %}
</td>
</tr>
{% endfor %}
</table>
<div class="more" style="text-align: center;">
<a class="button" style="display: inline-block; padding: 4px 10px 3px; text-decoration: none; color: #2592c5; font-size: 11px; font-weight: bold; line-height: 14px; border: 1px solid #90c7e0; text-transform: uppercase; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; width: 336px;" href="/expo/search/?{% for th in themes %}th={{ th.id }}&{% endfor %}{% if place %}co={{ place.id }}&{% endif %}">{% trans "посмотреть все события" %}</a>
</div>
</td>
</tr>
</table>
{% endwith %}
{# end conferencies #}
{% if news %}
<table cellpadding="0" cellspacing="0" border="0" width="600" style="width: 600px; margin-bottom: 10px;">
<tr>
@ -117,6 +160,7 @@
</tr>
</table>
{% endif %}
{% if blogs %}
<table cellpadding="0" cellspacing="0" border="0" width="600" style="width: 600px; margin-bottom: 10px;">
<tr>

Loading…
Cancel
Save