diff --git a/apps/notification/models.py b/apps/notification/models.py
index 4c221280..e0855c62 100644
--- a/apps/notification/models.py
+++ b/apps/notification/models.py
@@ -57,7 +57,6 @@ class SubscriberManager(models.Manager):
obj.country_code = country_code
obj.locale = locale
obj.update_code = generate_string_code()
-
obj.save()
else:
@@ -66,10 +65,12 @@ class SubscriberManager(models.Manager):
country_code=country_code, locale=locale,
)
- if subscription_types is not None:
- obj.subscription_types.set(subscription_types)
- obj.subscribe_set.update(unsubscribe_date=None)
- obj.save()
+ if subscription_types is None:
+ subscription_types = []
+
+ obj.subscription_types.set(subscription_types)
+ obj.subscribe_set.update(unsubscribe_date=None)
+ obj.save()
return obj
@@ -135,9 +136,9 @@ class Subscriber(ProjectBaseMixin):
self.subscribe_set.update(unsubscribe_date=now())
if settings.USE_CELERY:
- send_unsubscribe_email.delay(self.pk)
+ send_unsubscribe_email.delay(self.email)
else:
- send_unsubscribe_email(self.pk)
+ send_unsubscribe_email(self.email)
@property
def send_to(self):
diff --git a/apps/notification/tasks.py b/apps/notification/tasks.py
index 5129ad59..790c9650 100644
--- a/apps/notification/tasks.py
+++ b/apps/notification/tasks.py
@@ -3,6 +3,7 @@ from datetime import datetime
from celery import shared_task
from django.conf import settings
from django.core.mail import send_mail
+from django.utils.translation import gettext_lazy as _
from django.template.loader import get_template, render_to_string
from main.models import SiteSettings
@@ -27,11 +28,11 @@ def send_subscribes_update_email(email):
socials_for_subscriber = socials.get(country_code)
context = {
- "title": "You have subscribed on news G&M",
- "description": "
".join([
- name.get(subscriber.locale)
+ "title": _("You have subscribed on news G&M"),
+ "description": _("
".join([
+ name.get(subscriber.locale) if subscriber.locale in name else name.get(next(iter(name.keys())))
for name in subscriber.subscription_types.values_list('name', flat=True)
- ]),
+ ])),
"code": subscriber.update_code,
"link_to_unsubscribe": subscriber.link_to_unsubscribe,
"twitter_page_url": socials_for_subscriber.twitter_page_url if socials_for_subscriber else '#',
@@ -42,7 +43,7 @@ def send_subscribes_update_email(email):
}
send_mail(
- subject="G&M Subscriptions",
+ subject=_("G&M Subscriptions"),
message=render_to_string(settings.NOTIFICATION_SUBSCRIBE_TEMPLATE, context),
from_email=settings.EMAIL_HOST_USER,
recipient_list=[subscriber.send_to],
@@ -52,8 +53,11 @@ def send_subscribes_update_email(email):
@shared_task
-def send_unsubscribe_email(subscriber_id):
- subscriber = models.Subscriber.objects.get(id=subscriber_id)
+def send_unsubscribe_email(email):
+ subscriber = models.Subscriber.objects.filter(email=email).first()
+
+ if subscriber is None:
+ return
country_code = subscriber.country_code
@@ -66,7 +70,7 @@ def send_unsubscribe_email(subscriber_id):
socials_for_subscriber = socials.get(country_code)
context = {
- "title": "You have successfully unsubscribed from G&M news",
+ "title": _("You have successfully unsubscribed from G&M news"),
"description": "",
"code": subscriber.update_code,
"link_to_unsubscribe": subscriber.link_to_unsubscribe,
diff --git a/project/templates/notification/update_email.html b/project/templates/notification/update_email.html
index 0b4444c2..dd39f790 100644
--- a/project/templates/notification/update_email.html
+++ b/project/templates/notification/update_email.html
@@ -1,4 +1,5 @@
+{% load i18n %}
- Follow us
+ {% trans "Follow us" %}