Added actions mailing
This commit is contained in:
parent
469a246f49
commit
9999096320
|
|
@ -9,7 +9,7 @@ from account.models import User
|
||||||
from location.models import Country
|
from location.models import Country
|
||||||
from utils.methods import generate_string_code
|
from utils.methods import generate_string_code
|
||||||
from utils.models import ProjectBaseMixin, TJSONField, TranslatedFieldsMixin
|
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):
|
class SubscriptionType(ProjectBaseMixin, TranslatedFieldsMixin):
|
||||||
|
|
@ -101,8 +101,6 @@ class Subscriber(ProjectBaseMixin):
|
||||||
|
|
||||||
objects = SubscriberManager()
|
objects = SubscriberManager()
|
||||||
|
|
||||||
# todo: Add sending subscribes with update email
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
"""Meta class."""
|
"""Meta class."""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
"""Notification app serializers."""
|
"""Notification app serializers."""
|
||||||
|
from django.conf import settings
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from location.serializers import CountrySimpleSerializer
|
from location.serializers import CountrySimpleSerializer
|
||||||
from notification import models
|
from notification import models
|
||||||
|
from notification.tasks import send_subscribes_update_email
|
||||||
from utils.methods import get_user_ip
|
from utils.methods import get_user_ip
|
||||||
from utils.serializers import TranslatedField
|
from utils.serializers import TranslatedField
|
||||||
|
|
||||||
|
|
@ -74,7 +75,23 @@ class CreateSubscribeSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
"""Create obj."""
|
"""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):
|
class SubscribeObjectSerializer(serializers.ModelSerializer):
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@ from django.core.mail import send_mail
|
||||||
from django.template.loader import get_template, render_to_string
|
from django.template.loader import get_template, render_to_string
|
||||||
|
|
||||||
from main.models import SiteSettings
|
from main.models import SiteSettings
|
||||||
from notification.models import Subscriber
|
from notification import models
|
||||||
|
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def send_subscribes_update_email(subscriber_id):
|
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
|
country_code = subscriber.country_code
|
||||||
|
|
||||||
|
|
@ -24,9 +24,8 @@ def send_subscribes_update_email(subscriber_id):
|
||||||
socials_for_subscriber = socials.get(country_code)
|
socials_for_subscriber = socials.get(country_code)
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"title": "G&M Subscriptions",
|
"title": "You have subscribed on news G&M",
|
||||||
"subtitle": "You have subscribed on news G&M",
|
"description": "<br>".join([
|
||||||
"description": "\n".join([
|
|
||||||
name.get(subscriber.locale)
|
name.get(subscriber.locale)
|
||||||
for name in subscriber.subscription_types.values_list('name', flat=True)
|
for name in subscriber.subscription_types.values_list('name', flat=True)
|
||||||
]),
|
]),
|
||||||
|
|
@ -52,7 +51,7 @@ def send_subscribes_update_email(subscriber_id):
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def send_unsubscribe_email(subscriber_id):
|
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
|
country_code = subscriber.country_code
|
||||||
|
|
||||||
|
|
@ -65,8 +64,7 @@ def send_unsubscribe_email(subscriber_id):
|
||||||
socials_for_subscriber = socials.get(country_code)
|
socials_for_subscriber = socials.get(country_code)
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"title": "G&M Subscriptions",
|
"title": "You have successfully unsubscribed from G&M news",
|
||||||
"subtitle": "You have successfully unsubscribed from G&M news",
|
|
||||||
"description": "",
|
"description": "",
|
||||||
"code": subscriber.update_code,
|
"code": subscriber.update_code,
|
||||||
"domain_uri": settings.DOMAIN_URI,
|
"domain_uri": settings.DOMAIN_URI,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user