示例#1
0
    def post(self, request, client, client_id):
        data = json.loads(request.body.decode('utf-8'))

        account_data = {}
        account_data['login'] = data.pop('login')
        account_data['password'] = data.pop('password')
        data.pop('role', None)

        result = BaseAccontsView.user_validator(account_data)
        if result['status'] != 'Success':
            return result

        response = requests.post(settings.DANCERS_SERVICE_BASE_URL +
                                 'dancers/sportsmans/',
                                 headers={
                                     'Authorization': settings.SERVICE_SECRET,
                                     'From': settings.SERVICE_ID,
                                     'To': 'Dancers'
                                 },
                                 json=data)

        if response.status_code != 200:
            return {
                'status': 'Failed',
                'message': 'Service Error',
                'code': 500
            }

        print(response.json())
        account_data['uuid'] = response.json()['data']
        account_data['password'] = BaseView.hash_password(
            account_data['password'])
        response = Users.objects.create(**account_data).pk
        BaseView.log(user_auth_log, request, client, client_id)
        return {'status': 'Success', 'data': response, 'code': 200}
 def post(self, request, client, client_id):
     # TODO отправка данных на сервис танцоров
     data = json.loads(request.body.decode('utf-8'))
     data['service_secret'] = BaseView.hash_password(data['service_secret'])
     response = Services.objects.create(**data).pk
     BaseView.log(service_log, request, client, client_id)
     return {'status': 'Success', 'data': response, 'code': 200}
示例#3
0
 def get(self, request, uuid, client, client_id):
     response = list(Application.objects.filter(pk=uuid).values())
     if not response:
         return {
             'status': 'Failed',
             'message': 'Object does not exist',
             'code': 404
         }
     BaseView.log(log, request, client, client_id)
     return {'status': 'Success', 'data': response, 'code': 200}
示例#4
0
    def delete(self, request, uuid, client, client_id):

        response = requests.delete(
            settings.DANCERS_SERVICE_BASE_URL +
            'dancers/sportsman/{}/'.format(uuid),
            headers={
                'Authorization': settings.SERVICE_SECRET,
                'From': settings.SERVICE_ID,
                'To': 'Dancers'
            },
        )
        print(response.status_code)
        if response.status_code != 200:
            return {
                'status': 'Failed',
                'message': 'Service Error',
                'code': 500
            }

        entry = Users.objects.filter(pk=uuid)
        entry.delete()
        BaseView.log(user_auth_log, request, client, client_id)
        return {'status': 'Success', 'code': 200}
示例#5
0
 def delete(self, request, uuid, client, client_id):
     # TODO отправлка данных на сервис танцоров
     entry = Application.objects.filter(pk=uuid)
     entry.delete()
     BaseView.log(log, request, client, client_id)
     return {'status': 'Success', 'code': 200}
示例#6
0
 def patch(self, request, uuid, client, client_id):
     data = json.loads(request.body.decode('utf-8'))
     Application.objects.filter(pk=uuid).update(**data)
     response = list(Application.objects.filter(pk=uuid).values())
     BaseView.log(log, request, client, client_id)
     return {'status': 'Success', 'data': response, 'code': 200}
示例#7
0
 def post(self, request, client, client_id):
     # TODO отправка данных на сервис танцоров
     data = json.loads(request.body.decode('utf-8'))
     response = Application.objects.create(**data).pk
     BaseView.log(log, request, client, client_id)
     return {'status': 'Success', 'data': response, 'code': 200}
示例#8
0
 def get(self, request, client, client_id):
     params = request.GET
     response = list(Application.objects.filter(**params).values())
     BaseView.log(log, request, client, client_id)
     return {'status': 'Success', 'data': response, 'code': 200}