Added localization to subscribes

This commit is contained in:
dormantman 2020-01-21 14:39:49 +03:00
parent a8dd7f9347
commit 8e6d433ffd
3 changed files with 25 additions and 19 deletions

View File

@ -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):

View File

@ -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": "<br>".join([
name.get(subscriber.locale)
"title": _("You have subscribed on news G&M"),
"description": _("<br>".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,

View File

@ -1,4 +1,5 @@
<!DOCTYPE html>
{% load i18n %}
<html lang="en" style="box-sizing: border-box;margin: 0;">
<head>
<meta charset="UTF-8">
@ -40,9 +41,9 @@
<div class="letter__follow-content" style="padding: 1.25rem 0;background: #fff;text-align: center;">
<div class="letter__follow-header" style="display: inline-block;margin: 0 0 18px;font-family: &quot;PT Serif&quot;, sans-serif;font-size: 1.25rem;text-transform: uppercase;">
<img alt="thumb" style="width:30px;vertical-align: sub; display: inline-block" src="https://s3.eu-central-1.amazonaws.com/gm-test.com/manually_uploaded/2.png" />
<span class="letter__follow-title">Follow us</span>
<span class="letter__follow-title">{% trans "Follow us" %}</span>
</div>
<div class="letter__follow-text" style="display: block;margin: 0 0 30px;font-size: 12px;font-style: italic;">You can also us on our social network below
<div class="letter__follow-text" style="display: block;margin: 0 0 30px;font-size: 12px;font-style: italic;">{% trans "You can also us on our social network below" %}
</div>
<div class="letter__follow-social">
<a href="{{ facebook_page_url }}" class="letter__follow-link" target="_blank" style="color: #000;font-weight: 700;text-decoration: none;padding: 0;border-bottom: 1.5px solid #ffee29;cursor: pointer;display: inline-block;width: 30px;height: 30px;margin: 0 1rem 0 0;background: #ffee29;border: none;">
@ -58,8 +59,8 @@
</div>
</div>
<div class="letter__unsubscribe" style="margin: 0 0 1.25rem;font-size: 12px;text-align: center;">
<span class="letter__unsubscribe-dscr" style="display: inline-block;">This email has been sent to {{ send_to }} ,</span>
<a href="{{ link_to_unsubscribe }}" target="_blank" style="color: #000;font-weight: 700;text-decoration: none;padding: 0;border-bottom: 1.5px solid #ffee29;cursor: pointer;">click here to unsubscribe</a>
<span class="letter__unsubscribe-dscr" style="display: inline-block;">{% trans "This email has been sent to" %} {{ send_to }} ,</span>
<a href="{{ link_to_unsubscribe }}" target="_blank" style="color: #000;font-weight: 700;text-decoration: none;padding: 0;border-bottom: 1.5px solid #ffee29;cursor: pointer;">{% trans "click here to unsubscribe" %}</a>
</div>
<div class="letter__footer" style="padding: 24px 0 15px;text-align: center;background: #ffee29;">
<div class="letter__footer-logo" style="width: 71px;height: 42px;margin: 0 auto 14px auto;">