You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

32 lines
1.0 KiB

import requests
from django.conf import settings
from django.contrib.auth import get_user_model
from django.core.management.base import BaseCommand, CommandError
# User = get_user_model()
from apps.user.models import User
class Command(BaseCommand):
help = 'Upload users to Roistat'
def handle(self, *args, **options):
users_queryset = User.objects.all()
users = [
{
'id': str(user.id),
'name': user.get_full_name(),
'phone': str(user.phone),
'email': user.email,
'birth_date': user.birthday.strftime('%d%m%Y') if user.birthday else None,
}
for user in users_queryset
]
project = settings.ROISTAT_PROJECT
key = settings.ROISTAT_KEY
url = settings.ROISTAT_API_URL + f'/project/clients/import?key={key}&project={project}'
resp = requests.post(url, json=users)
self.stdout.write(str(resp))
self.stdout.write(str(resp.json()))