From b1b9ab5ab264b98275bf966c482d41acc5d68a35 Mon Sep 17 00:00:00 2001 From: michail Date: Fri, 27 Sep 2019 11:14:18 +0500 Subject: [PATCH 01/17] 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 From 90ae87a14ece3f86e2ae33ffdd8bfb8115ad24f0 Mon Sep 17 00:00:00 2001 From: michail Date: Mon, 30 Sep 2019 12:09:53 +0500 Subject: [PATCH 02/17] added news mail template and task without celery delay --- apps/news/admin.py | 8 +------- apps/news/tasks.py | 28 ++++++++++++++++++++++------ apps/notification/urls/common.py | 1 + 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/apps/news/admin.py b/apps/news/admin.py index b866d867..dab70ec8 100644 --- a/apps/news/admin.py +++ b/apps/news/admin.py @@ -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 diff --git a/apps/news/tasks.py b/apps/news/tasks.py index a7e43c8c..c3c011d7 100644 --- a/apps/news/tasks.py +++ b/apps/news/tasks.py @@ -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 \ No newline at end of file + 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 diff --git a/apps/notification/urls/common.py b/apps/notification/urls/common.py index df43c805..842aa642 100644 --- a/apps/notification/urls/common.py +++ b/apps/notification/urls/common.py @@ -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'), From 50b00e5b6d7bb02b779d7c7886b7571fcb1be5f3 Mon Sep 17 00:00:00 2001 From: michail Date: Mon, 30 Sep 2019 12:10:45 +0500 Subject: [PATCH 03/17] added news mail template and task without celery delay --- project/settings/base.py | 1 + project/templates/news/news_email.html | 20 ++++++++++++++++++++ project/urls/web.py | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 project/templates/news/news_email.html diff --git a/project/settings/base.py b/project/settings/base.py index cfea18a5..719b637b 100644 --- a/project/settings/base.py +++ b/project/settings/base.py @@ -397,6 +397,7 @@ PASSWORD_RESET_TIMEOUT_DAYS = 1 RESETTING_TOKEN_TEMPLATE = 'account/password_reset_email.html' CHANGE_EMAIL_TEMPLATE = 'account/change_email.html' CONFIRM_EMAIL_TEMPLATE = 'authorization/confirm_email.html' +NEWS_EMAIL_TEMPLATE = "news/news_email.html" # COOKIES diff --git a/project/templates/news/news_email.html b/project/templates/news/news_email.html new file mode 100644 index 00000000..c9669829 --- /dev/null +++ b/project/templates/news/news_email.html @@ -0,0 +1,20 @@ + + + + + {{ title }} + + +

{{ title }}

+ + {% if subtitle %} +

{{ subtitle }}

+ {% endif %} + +

{{ description }}

+ +https://{{ domain_uri }}{% url 'web:notification:unsubscribe' code %} + + + + diff --git a/project/urls/web.py b/project/urls/web.py index 0a81672d..5bf538f3 100644 --- a/project/urls/web.py +++ b/project/urls/web.py @@ -23,7 +23,7 @@ urlpatterns = [ path('collections/', include('collection.urls.web')), path('establishments/', include('establishment.urls.web')), path('news/', include('news.urls.web')), - path('notifications/', include('notification.urls.web')), + path('notifications/', include(('notification.urls.web', "notification"), namespace='notification')), path('partner/', include('partner.urls.web')), path('location/', include('location.urls.web')), path('main/', include('main.urls')), From 6d72c1abfdf5c77290191e853d9cf51355a36b74 Mon Sep 17 00:00:00 2001 From: michail Date: Mon, 30 Sep 2019 12:18:18 +0500 Subject: [PATCH 04/17] fix locale and country code in task --- apps/news/tasks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/news/tasks.py b/apps/news/tasks.py index c3c011d7..98eaa8b1 100644 --- a/apps/news/tasks.py +++ b/apps/news/tasks.py @@ -18,9 +18,9 @@ def send_email_with_news(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), + {"title": sent_news.title.get(s.locale), + "subtitle": sent_news.subtitle.get(s.locale), + "description": sent_news.description.get(s.locale), "code": s.update_code, "domain_uri": settings.DOMAIN_URI}), settings.EMAIL_HOST_USER, [s.send_to], fail_silently=False) From 88df92a7a54edaaf5ca0f9a5913f727fea383a57 Mon Sep 17 00:00:00 2001 From: michail Date: Mon, 30 Sep 2019 12:42:49 +0500 Subject: [PATCH 05/17] added country_code to news email template --- apps/news/tasks.py | 3 ++- project/templates/news/news_email.html | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/news/tasks.py b/apps/news/tasks.py index 98eaa8b1..7bc2ce23 100644 --- a/apps/news/tasks.py +++ b/apps/news/tasks.py @@ -22,7 +22,8 @@ def send_email_with_news(news_ids): "subtitle": sent_news.subtitle.get(s.locale), "description": sent_news.description.get(s.locale), "code": s.update_code, - "domain_uri": settings.DOMAIN_URI}), + "domain_uri": settings.DOMAIN_URI, + "country_code": s.country_code}), settings.EMAIL_HOST_USER, [s.send_to], fail_silently=False) except SMTPException: continue diff --git a/project/templates/news/news_email.html b/project/templates/news/news_email.html index c9669829..a47af685 100644 --- a/project/templates/news/news_email.html +++ b/project/templates/news/news_email.html @@ -13,7 +13,7 @@

