From b1b9ab5ab264b98275bf966c482d41acc5d68a35 Mon Sep 17 00:00:00 2001 From: michail Date: Fri, 27 Sep 2019 11:14:18 +0500 Subject: [PATCH] First commit --- apps/news/admin.py | 22 ++++++++++++++++++++++ apps/news/tasks.py | 12 ++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 apps/news/tasks.py diff --git a/apps/news/admin.py b/apps/news/admin.py index 7cbfb049..b866d867 100644 --- a/apps/news/admin.py +++ b/apps/news/admin.py @@ -1,5 +1,9 @@ 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) @@ -9,6 +13,24 @@ class NewsTypeAdmin(admin.ModelAdmin): list_display_links = ['id', 'name'] +def send_email_action(modeladmin, request, queryset): + print(queryset) + + news_ids = [n.id for n in queryset] + + print(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 + + +send_email_action.short_description = "Send the selected news by email" + + @admin.register(models.News) class NewsAdmin(admin.ModelAdmin): """News admin.""" + actions = [send_email_action] diff --git a/apps/news/tasks.py b/apps/news/tasks.py new file mode 100644 index 00000000..a7e43c8c --- /dev/null +++ b/apps/news/tasks.py @@ -0,0 +1,12 @@ +from celery import shared_task + +from notification.models import Subscriber + +@shared_task +def send_email_with_news(news): + + print(news) + + print("EMAILS WAS SENT!") + + return news \ No newline at end of file