Fix news mailing
This commit is contained in:
parent
3d030c91fe
commit
6c47fb404b
|
|
@ -19,20 +19,24 @@ def send_email_with_news(news_ids):
|
|||
.prefetch_related('subscription_type')
|
||||
sent_news = models.News.objects.filter(id__in=news_ids)
|
||||
|
||||
htmly = get_template(settings.NEWS_EMAIL_TEMPLATE)
|
||||
html_template = get_template(settings.NEWS_EMAIL_TEMPLATE)
|
||||
year = datetime.now().year
|
||||
|
||||
socials = list(SiteSettings.objects.with_country().select_related('country'))
|
||||
socials = dict(zip(map(lambda social: social.country.code, socials), socials))
|
||||
|
||||
for subscribe in subscribes.filter(unsubscribe_date=None):
|
||||
subscriber = subscribe.subscriber
|
||||
|
||||
country = subscribe.subscription_type.country
|
||||
|
||||
if country is None:
|
||||
continue
|
||||
country_code = subscriber.country_code
|
||||
|
||||
socials_for_subscriber = socials.get(country.code)
|
||||
subscriber = subscribe.subscriber
|
||||
else:
|
||||
country_code = country.code
|
||||
|
||||
socials_for_subscriber = socials.get(country_code)
|
||||
|
||||
try:
|
||||
for new in sent_news:
|
||||
|
|
@ -52,9 +56,12 @@ def send_email_with_news(news_ids):
|
|||
"year": year
|
||||
}
|
||||
send_mail(
|
||||
"G&M News", render_to_string(settings.NEWS_EMAIL_TEMPLATE, context),
|
||||
settings.EMAIL_HOST_USER, [subscriber.send_to], fail_silently=False,
|
||||
html_message=htmly.render(context)
|
||||
subject="G&M News",
|
||||
message=render_to_string(settings.NEWS_EMAIL_TEMPLATE, context),
|
||||
from_email=settings.EMAIL_HOST_USER,
|
||||
recipient_list=[subscriber.send_to],
|
||||
fail_silently=False,
|
||||
html_message=html_template.render(context)
|
||||
)
|
||||
except SMTPException:
|
||||
continue
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user