parent
13eafdc518
commit
382d9a76e8
5 changed files with 60 additions and 0 deletions
@ -0,0 +1,32 @@ |
|||||||
|
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())) |
||||||
Loading…
Reference in new issue