Fix celery
This commit is contained in:
parent
88df92a7a5
commit
ee221d0938
|
|
@ -3,7 +3,6 @@ from django.contrib import admin
|
||||||
from news import models
|
from news import models
|
||||||
from .tasks import send_email_with_news
|
from .tasks import send_email_with_news
|
||||||
|
|
||||||
|
|
||||||
@admin.register(models.NewsType)
|
@admin.register(models.NewsType)
|
||||||
class NewsTypeAdmin(admin.ModelAdmin):
|
class NewsTypeAdmin(admin.ModelAdmin):
|
||||||
"""News type admin."""
|
"""News type admin."""
|
||||||
|
|
@ -12,13 +11,9 @@ class NewsTypeAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
|
|
||||||
def send_email_action(modeladmin, request, queryset):
|
def send_email_action(modeladmin, request, queryset):
|
||||||
news_ids = [n.id for n in queryset]
|
news_ids =queryset.values('id')
|
||||||
|
list_id = list(queryset.values_list('id', flat=True))
|
||||||
send_email_with_news(news_ids)
|
send_email_with_news.delay(list_id)
|
||||||
|
|
||||||
# send_email_with_news.delay(news_ids)
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
send_email_action.short_description = "Send the selected news by email"
|
send_email_action.short_description = "Send the selected news by email"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from celery import shared_task
|
from celery import shared_task, task
|
||||||
from django.core.mail import send_mail
|
from django.core.mail import send_mail
|
||||||
from notification.models import Subscriber
|
from notification.models import Subscriber
|
||||||
from news import models
|
from news import models
|
||||||
|
|
@ -7,15 +7,16 @@ from django.conf import settings
|
||||||
from smtplib import SMTPException
|
from smtplib import SMTPException
|
||||||
|
|
||||||
|
|
||||||
# @shared_task
|
@shared_task
|
||||||
def send_email_with_news(news_ids):
|
def send_email_with_news(news_ids):
|
||||||
|
|
||||||
subscribers = Subscriber.objects.filter(state=Subscriber.USABLE)
|
subscribers = Subscriber.objects.filter(state=Subscriber.USABLE)
|
||||||
|
|
||||||
for s in subscribers:
|
for s in subscribers:
|
||||||
try:
|
try:
|
||||||
for n in news_ids:
|
for n in news_ids:
|
||||||
|
print(n)
|
||||||
sent_news = models.News.objects.get(id=n)
|
sent_news = models.News.objects.get(id=n)
|
||||||
|
# settings.NEWS_EMAIL_TEMPLATE
|
||||||
|
|
||||||
send_mail("G&M News", render_to_string(settings.NEWS_EMAIL_TEMPLATE,
|
send_mail("G&M News", render_to_string(settings.NEWS_EMAIL_TEMPLATE,
|
||||||
{"title": sent_news.title.get(s.locale),
|
{"title": sent_news.title.get(s.locale),
|
||||||
|
|
@ -26,4 +27,5 @@ def send_email_with_news(news_ids):
|
||||||
"country_code": s.country_code}),
|
"country_code": s.country_code}),
|
||||||
settings.EMAIL_HOST_USER, [s.send_to], fail_silently=False)
|
settings.EMAIL_HOST_USER, [s.send_to], fail_silently=False)
|
||||||
except SMTPException:
|
except SMTPException:
|
||||||
|
print('SMTPException')
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user