News email #2
This commit is contained in:
parent
90b8dafba9
commit
73646eb05f
|
|
@ -8,6 +8,8 @@ from django.template.loader import render_to_string
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from smtplib import SMTPException
|
from smtplib import SMTPException
|
||||||
from django.template.loader import get_template
|
from django.template.loader import get_template
|
||||||
|
from django.core.validators import EMPTY_VALUES
|
||||||
|
from main.models import SiteSettings
|
||||||
|
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
|
|
@ -16,17 +18,23 @@ def send_email_with_news(news_ids):
|
||||||
sent_news = models.News.objects.filter(id__in=news_ids)
|
sent_news = models.News.objects.filter(id__in=news_ids)
|
||||||
htmly = get_template(settings.NEWS_EMAIL_TEMPLATE)
|
htmly = get_template(settings.NEWS_EMAIL_TEMPLATE)
|
||||||
year = datetime.now().year
|
year = datetime.now().year
|
||||||
|
socials = list(SiteSettings.objects.with_country())
|
||||||
|
socials = dict(zip(map(lambda s: s.country.code, socials), socials))
|
||||||
for s in subscribers:
|
for s in subscribers:
|
||||||
|
socials_for_subscriber = socials.get(s.country_code)
|
||||||
try:
|
try:
|
||||||
for n in sent_news:
|
for n in sent_news:
|
||||||
context = {"title": n.title.get(s.locale),
|
context = {"title": n.title.get(s.locale),
|
||||||
"subtitle": n.subtitle.get(s.locale),
|
"subtitle": n.subtitle.get(s.locale),
|
||||||
"description": n.description.get(s.locale),
|
"description": n.description.get(s.locale),
|
||||||
"code": s.update_code,
|
"code": s.update_code,
|
||||||
"image_url": n.image_url,
|
"image_url": n.image_url if n.image_url not in EMPTY_VALUES else None,
|
||||||
"domain_uri": settings.DOMAIN_URI,
|
"domain_uri": settings.DOMAIN_URI,
|
||||||
"slug": n.slug,
|
"slug": n.slug,
|
||||||
"country_code": s.country_code,
|
"country_code": s.country_code,
|
||||||
|
"twitter_page_url": socials_for_subscriber.twitter_page_url if socials_for_subscriber else '#',
|
||||||
|
"instagram_page_url": socials_for_subscriber.instagram_page_url if socials_for_subscriber else '#',
|
||||||
|
"facebook_page_url": socials_for_subscriber.facebook_page_url if socials_for_subscriber else '#',
|
||||||
"send_to": s.send_to,
|
"send_to": s.send_to,
|
||||||
"year": year}
|
"year": year}
|
||||||
send_mail("G&M News", render_to_string(settings.NEWS_EMAIL_TEMPLATE, context),
|
send_mail("G&M News", render_to_string(settings.NEWS_EMAIL_TEMPLATE, context),
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user