|
|
|
|
@ -12,6 +12,8 @@ from StringIO import StringIO |
|
|
|
|
from datetime import datetime |
|
|
|
|
from datetime import timedelta |
|
|
|
|
from smtplib import SMTPRecipientsRefused |
|
|
|
|
from pymorphy2 import MorphAnalyzer |
|
|
|
|
morph = MorphAnalyzer() |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
from email.mime.multipart import MIMEMultipart |
|
|
|
|
@ -307,16 +309,27 @@ class NewsLetterSender(object): |
|
|
|
|
|
|
|
|
|
# include preheader |
|
|
|
|
if self.newsletter.preheader: |
|
|
|
|
preheader_ctx = { |
|
|
|
|
'name': contact.first_name or contact.last_name, |
|
|
|
|
'subscribe_themes': ', '.join([self.themes.get(x) for x in contact.contactsettings.theme.all().values_list('pk', flat=True)]), |
|
|
|
|
} |
|
|
|
|
preheader = self.newsletter.preheader.format(**preheader_ctx) |
|
|
|
|
preheader = self.newsletter.preheader.format(**self.build_preheader_ctx(contact)) |
|
|
|
|
preheader_html = render_to_string('newsletter/newsletter_preheader.html', {'preheader': preheader}) |
|
|
|
|
content = body_insertion(content, preheader_html) |
|
|
|
|
|
|
|
|
|
return smart_unicode(content) |
|
|
|
|
|
|
|
|
|
def build_preheader_ctx(self, contact): |
|
|
|
|
t_add = '' |
|
|
|
|
count = contact.contactsettings.theme.count() |
|
|
|
|
if count > 3: |
|
|
|
|
count -= 3 |
|
|
|
|
theme_word = morph.parse(u'тема')[0] |
|
|
|
|
t_add = _(u' и еще {count} {theme_word}').format( |
|
|
|
|
count=count, |
|
|
|
|
theme_word=theme_word.t.make_agree_with_number(count).word, |
|
|
|
|
) |
|
|
|
|
return { |
|
|
|
|
'name': contact.first_name or contact.last_name, |
|
|
|
|
'themes': ', '.join([self.themes.get(x) for x in contact.contactsettings.theme.all().values_list('pk', flat=True)[:3]]) + t_add, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
def update_newsletter_status(self): |
|
|
|
|
"""Update the status of the newsletter""" |
|
|
|
|
if self.test: |
|
|
|
|
|