{{ description }}

-https://{{ domain_uri }}{% url 'web:notification:unsubscribe' code %} +https://{{ country_code }}.{{ domain_uri }}{% url 'web:notification:unsubscribe' code %} From ee221d093817e5aaa6fb2f2119938d78584536e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80=20=D0=93=D0=BB=D0=B0?= =?UTF-8?q?=D0=B4=D0=BA=D0=B8=D1=85?= Date: Tue, 1 Oct 2019 17:33:21 +0300 Subject: [PATCH 06/17] Fix celery --- apps/news/admin.py | 11 +++-------- apps/news/tasks.py | 8 +++++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/apps/news/admin.py b/apps/news/admin.py index dab70ec8..ad4a87c7 100644 --- a/apps/news/admin.py +++ b/apps/news/admin.py @@ -3,7 +3,6 @@ from django.contrib import admin from news import models from .tasks import send_email_with_news - @admin.register(models.NewsType) class NewsTypeAdmin(admin.ModelAdmin): """News type admin.""" @@ -12,13 +11,9 @@ class NewsTypeAdmin(admin.ModelAdmin): def send_email_action(modeladmin, request, queryset): - news_ids = [n.id for n in queryset] - - send_email_with_news(news_ids) - - # send_email_with_news.delay(news_ids) - - return + news_ids =queryset.values('id') + list_id = list(queryset.values_list('id', flat=True)) + send_email_with_news.delay(list_id) send_email_action.short_description = "Send the selected news by email" diff --git a/apps/news/tasks.py b/apps/news/tasks.py index 7bc2ce23..41a4a8c7 100644 --- a/apps/news/tasks.py +++ b/apps/news/tasks.py @@ -1,4 +1,4 @@ -from celery import shared_task +from celery import shared_task, task from django.core.mail import send_mail from notification.models import Subscriber from news import models @@ -7,15 +7,16 @@ from django.conf import settings from smtplib import SMTPException -# @shared_task +@shared_task def send_email_with_news(news_ids): - subscribers = Subscriber.objects.filter(state=Subscriber.USABLE) for s in subscribers: try: for n in news_ids: + print(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, {"title": sent_news.title.get(s.locale), @@ -26,4 +27,5 @@ def send_email_with_news(news_ids): "country_code": s.country_code}), settings.EMAIL_HOST_USER, [s.send_to], fail_silently=False) except SMTPException: + print('SMTPException') continue From 1f85f63d20ae6f3e18f8be9cfa98cf5002facd10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80=20=D0=93=D0=BB=D0=B0?= =?UTF-8?q?=D0=B4=D0=BA=D0=B8=D1=85?= Date: Tue, 1 Oct 2019 17:45:57 +0300 Subject: [PATCH 07/17] Fix celery --- apps/news/admin.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/news/admin.py b/apps/news/admin.py index ad4a87c7..0bd9b709 100644 --- a/apps/news/admin.py +++ b/apps/news/admin.py @@ -11,9 +11,7 @@ class NewsTypeAdmin(admin.ModelAdmin): def send_email_action(modeladmin, request, queryset): - news_ids =queryset.values('id') - list_id = list(queryset.values_list('id', flat=True)) - send_email_with_news.delay(list_id) + send_email_with_news.delay(list(queryset.values_list('id', flat=True))) send_email_action.short_description = "Send the selected news by email" From 0c79548027243054eac96367b781c3e312fa982e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80=20=D0=93=D0=BB=D0=B0?= =?UTF-8?q?=D0=B4=D0=BA=D0=B8=D1=85?= Date: Tue, 1 Oct 2019 17:51:27 +0300 Subject: [PATCH 08/17] Fix --- apps/news/tasks.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/news/tasks.py b/apps/news/tasks.py index 41a4a8c7..6d9e25b6 100644 --- a/apps/news/tasks.py +++ b/apps/news/tasks.py @@ -14,7 +14,6 @@ def send_email_with_news(news_ids): for s in subscribers: try: for n in news_ids: - print(n) sent_news = models.News.objects.get(id=n) # settings.NEWS_EMAIL_TEMPLATE @@ -27,5 +26,4 @@ def send_email_with_news(news_ids): "country_code": s.country_code}), settings.EMAIL_HOST_USER, [s.send_to], fail_silently=False) except SMTPException: - print('SMTPException') continue From 6683d4a4eff4f6f4d8cbe778b0fa155eb83cdff4 Mon Sep 17 00:00:00 2001 From: michail Date: Fri, 27 Sep 2019 11:14:18 +0500 Subject: [PATCH 09/17] 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 From 5474c2ff692a36a276553688b021e39651a7d986 Mon Sep 17 00:00:00 2001 From: michail Date: Mon, 30 Sep 2019 12:09:53 +0500 Subject: [PATCH 10/17] added news mail template and task without celery delay --- apps/news/admin.py | 8 +------- apps/news/tasks.py | 28 ++++++++++++++++++++++------ apps/notification/urls/common.py | 1 + 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/apps/news/admin.py b/apps/news/admin.py index b866d867..dab70ec8 100644 --- a/apps/news/admin.py +++ b/apps/news/admin.py @@ -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 diff --git a/apps/news/tasks.py b/apps/news/tasks.py index a7e43c8c..c3c011d7 100644 --- a/apps/news/tasks.py +++ b/apps/news/tasks.py @@ -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 \ No newline at end of file + 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 diff --git a/apps/notification/urls/common.py b/apps/notification/urls/common.py index df43c805..842aa642 100644 --- a/apps/notification/urls/common.py +++ b/apps/notification/urls/common.py @@ -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'), From b96ed30a492776f5e7d24fbfc9729a7b7bd800b5 Mon Sep 17 00:00:00 2001 From: michail Date: Mon, 30 Sep 2019 12:10:45 +0500 Subject: [PATCH 11/17] added news mail template and task without celery delay --- project/settings/base.py | 1 + project/templates/news/news_email.html | 20 ++++++++++++++++++++ project/urls/web.py | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 project/templates/news/news_email.html diff --git a/project/settings/base.py b/project/settings/base.py index cfea18a5..719b637b 100644 --- a/project/settings/base.py +++ b/project/settings/base.py @@ -397,6 +397,7 @@ PASSWORD_RESET_TIMEOUT_DAYS = 1 RESETTING_TOKEN_TEMPLATE = 'account/password_reset_email.html' CHANGE_EMAIL_TEMPLATE = 'account/change_email.html' CONFIRM_EMAIL_TEMPLATE = 'authorization/confirm_email.html' +NEWS_EMAIL_TEMPLATE = "news/news_email.html" # COOKIES diff --git a/project/templates/news/news_email.html b/project/templates/news/news_email.html new file mode 100644 index 00000000..c9669829 --- /dev/null +++ b/project/templates/news/news_email.html @@ -0,0 +1,20 @@ + + + + + {{ title }} + + +

