added news mail template and task without celery delay
This commit is contained in:
parent
6683d4a4ef
commit
5474c2ff69
|
|
@ -1,9 +1,7 @@
|
|||
from django.contrib import admin
|
||||
|
||||
from news import models
|
||||
from notification.models import Subscriber
|
||||
from .tasks import send_email_with_news
|
||||
from establishment.tasks import recalculate_price_levels_by_country
|
||||
|
||||
|
||||
@admin.register(models.NewsType)
|
||||
|
|
@ -14,16 +12,12 @@ class NewsTypeAdmin(admin.ModelAdmin):
|
|||
|
||||
|
||||
def send_email_action(modeladmin, request, queryset):
|
||||
print(queryset)
|
||||
|
||||
news_ids = [n.id for n in queryset]
|
||||
|
||||
print(news_ids)
|
||||
send_email_with_news(news_ids)
|
||||
|
||||
# send_email_with_news.delay(news_ids)
|
||||
recalculate_price_levels_by_country.delay(news_ids)
|
||||
|
||||
print("TEST send_email_action IS CALLED!")
|
||||
return
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,28 @@
|
|||
from celery import shared_task
|
||||
|
||||
from django.core.mail import send_mail
|
||||
from notification.models import Subscriber
|
||||
from news import models
|
||||
from django.template.loader import render_to_string
|
||||
from django.conf import settings
|
||||
from smtplib import SMTPException
|
||||
|
||||
@shared_task
|
||||
def send_email_with_news(news):
|
||||
|
||||
print(news)
|
||||
# @shared_task
|
||||
def send_email_with_news(news_ids):
|
||||
|
||||
print("EMAILS WAS SENT!")
|
||||
subscribers = Subscriber.objects.filter(state=Subscriber.USABLE)
|
||||
|
||||
return news
|
||||
for s in subscribers:
|
||||
try:
|
||||
for n in news_ids:
|
||||
sent_news = models.News.objects.get(id=n)
|
||||
|
||||
send_mail("G&M News", render_to_string(settings.NEWS_EMAIL_TEMPLATE,
|
||||
{"title": sent_news.title.get(s.country_code),
|
||||
"subtitle": sent_news.subtitle.get(s.country_code),
|
||||
"description": sent_news.description.get(s.country_code),
|
||||
"code": s.update_code,
|
||||
"domain_uri": settings.DOMAIN_URI}),
|
||||
settings.EMAIL_HOST_USER, [s.send_to], fail_silently=False)
|
||||
except SMTPException:
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
from django.urls import path
|
||||
from notification.views import common
|
||||
|
||||
app_name = "notification"
|
||||
|
||||
urlpatterns = [
|
||||
path('subscribe/', common.SubscribeView.as_view(), name='subscribe'),
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user