added transfer for notification app
This commit is contained in:
parent
1264ba963f
commit
8d0f4a8a00
21
apps/notification/transfer_data.py
Normal file
21
apps/notification/transfer_data.py
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
from transfer.serializers.notification import SubscriberSerializer
|
||||||
|
from notification.models import Subscriber
|
||||||
|
from transfer.models import EmailAddresses
|
||||||
|
from django.db.models import Value, IntegerField, F
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
|
||||||
|
def transfer_subscriber():
|
||||||
|
queryset = EmailAddresses.objects.filter(state="usable")
|
||||||
|
|
||||||
|
serialized_data = SubscriberSerializer(data=list(queryset.values()), many=True)
|
||||||
|
|
||||||
|
if serialized_data.is_valid():
|
||||||
|
serialized_data.save()
|
||||||
|
else:
|
||||||
|
pprint(f"News serializer errors: {serialized_data.errors}")
|
||||||
|
|
||||||
|
|
||||||
|
data_types = {
|
||||||
|
"subscriber": [transfer_subscriber]
|
||||||
|
}
|
||||||
|
|
@ -11,7 +11,8 @@ class Command(BaseCommand):
|
||||||
DATA_TYPES = [
|
DATA_TYPES = [
|
||||||
'dictionaries',
|
'dictionaries',
|
||||||
'news',
|
'news',
|
||||||
'account'
|
'account',
|
||||||
|
'subscriber'
|
||||||
]
|
]
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
|
|
|
||||||
34
apps/transfer/serializers/notification.py
Normal file
34
apps/transfer/serializers/notification.py
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
from rest_framework import serializers
|
||||||
|
from notification.models import Subscriber
|
||||||
|
|
||||||
|
|
||||||
|
class SubscriberSerializer(serializers.ModelSerializer):
|
||||||
|
email = serializers.CharField()
|
||||||
|
locale = serializers.CharField(allow_null=True)
|
||||||
|
country_code = serializers.CharField(allow_null=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Subscriber
|
||||||
|
fields = (
|
||||||
|
"email",
|
||||||
|
"locale",
|
||||||
|
"country_code"
|
||||||
|
)
|
||||||
|
|
||||||
|
def validate(self, data):
|
||||||
|
data["email"] = self.get_email(data)
|
||||||
|
data["locale"] = self.get_locale(data)
|
||||||
|
data["country_code"] = self.get_country_code(data)
|
||||||
|
return data
|
||||||
|
|
||||||
|
def create(self, validated_data):
|
||||||
|
Subscriber.objects.create(**validated_data)
|
||||||
|
|
||||||
|
def get_email(self, obj):
|
||||||
|
return obj["email"]
|
||||||
|
|
||||||
|
def get_locale(self, obj):
|
||||||
|
return obj["locale"]
|
||||||
|
|
||||||
|
def get_country_code(self, obj):
|
||||||
|
return obj["country_code"]
|
||||||
Loading…
Reference in New Issue
Block a user