{{ title }}

+ + {% if subtitle %} +

{{ subtitle }}

+ {% endif %} + +

{{ description }}

+ +https://{{ domain_uri }}{% url 'web:notification:unsubscribe' code %} + + + + diff --git a/project/urls/web.py b/project/urls/web.py index 0a81672d..5bf538f3 100644 --- a/project/urls/web.py +++ b/project/urls/web.py @@ -23,7 +23,7 @@ urlpatterns = [ path('collections/', include('collection.urls.web')), path('establishments/', include('establishment.urls.web')), path('news/', include('news.urls.web')), - path('notifications/', include('notification.urls.web')), + path('notifications/', include(('notification.urls.web', "notification"), namespace='notification')), path('partner/', include('partner.urls.web')), path('location/', include('location.urls.web')), path('main/', include('main.urls')), From c28d1cf3a07cd0f020f09e9f82247d3227cf0dd3 Mon Sep 17 00:00:00 2001 From: michail Date: Mon, 30 Sep 2019 12:18:18 +0500 Subject: [PATCH 12/17] fix locale and country code in task --- apps/news/tasks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/news/tasks.py b/apps/news/tasks.py index c3c011d7..98eaa8b1 100644 --- a/apps/news/tasks.py +++ b/apps/news/tasks.py @@ -18,9 +18,9 @@ def send_email_with_news(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), + {"title": sent_news.title.get(s.locale), + "subtitle": sent_news.subtitle.get(s.locale), + "description": sent_news.description.get(s.locale), "code": s.update_code, "domain_uri": settings.DOMAIN_URI}), settings.EMAIL_HOST_USER, [s.send_to], fail_silently=False) From c0149a069583e1b94c2887b107894e812e91e61f Mon Sep 17 00:00:00 2001 From: michail Date: Mon, 30 Sep 2019 12:42:49 +0500 Subject: [PATCH 13/17] added country_code to news email template --- apps/news/tasks.py | 3 ++- project/templates/news/news_email.html | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/news/tasks.py b/apps/news/tasks.py index 98eaa8b1..7bc2ce23 100644 --- a/apps/news/tasks.py +++ b/apps/news/tasks.py @@ -22,7 +22,8 @@ def send_email_with_news(news_ids): "subtitle": sent_news.subtitle.get(s.locale), "description": sent_news.description.get(s.locale), "code": s.update_code, - "domain_uri": settings.DOMAIN_URI}), + "domain_uri": settings.DOMAIN_URI, + "country_code": s.country_code}), settings.EMAIL_HOST_USER, [s.send_to], fail_silently=False) except SMTPException: continue diff --git a/project/templates/news/news_email.html b/project/templates/news/news_email.html index c9669829..a47af685 100644 --- a/project/templates/news/news_email.html +++ b/project/templates/news/news_email.html @@ -13,7 +13,7 @@

