Merge branch 'feature/subscriptions' into 'develop'
Fixed creating subscriber with signup See merge request gm/gm-backend!227
This commit is contained in:
commit
1c4060ac7b
|
|
@ -9,8 +9,10 @@ from rest_framework.generics import get_object_or_404
|
||||||
from account import models as account_models
|
from account import models as account_models
|
||||||
from authorization import tasks
|
from authorization import tasks
|
||||||
from authorization.models import JWTRefreshToken
|
from authorization.models import JWTRefreshToken
|
||||||
|
from notification.models import Subscriber
|
||||||
from utils import exceptions as utils_exceptions
|
from utils import exceptions as utils_exceptions
|
||||||
from utils import methods as utils_methods
|
from utils import methods as utils_methods
|
||||||
|
from utils.methods import get_user_ip
|
||||||
from utils.serializers import SourceSerializerMixin
|
from utils.serializers import SourceSerializerMixin
|
||||||
from utils.tokens import GMRefreshToken
|
from utils.tokens import GMRefreshToken
|
||||||
|
|
||||||
|
|
@ -61,6 +63,8 @@ class SignupSerializer(serializers.ModelSerializer):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
|
request = self.context.get('request')
|
||||||
|
|
||||||
"""Overridden create method"""
|
"""Overridden create method"""
|
||||||
|
|
||||||
username = validated_data.get('username')
|
username = validated_data.get('username')
|
||||||
|
|
@ -74,15 +78,23 @@ class SignupSerializer(serializers.ModelSerializer):
|
||||||
password=validated_data.get('password'),
|
password=validated_data.get('password'),
|
||||||
email=validated_data.get('email'),
|
email=validated_data.get('email'),
|
||||||
newsletter=validated_data.get('newsletter'))
|
newsletter=validated_data.get('newsletter'))
|
||||||
|
|
||||||
# Send verification link on user email
|
# Send verification link on user email
|
||||||
if settings.USE_CELERY:
|
if settings.USE_CELERY:
|
||||||
tasks.send_confirm_email.delay(
|
tasks.send_confirm_email.delay(
|
||||||
user_id=obj.id,
|
user_id=obj.id,
|
||||||
country_code=self.context.get('request').country_code)
|
country_code=request.country_code)
|
||||||
else:
|
else:
|
||||||
tasks.send_confirm_email(
|
tasks.send_confirm_email(
|
||||||
user_id=obj.id,
|
user_id=obj.id,
|
||||||
country_code=self.context.get('request').country_code)
|
country_code=request.country_code)
|
||||||
|
|
||||||
|
# Make subscriber
|
||||||
|
Subscriber.objects.make_subscriber(
|
||||||
|
email=obj.email, user=obj, ip_address=get_user_ip(request),
|
||||||
|
country_code=request.country_code, locale=request.locale
|
||||||
|
)
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,8 +59,9 @@ class SubscriberManager(models.Manager):
|
||||||
country_code=country_code, locale=locale
|
country_code=country_code, locale=locale
|
||||||
)
|
)
|
||||||
|
|
||||||
obj.subscription_types.set(subscription_types)
|
if subscription_types is not None:
|
||||||
obj.subscribe_set.update(unsubscribe_date=None)
|
obj.subscription_types.set(subscription_types)
|
||||||
|
obj.subscribe_set.update(unsubscribe_date=None)
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user