From 2c888d1c3ab415b1378efddefa4d35b471c3f8f7 Mon Sep 17 00:00:00 2001 From: Kuroshini Date: Mon, 13 Jan 2020 11:16:02 +0300 Subject: [PATCH 01/18] default ordering for BO establishments search --- apps/search_indexes/serializers.py | 9 +++++++++ apps/search_indexes/views.py | 26 +++++++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/apps/search_indexes/serializers.py b/apps/search_indexes/serializers.py index be0d517d..a668ccf1 100644 --- a/apps/search_indexes/serializers.py +++ b/apps/search_indexes/serializers.py @@ -313,6 +313,15 @@ class EstablishmentDocumentSerializer(InFavoritesMixin, DocumentSerializer): ) +class EstablishmentBackOfficeDocumentSerializer(EstablishmentDocumentSerializer): + + class Meta(EstablishmentDocumentSerializer.Meta): + document = EstablishmentDocumentSerializer.Meta.document + fields = EstablishmentDocumentSerializer.Meta.fields + ( + 'created', + ) + + class ProductDocumentSerializer(InFavoritesMixin): """Product document serializer""" diff --git a/apps/search_indexes/views.py b/apps/search_indexes/views.py index fd896738..a3399fc1 100644 --- a/apps/search_indexes/views.py +++ b/apps/search_indexes/views.py @@ -1,5 +1,5 @@ """Search indexes app views.""" -from django_elasticsearch_dsl_drf import constants +from django_elasticsearch_dsl_drf import constants, pagination from django_elasticsearch_dsl_drf.filter_backends import ( FilteringFilterBackend, GeoSpatialOrderingFilterBackend, @@ -321,14 +321,26 @@ class EstablishmentDocumentViewSet(BaseDocumentViewSet): class EstablishmentBackOfficeViewSet(EstablishmentDocumentViewSet): - filter_backends = EstablishmentDocumentViewSet.filter_backends + [ - OrderingFilterBackend - ] + def get_queryset(self): + if not self.request.query_params.get('search'): + self.request.GET._mutable = True + self.request.query_params.update({ + 'ordering': '-created', + }) + self.request.GET._mutable = False + return super(EstablishmentBackOfficeViewSet, self).get_queryset() + serializer_class = serializers.EstablishmentBackOfficeDocumentSerializer + pagination_class = pagination.PageNumberPagination + filter_backends = [ + FilteringFilterBackend, + filters.CustomSearchFilterBackend, + filters.CustomGeoSpatialFilteringFilterBackend, + GeoSpatialOrderingFilterBackend, + OrderingFilterBackend, + ] ordering_fields = { - 'created': { - 'field': 'created' - } + 'created': 'created', } From d1572cbb56582ebe58eee651cf73bf1737f2bdd0 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 13 Jan 2020 11:25:22 +0300 Subject: [PATCH 02/18] rm publish filter from BO establishment api --- apps/establishment/views/back.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/establishment/views/back.py b/apps/establishment/views/back.py index a195e31a..19a75fd5 100644 --- a/apps/establishment/views/back.py +++ b/apps/establishment/views/back.py @@ -19,7 +19,7 @@ class EstablishmentMixinViews: def get_queryset(self): """Overrided method 'get_queryset'.""" - return models.Establishment.objects.published().with_base_related() + return models.Establishment.objects.with_base_related() class EstablishmentListCreateView(EstablishmentMixinViews, generics.ListCreateAPIView): From b2f3e1f96be2ca261cb53b245c001180e948a5a9 Mon Sep 17 00:00:00 2001 From: Anatoly Date: Mon, 13 Jan 2020 11:50:54 +0300 Subject: [PATCH 03/18] added field - "distillery_types" in establishment list, detail and similar list view --- apps/establishment/models.py | 5 +++++ apps/establishment/serializers/common.py | 2 ++ 2 files changed, 7 insertions(+) diff --git a/apps/establishment/models.py b/apps/establishment/models.py index e4087b4b..c10be29d 100644 --- a/apps/establishment/models.py +++ b/apps/establishment/models.py @@ -854,6 +854,11 @@ class Establishment(GalleryMixin, ProjectBaseMixin, URLImageMixin, metadata.append(category_tags) return metadata + @property + def distillery_types(self): + """Tags from tag category - distillery_type.""" + return self.tags.filter(category__index_name='distillery_type') + class EstablishmentNoteQuerySet(models.QuerySet): """QuerySet for model EstablishmentNote.""" diff --git a/apps/establishment/serializers/common.py b/apps/establishment/serializers/common.py index deabd100..8d0c8103 100644 --- a/apps/establishment/serializers/common.py +++ b/apps/establishment/serializers/common.py @@ -329,6 +329,7 @@ class EstablishmentBaseSerializer(ProjectModelSerializer): read_only=True) tz = serializers.CharField(read_only=True, source='timezone_as_str') new_image = ImageBaseSerializer(source='crop_main_image', allow_null=True, read_only=True) + distillery_types = TagBaseSerializer(read_only=True, many=True, allow_null=True) class Meta: """Meta class.""" @@ -354,6 +355,7 @@ class EstablishmentBaseSerializer(ProjectModelSerializer): 'new_image', 'tz', 'wine_regions', + 'distillery_types', ] From d6345f27e2bf05596dac84c7f171b673729590d7 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 13 Jan 2020 11:56:04 +0300 Subject: [PATCH 04/18] establishment menu currency id --- apps/establishment/serializers/common.py | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/establishment/serializers/common.py b/apps/establishment/serializers/common.py index 8d0c8103..ada87016 100644 --- a/apps/establishment/serializers/common.py +++ b/apps/establishment/serializers/common.py @@ -54,7 +54,6 @@ class SocialNetworkRelatedSerializers(serializers.ModelSerializer): class PlateSerializer(ProjectModelSerializer): name_translated = TranslatedField() - currency = CurrencySerializer(read_only=True) class Meta: model = models.Plate From 28c674702c21f31f910401bed6f7a73bab64a01d Mon Sep 17 00:00:00 2001 From: Kuroshini Date: Mon, 13 Jan 2020 12:12:01 +0300 Subject: [PATCH 05/18] fix news state update --- apps/news/serializers.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/news/serializers.py b/apps/news/serializers.py index 2c7983d1..c0df73a4 100644 --- a/apps/news/serializers.py +++ b/apps/news/serializers.py @@ -232,9 +232,9 @@ class NewsBackOfficeBaseSerializer(NewsBaseSerializer): def create(self, validated_data): slugs = validated_data.get('slugs') - slugs_list = list(map(lambda x: x.lower(), slugs.values())) - slugs_set = set(slugs_list) if slugs: + slugs_list = list(map(lambda x: x.lower(), slugs.values())) + slugs_set = set(slugs_list) if models.News.objects.filter( slugs__values__contains=list(slugs.values()) ).exists() or len(slugs_list) != len(slugs_set): @@ -249,9 +249,9 @@ class NewsBackOfficeBaseSerializer(NewsBaseSerializer): def update(self, instance, validated_data): slugs = validated_data.get('slugs') - slugs_list = list(map(lambda x: x.lower(), slugs.values())) - slugs_set = set(slugs_list) if slugs: + slugs_list = list(map(lambda x: x.lower(), slugs.values())) + slugs_set = set(slugs_list) if models.News.objects.filter( slugs__values__contains=list(slugs.values()) ).exists() or len(slugs_list) != len(slugs_set): From 6c47fb404b470a2f4d5be8d9a57fa610de0f896b Mon Sep 17 00:00:00 2001 From: dormantman Date: Mon, 13 Jan 2020 11:53:54 +0300 Subject: [PATCH 06/18] Fix news mailing --- apps/news/tasks.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/apps/news/tasks.py b/apps/news/tasks.py index 0267fcf4..e70b8271 100644 --- a/apps/news/tasks.py +++ b/apps/news/tasks.py @@ -19,20 +19,24 @@ def send_email_with_news(news_ids): .prefetch_related('subscription_type') sent_news = models.News.objects.filter(id__in=news_ids) - htmly = get_template(settings.NEWS_EMAIL_TEMPLATE) + html_template = get_template(settings.NEWS_EMAIL_TEMPLATE) year = datetime.now().year socials = list(SiteSettings.objects.with_country().select_related('country')) socials = dict(zip(map(lambda social: social.country.code, socials), socials)) for subscribe in subscribes.filter(unsubscribe_date=None): + subscriber = subscribe.subscriber + country = subscribe.subscription_type.country if country is None: - continue + country_code = subscriber.country_code - socials_for_subscriber = socials.get(country.code) - subscriber = subscribe.subscriber + else: + country_code = country.code + + socials_for_subscriber = socials.get(country_code) try: for new in sent_news: @@ -52,9 +56,12 @@ def send_email_with_news(news_ids): "year": year } send_mail( - "G&M News", render_to_string(settings.NEWS_EMAIL_TEMPLATE, context), - settings.EMAIL_HOST_USER, [subscriber.send_to], fail_silently=False, - html_message=htmly.render(context) + subject="G&M News", + message=render_to_string(settings.NEWS_EMAIL_TEMPLATE, context), + from_email=settings.EMAIL_HOST_USER, + recipient_list=[subscriber.send_to], + fail_silently=False, + html_message=html_template.render(context) ) except SMTPException: continue From f048cf2e176fe5b746bcdc6ea0faedd9f6fa82a5 Mon Sep 17 00:00:00 2001 From: dormantman Date: Mon, 13 Jan 2020 12:08:43 +0300 Subject: [PATCH 07/18] Mailing fixed --- apps/news/tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/news/tasks.py b/apps/news/tasks.py index e70b8271..d66e4db1 100644 --- a/apps/news/tasks.py +++ b/apps/news/tasks.py @@ -47,7 +47,7 @@ def send_email_with_news(news_ids): "code": subscriber.update_code, "image_url": new.image_url if new.image_url not in EMPTY_VALUES else None, "domain_uri": settings.DOMAIN_URI, - "slug": new.slug, + "slug": new.slugs.get(subscriber.locale), "country_code": subscriber.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 '#', From bb7cd98b9875742f9d67cdacb64b2fbc34ea84de Mon Sep 17 00:00:00 2001 From: dormantman Date: Mon, 13 Jan 2020 12:24:48 +0300 Subject: [PATCH 08/18] Added news locale check --- apps/news/tasks.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/news/tasks.py b/apps/news/tasks.py index d66e4db1..d46d3083 100644 --- a/apps/news/tasks.py +++ b/apps/news/tasks.py @@ -40,6 +40,9 @@ def send_email_with_news(news_ids): try: for new in sent_news: + if new.country.code != country_code: + continue + context = { "title": new.title.get(subscriber.locale), "subtitle": new.subtitle.get(subscriber.locale), From 114304b3c92f911b43ff2302bb0dc9d0d3f4cfb5 Mon Sep 17 00:00:00 2001 From: dormantman Date: Mon, 13 Jan 2020 12:28:30 +0300 Subject: [PATCH 09/18] Reformat builder method --- apps/news/tasks.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/news/tasks.py b/apps/news/tasks.py index d46d3083..5256c598 100644 --- a/apps/news/tasks.py +++ b/apps/news/tasks.py @@ -16,7 +16,9 @@ from notification.models import Subscribe def send_email_with_news(news_ids): subscribes = Subscribe.objects.all() \ .prefetch_related('subscriber') \ - .prefetch_related('subscription_type') + .prefetch_related('subscription_type') \ + .exclude(unsubscrube_date__isnull=False) + sent_news = models.News.objects.filter(id__in=news_ids) html_template = get_template(settings.NEWS_EMAIL_TEMPLATE) @@ -25,7 +27,7 @@ def send_email_with_news(news_ids): socials = list(SiteSettings.objects.with_country().select_related('country')) socials = dict(zip(map(lambda social: social.country.code, socials), socials)) - for subscribe in subscribes.filter(unsubscribe_date=None): + for subscribe in subscribes: subscriber = subscribe.subscriber country = subscribe.subscription_type.country From 2deb4b3b7f6c5b446d129384f56baee9c64fd5c5 Mon Sep 17 00:00:00 2001 From: Kuroshini Date: Mon, 13 Jan 2020 12:47:07 +0300 Subject: [PATCH 10/18] some code improvements --- apps/news/tasks.py | 7 +++---- apps/notification/models.py | 9 +++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/news/tasks.py b/apps/news/tasks.py index 5256c598..21afdafb 100644 --- a/apps/news/tasks.py +++ b/apps/news/tasks.py @@ -15,9 +15,8 @@ from notification.models import Subscribe @shared_task def send_email_with_news(news_ids): subscribes = Subscribe.objects.all() \ - .prefetch_related('subscriber') \ - .prefetch_related('subscription_type') \ - .exclude(unsubscrube_date__isnull=False) + .prefetch_related('subscriber', 'subscription_type') \ + .active() sent_news = models.News.objects.filter(id__in=news_ids) @@ -33,7 +32,7 @@ def send_email_with_news(news_ids): country = subscribe.subscription_type.country if country is None: - country_code = subscriber.country_code + continue # subscription_type has no country else: country_code = country.code diff --git a/apps/notification/models.py b/apps/notification/models.py index 88c87ce1..ef3ca70b 100644 --- a/apps/notification/models.py +++ b/apps/notification/models.py @@ -135,6 +135,13 @@ class Subscriber(ProjectBaseMixin): return self.subscription_types.exclude(subscriber__subscribe__unsubscribe_date__isnull=False) +class SubscribeQuerySet(models.QuerySet): + + def active(self, switcher=True): + """Fetches active subscriptions.""" + return self.exclude(unsubscribe_date__isnull=not switcher) + + class Subscribe(ProjectBaseMixin): """Subscribe model.""" @@ -144,6 +151,8 @@ class Subscribe(ProjectBaseMixin): subscriber = models.ForeignKey(Subscriber, on_delete=models.CASCADE) subscription_type = models.ForeignKey(SubscriptionType, on_delete=models.CASCADE) + objects = SubscribeQuerySet.as_manager() + class Meta: """Meta class.""" From 9b2ad2a6dd9546343f978ce15da993457b1a2971 Mon Sep 17 00:00:00 2001 From: Kuroshini Date: Mon, 13 Jan 2020 13:37:11 +0300 Subject: [PATCH 11/18] try new email settings for dev --- project/settings/development.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/project/settings/development.py b/project/settings/development.py index 88b88789..24a1a795 100644 --- a/project/settings/development.py +++ b/project/settings/development.py @@ -74,3 +74,10 @@ CELERY_RESULT_BACKEND = BROKER_URL CELERY_BROKER_URL = BROKER_URL COOKIE_DOMAIN = '.id-east.ru' + +# Email settings +EMAIL_USE_TLS = True +EMAIL_HOST = 'smtp.gmail.com' +EMAIL_HOST_USER = 'anatolyfeteleu@gmail.com' +EMAIL_HOST_PASSWORD = 'nggrlnbehzksgmbt' +EMAIL_PORT = 587 \ No newline at end of file From 469a246f49da7bb4815834d8cae6642bea94e32e Mon Sep 17 00:00:00 2001 From: dormantman Date: Mon, 13 Jan 2020 13:36:49 +0300 Subject: [PATCH 12/18] Added subscribes notification --- apps/notification/models.py | 8 ++ apps/notification/tasks.py | 88 +++++++++++++++++++ project/settings/base.py | 1 + .../templates/notification/update_email.html | 75 ++++++++++++++++ 4 files changed, 172 insertions(+) create mode 100644 apps/notification/tasks.py create mode 100644 project/templates/notification/update_email.html diff --git a/apps/notification/models.py b/apps/notification/models.py index ef3ca70b..6dbf0230 100644 --- a/apps/notification/models.py +++ b/apps/notification/models.py @@ -9,6 +9,7 @@ from account.models import User from location.models import Country from utils.methods import generate_string_code from utils.models import ProjectBaseMixin, TJSONField, TranslatedFieldsMixin +from notification.tasks import send_subscribes_update_email, send_unsubscribe_email class SubscriptionType(ProjectBaseMixin, TranslatedFieldsMixin): @@ -100,6 +101,8 @@ class Subscriber(ProjectBaseMixin): objects = SubscriberManager() + # todo: Add sending subscribes with update email + class Meta: """Meta class.""" @@ -116,6 +119,11 @@ class Subscriber(ProjectBaseMixin): """Unsubscribe user.""" self.subscribe_set.update(unsubscribe_date=now()) + if settings.USE_CELERY: + send_unsubscribe_email.delay(self.pk) + else: + send_unsubscribe_email(self.pk) + @property def send_to(self): """Actual email.""" diff --git a/apps/notification/tasks.py b/apps/notification/tasks.py new file mode 100644 index 00000000..4a0ff5f3 --- /dev/null +++ b/apps/notification/tasks.py @@ -0,0 +1,88 @@ +from datetime import datetime + +from celery import shared_task +from django.conf import settings +from django.core.mail import send_mail +from django.template.loader import get_template, render_to_string + +from main.models import SiteSettings +from notification.models import Subscriber + + +@shared_task +def send_subscribes_update_email(subscriber_id): + subscriber = Subscriber.objects.get(subscriber_id) + + country_code = subscriber.country_code + + html_template = get_template(settings.NEWS_EMAIL_TEMPLATE) + year = datetime.now().year + + socials = list(SiteSettings.objects.with_country().select_related('country')) + socials = dict(zip(map(lambda social: social.country.code, socials), socials)) + + socials_for_subscriber = socials.get(country_code) + + context = { + "title": "G&M Subscriptions", + "subtitle": "You have subscribed on news G&M", + "description": "\n".join([ + name.get(subscriber.locale) + for name in subscriber.subscription_types.values_list('name', flat=True) + ]), + "code": subscriber.update_code, + "domain_uri": settings.DOMAIN_URI, + "country_code": subscriber.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": subscriber.send_to, + "year": year + } + + send_mail( + subject="G&M Subscriptions", + message=render_to_string(settings.NOTIFICATION_SUBSCRIBE_TEMPLATE, context), + from_email=settings.EMAIL_HOST_USER, + recipient_list=[subscriber.send_to], + fail_silently=False, + html_message=html_template.render(context) + ) + + +@shared_task +def send_unsubscribe_email(subscriber_id): + subscriber = Subscriber.objects.get(subscriber_id) + + country_code = subscriber.country_code + + html_template = get_template(settings.NEWS_EMAIL_TEMPLATE) + year = datetime.now().year + + socials = list(SiteSettings.objects.with_country().select_related('country')) + socials = dict(zip(map(lambda social: social.country.code, socials), socials)) + + socials_for_subscriber = socials.get(country_code) + + context = { + "title": "G&M Subscriptions", + "subtitle": "You have successfully unsubscribed from G&M news", + "description": "", + "code": subscriber.update_code, + "domain_uri": settings.DOMAIN_URI, + "country_code": subscriber.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": subscriber.send_to, + "year": year + } + + send_mail( + subject="G&M Subscriptions", + message=render_to_string(settings.NOTIFICATION_SUBSCRIBE_TEMPLATE, context), + from_email=settings.EMAIL_HOST_USER, + recipient_list=[subscriber.send_to], + fail_silently=False, + html_message=html_template.render(context) + ) diff --git a/project/settings/base.py b/project/settings/base.py index f34638aa..08a36609 100644 --- a/project/settings/base.py +++ b/project/settings/base.py @@ -454,6 +454,7 @@ CHANGE_EMAIL_TEMPLATE = 'account/change_email.html' CONFIRM_EMAIL_TEMPLATE = 'authorization/confirm_email.html' NEWS_EMAIL_TEMPLATE = 'news/news_email.html' NOTIFICATION_PASSWORD_TEMPLATE = 'account/password_change_email.html' +NOTIFICATION_SUBSCRIBE_TEMPLATE = 'notification/update_email.html' # COOKIES diff --git a/project/templates/notification/update_email.html b/project/templates/notification/update_email.html new file mode 100644 index 00000000..dad6e9b8 --- /dev/null +++ b/project/templates/notification/update_email.html @@ -0,0 +1,75 @@ + + + + + + + + {{ title }} + + +
+ +
+ +
+
+
+
+
+ + +
+
+ {{ title }} +
+ {% if not image_url is None %} +
+ +
+ {% endif %} +
+ {{ description | safe }} +
+
+ +
+ This email has been sent to {{ send_to }} , + click here to unsubscribe +
+ +
+
+
+ + \ No newline at end of file From 99990963208d782893ff2dc9fdd4d2675eb96c65 Mon Sep 17 00:00:00 2001 From: dormantman Date: Mon, 13 Jan 2020 14:01:58 +0300 Subject: [PATCH 13/18] Added actions mailing --- apps/notification/models.py | 4 +--- apps/notification/serializers/common.py | 21 +++++++++++++++++++-- apps/notification/tasks.py | 14 ++++++-------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/apps/notification/models.py b/apps/notification/models.py index 6dbf0230..c7d277d8 100644 --- a/apps/notification/models.py +++ b/apps/notification/models.py @@ -9,7 +9,7 @@ from account.models import User from location.models import Country from utils.methods import generate_string_code from utils.models import ProjectBaseMixin, TJSONField, TranslatedFieldsMixin -from notification.tasks import send_subscribes_update_email, send_unsubscribe_email +from notification.tasks import send_unsubscribe_email class SubscriptionType(ProjectBaseMixin, TranslatedFieldsMixin): @@ -101,8 +101,6 @@ class Subscriber(ProjectBaseMixin): objects = SubscriberManager() - # todo: Add sending subscribes with update email - class Meta: """Meta class.""" diff --git a/apps/notification/serializers/common.py b/apps/notification/serializers/common.py index e1e69991..88585da7 100644 --- a/apps/notification/serializers/common.py +++ b/apps/notification/serializers/common.py @@ -1,10 +1,11 @@ """Notification app serializers.""" - +from django.conf import settings from django.utils.translation import ugettext_lazy as _ from rest_framework import serializers from location.serializers import CountrySimpleSerializer from notification import models +from notification.tasks import send_subscribes_update_email from utils.methods import get_user_ip from utils.serializers import TranslatedField @@ -74,7 +75,23 @@ class CreateSubscribeSerializer(serializers.ModelSerializer): def create(self, validated_data): """Create obj.""" - return models.Subscriber.objects.make_subscriber(**validated_data) + + subscriber = models.Subscriber.objects.make_subscriber(**validated_data) + + if settings.USE_CELERY: + send_subscribes_update_email.delay(subscriber.pk) + else: + send_subscribes_update_email(subscriber.pk) + + return subscriber + + def update(self, instance, validated_data): + if settings.USE_CELERY: + send_subscribes_update_email.delay(instance.pk) + else: + send_subscribes_update_email(instance.pk) + + return super().update(instance, validated_data) class SubscribeObjectSerializer(serializers.ModelSerializer): diff --git a/apps/notification/tasks.py b/apps/notification/tasks.py index 4a0ff5f3..f2e4ccc3 100644 --- a/apps/notification/tasks.py +++ b/apps/notification/tasks.py @@ -6,12 +6,12 @@ from django.core.mail import send_mail from django.template.loader import get_template, render_to_string from main.models import SiteSettings -from notification.models import Subscriber +from notification import models @shared_task def send_subscribes_update_email(subscriber_id): - subscriber = Subscriber.objects.get(subscriber_id) + subscriber = models.Subscriber.objects.get(id=subscriber_id) country_code = subscriber.country_code @@ -24,9 +24,8 @@ def send_subscribes_update_email(subscriber_id): socials_for_subscriber = socials.get(country_code) context = { - "title": "G&M Subscriptions", - "subtitle": "You have subscribed on news G&M", - "description": "\n".join([ + "title": "You have subscribed on news G&M", + "description": "
".join([ name.get(subscriber.locale) for name in subscriber.subscription_types.values_list('name', flat=True) ]), @@ -52,7 +51,7 @@ def send_subscribes_update_email(subscriber_id): @shared_task def send_unsubscribe_email(subscriber_id): - subscriber = Subscriber.objects.get(subscriber_id) + subscriber = models.Subscriber.objects.get(id=subscriber_id) country_code = subscriber.country_code @@ -65,8 +64,7 @@ def send_unsubscribe_email(subscriber_id): socials_for_subscriber = socials.get(country_code) context = { - "title": "G&M Subscriptions", - "subtitle": "You have successfully unsubscribed from G&M news", + "title": "You have successfully unsubscribed from G&M news", "description": "", "code": subscriber.update_code, "domain_uri": settings.DOMAIN_URI, From 3506f6b2f0daba3881e676253312a71bc8c19ee2 Mon Sep 17 00:00:00 2001 From: dormantman Date: Mon, 13 Jan 2020 14:34:11 +0300 Subject: [PATCH 14/18] Change templates --- apps/notification/tasks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/notification/tasks.py b/apps/notification/tasks.py index f2e4ccc3..f5261a82 100644 --- a/apps/notification/tasks.py +++ b/apps/notification/tasks.py @@ -15,7 +15,7 @@ def send_subscribes_update_email(subscriber_id): country_code = subscriber.country_code - html_template = get_template(settings.NEWS_EMAIL_TEMPLATE) + html_template = get_template(settings.NOTIFICATION_SUBSCRIBE_TEMPLATE) year = datetime.now().year socials = list(SiteSettings.objects.with_country().select_related('country')) @@ -55,7 +55,7 @@ def send_unsubscribe_email(subscriber_id): country_code = subscriber.country_code - html_template = get_template(settings.NEWS_EMAIL_TEMPLATE) + html_template = get_template(settings.NOTIFICATION_SUBSCRIBE_TEMPLATE) year = datetime.now().year socials = list(SiteSettings.objects.with_country().select_related('country')) From 34a246abab70ec3e2166306cab15d3a6dafe7015 Mon Sep 17 00:00:00 2001 From: Kuroshini Date: Mon, 13 Jan 2020 14:58:55 +0300 Subject: [PATCH 15/18] try to boost translations fetch --- apps/translation/serializers.py | 6 +++++- apps/translation/views.py | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/translation/serializers.py b/apps/translation/serializers.py index d5d8d553..8f858aa7 100644 --- a/apps/translation/serializers.py +++ b/apps/translation/serializers.py @@ -1,5 +1,6 @@ from rest_framework import serializers from translation import models +from utils.models import get_current_locale class LanguageSerializer(serializers.ModelSerializer): @@ -17,9 +18,12 @@ class LanguageSerializer(serializers.ModelSerializer): class SiteInterfaceDictionarySerializer(serializers.ModelSerializer): """Serializer for model SiteInterfaceDictionary.""" - text_trans = serializers.CharField(read_only=True) + text_trans = serializers.SerializerMethodField(read_only=True) text = serializers.JSONField(write_only=True) + def get_text_trans(self, obj): + return obj.text.get(get_current_locale(), '') if obj.text else '' + class Meta: """Meta class.""" model = models.SiteInterfaceDictionary diff --git a/apps/translation/views.py b/apps/translation/views.py index 1b8c2736..8382f889 100644 --- a/apps/translation/views.py +++ b/apps/translation/views.py @@ -44,6 +44,9 @@ class SiteInterfaceDictionaryView(JWTGenericViewMixin, serializer_class = serializers.SiteInterfaceDictionarySerializer filter_fields = ['page', 'keywords'] + def get_queryset(self): + return models.SiteInterfaceDictionary.objects.all() + class SiteInterfaceDictionaryRetrieveView(JWTGenericViewMixin, SiteInterfaceDictionaryMixin, From ada48b34aa9e62b1df20d9c4211a4dc1715df789 Mon Sep 17 00:00:00 2001 From: Kuroshini Date: Mon, 13 Jan 2020 15:01:17 +0300 Subject: [PATCH 16/18] Revert "try to boost translations fetch" This reverts commit 34a246a --- apps/translation/serializers.py | 6 +----- apps/translation/views.py | 3 --- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/apps/translation/serializers.py b/apps/translation/serializers.py index 8f858aa7..d5d8d553 100644 --- a/apps/translation/serializers.py +++ b/apps/translation/serializers.py @@ -1,6 +1,5 @@ from rest_framework import serializers from translation import models -from utils.models import get_current_locale class LanguageSerializer(serializers.ModelSerializer): @@ -18,12 +17,9 @@ class LanguageSerializer(serializers.ModelSerializer): class SiteInterfaceDictionarySerializer(serializers.ModelSerializer): """Serializer for model SiteInterfaceDictionary.""" - text_trans = serializers.SerializerMethodField(read_only=True) + text_trans = serializers.CharField(read_only=True) text = serializers.JSONField(write_only=True) - def get_text_trans(self, obj): - return obj.text.get(get_current_locale(), '') if obj.text else '' - class Meta: """Meta class.""" model = models.SiteInterfaceDictionary diff --git a/apps/translation/views.py b/apps/translation/views.py index 8382f889..1b8c2736 100644 --- a/apps/translation/views.py +++ b/apps/translation/views.py @@ -44,9 +44,6 @@ class SiteInterfaceDictionaryView(JWTGenericViewMixin, serializer_class = serializers.SiteInterfaceDictionarySerializer filter_fields = ['page', 'keywords'] - def get_queryset(self): - return models.SiteInterfaceDictionary.objects.all() - class SiteInterfaceDictionaryRetrieveView(JWTGenericViewMixin, SiteInterfaceDictionaryMixin, From fdb08923777828f522a940ee5e6a64add6ee48bf Mon Sep 17 00:00:00 2001 From: dormantman Date: Mon, 13 Jan 2020 15:32:40 +0300 Subject: [PATCH 17/18] Update unsubscribe url --- apps/notification/tasks.py | 6 ++---- project/templates/notification/update_email.html | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/apps/notification/tasks.py b/apps/notification/tasks.py index f5261a82..38b11cd5 100644 --- a/apps/notification/tasks.py +++ b/apps/notification/tasks.py @@ -30,8 +30,7 @@ def send_subscribes_update_email(subscriber_id): for name in subscriber.subscription_types.values_list('name', flat=True) ]), "code": subscriber.update_code, - "domain_uri": settings.DOMAIN_URI, - "country_code": subscriber.country_code, + "link_to_unsubscribe": subscriber.link_to_unsubscribe, "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 '#', @@ -67,8 +66,7 @@ def send_unsubscribe_email(subscriber_id): "title": "You have successfully unsubscribed from G&M news", "description": "", "code": subscriber.update_code, - "domain_uri": settings.DOMAIN_URI, - "country_code": subscriber.country_code, + "link_to_unsubscribe": subscriber.link_to_unsubscribe, "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 '#', diff --git a/project/templates/notification/update_email.html b/project/templates/notification/update_email.html index dad6e9b8..0b4444c2 100644 --- a/project/templates/notification/update_email.html +++ b/project/templates/notification/update_email.html @@ -59,7 +59,7 @@
This email has been sent to {{ send_to }} , - click here to unsubscribe + click here to unsubscribe