{{ description }}

-https://{{ domain_uri }}{% url 'web:notification:unsubscribe' code %} +https://{{ country_code }}.{{ domain_uri }}{% url 'web:notification:unsubscribe' code %} From 02638a26fe9561f3f449280d36282679bf389e29 Mon Sep 17 00:00:00 2001 From: michail Date: Wed, 2 Oct 2019 12:09:45 +0500 Subject: [PATCH 14/17] added sending through celery --- apps/news/admin.py | 4 +--- apps/news/tasks.py | 2 +- docker-compose.yml | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/apps/news/admin.py b/apps/news/admin.py index dab70ec8..1b869eb2 100644 --- a/apps/news/admin.py +++ b/apps/news/admin.py @@ -14,9 +14,7 @@ class NewsTypeAdmin(admin.ModelAdmin): def send_email_action(modeladmin, request, queryset): news_ids = [n.id for n in queryset] - send_email_with_news(news_ids) - - # send_email_with_news.delay(news_ids) + send_email_with_news.delay(news_ids) return diff --git a/apps/news/tasks.py b/apps/news/tasks.py index 7bc2ce23..35f2c644 100644 --- a/apps/news/tasks.py +++ b/apps/news/tasks.py @@ -7,7 +7,7 @@ from django.conf import settings from smtplib import SMTPException -# @shared_task +@shared_task def send_email_with_news(news_ids): subscribers = Subscriber.objects.filter(state=Subscriber.USABLE) diff --git a/docker-compose.yml b/docker-compose.yml index 3fb05f98..2ccd6de3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,8 +12,8 @@ services: - POSTGRES_DB=postgres ports: - "5436:5432" - networks: - - db-net +# networks: +# - db-net volumes: - gm-db:/var/lib/postgresql/data/ elasticsearch: @@ -28,8 +28,8 @@ services: - "ES_JAVA_OPTS=-Xms512m -Xmx512m" - discovery.type=single-node - xpack.security.enabled=false - networks: - - app-net +# networks: +# - app-net # RabbitMQ rabbitmq: image: rabbitmq:latest @@ -83,18 +83,18 @@ services: - worker - worker_beat - elasticsearch - networks: - - app-net - - db-net +# networks: +# - app-net +# - db-net volumes: - .:/code - gm-media:/media-data ports: - "8000:8000" -networks: - app-net: - db-net: +#networks: +# app-net: +# db-net: volumes: gm-db: From e611e3154d14322fc544e41042a5a6358a9396cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80=20=D0=93=D0=BB=D0=B0?= =?UTF-8?q?=D0=B4=D0=BA=D0=B8=D1=85?= Date: Wed, 2 Oct 2019 11:21:28 +0300 Subject: [PATCH 15/17] Push --- apps/news/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/news/admin.py b/apps/news/admin.py index 0bd9b709..c993404d 100644 --- a/apps/news/admin.py +++ b/apps/news/admin.py @@ -9,7 +9,7 @@ class NewsTypeAdmin(admin.ModelAdmin): list_display = ['id', 'name'] list_display_links = ['id', 'name'] - +# Изменения def send_email_action(modeladmin, request, queryset): send_email_with_news.delay(list(queryset.values_list('id', flat=True))) From fb9e71cbdd8607f831f7b6e4423f63c51c93ff8a Mon Sep 17 00:00:00 2001 From: michail Date: Wed, 2 Oct 2019 13:27:33 +0500 Subject: [PATCH 16/17] fix querysets --- apps/news/admin.py | 3 +-- apps/news/tasks.py | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/apps/news/admin.py b/apps/news/admin.py index 1b869eb2..cbda27b0 100644 --- a/apps/news/admin.py +++ b/apps/news/admin.py @@ -12,11 +12,10 @@ class NewsTypeAdmin(admin.ModelAdmin): def send_email_action(modeladmin, request, queryset): - news_ids = [n.id for n in queryset] + news_ids = list(queryset.values_list("id", flat=True)) send_email_with_news.delay(news_ids) - return send_email_action.short_description = "Send the selected news by email" diff --git a/apps/news/tasks.py b/apps/news/tasks.py index 35f2c644..6f48e17c 100644 --- a/apps/news/tasks.py +++ b/apps/news/tasks.py @@ -11,12 +11,11 @@ from smtplib import SMTPException def send_email_with_news(news_ids): subscribers = Subscriber.objects.filter(state=Subscriber.USABLE) + sent_news = models.News.objects.filter(id__in=news_ids) for s in subscribers: try: - for n in news_ids: - sent_news = models.News.objects.get(id=n) - + for n in sent_news: send_mail("G&M News", render_to_string(settings.NEWS_EMAIL_TEMPLATE, {"title": sent_news.title.get(s.locale), "subtitle": sent_news.subtitle.get(s.locale), From 5ec81f417ad6c6267ab9157b76af70f703e76791 Mon Sep 17 00:00:00 2001 From: michail Date: Wed, 2 Oct 2019 13:37:46 +0500 Subject: [PATCH 17/17] fix bug --- apps/news/tasks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/news/tasks.py b/apps/news/tasks.py index 6f48e17c..99065fc8 100644 --- a/apps/news/tasks.py +++ b/apps/news/tasks.py @@ -17,9 +17,9 @@ def send_email_with_news(news_ids): try: for n in sent_news: send_mail("G&M News", render_to_string(settings.NEWS_EMAIL_TEMPLATE, - {"title": sent_news.title.get(s.locale), - "subtitle": sent_news.subtitle.get(s.locale), - "description": sent_news.description.get(s.locale), + {"title": n.title.get(s.locale), + "subtitle": n.subtitle.get(s.locale), + "description": n.description.get(s.locale), "code": s.update_code, "domain_uri": settings.DOMAIN_URI, "country_code": s.country_code}),