Пример #1
0
    def saveUser(self):
        u1 = users.get_user(self.get_current_user())

        if u1 is not None:
            self.write(u1["user_name"])
        else:
            users.insert(self.get_current_user())

            u1 = users.get_user(self.get_current_user())

        self.write(u1["user_name"])
Пример #2
0
def get_service_controller_id(**params):
    service = get_service_id(params['id'])
    service_info = service.to_dict()
    people = []
    people_details = []
    for one_person in service_info['user']:
        person = get_user_config_id_controller({
            'type': 'person',
            'id': one_person
        })
        people_details.append(person)
        people.append(person['name'])
    service_info['user'] = people
    service_info['user_details'] = people_details
    address = get_user_config_id_controller({
        'type': 'address',
        'id': service_info['address']
    })
    service_info['address'] = '' + address['street'] + ' ' + str(
        address['number']) + ' ' + address['city']
    service_info['address_details'] = address
    client_details = get_user(service_info['client'])
    service_info['client_details'] = client_details.to_dict()
    if service_info['worker'] is not None and service_info['worker'] != '':
        worker = get_worker_controller_id({'email': service_info['worker']})
        service_info['worker_details'] = worker.json
    else:
        worker = None
        service_info['worker_details'] = worker
    return jsonify(service_info)
Пример #3
0
def post_user_controller(**params):
    try:
        user = get_user(params['email'])
        if user.to_dict()['admin']:
            return jsonify(user.to_dict())
        else:
            update_user(user.to_dict()['email'], **{'admin': True})
    except ModelNotFound:
        user = create_new_user(params)
    return jsonify(user.to_dict())
Пример #4
0
def check_catering_user():
    token_info = get_token_info()
    email = token_info['email']

    try:
        user = get_user(email)
    except ModelNotFound:
        raise Unauthorized('notAuthorized')

    if not user.catering:
        raise Unauthorized('notAuthorized')
Пример #5
0
def get_worker_controller_id(params):
    if 'id' in params.keys():
        worker = get_worker_id('id',params['id'])
    elif 'email' in params.keys():
        worker = get_worker_id('email',params['email'])
    worker_info = worker.to_dict()
    user_details = get_user(worker_info['email'])
    worker_info['name'] = user_details.to_dict()['name']
    worker_info['dni'] = user_details.to_dict()['dni']
    worker_info['picture'] = user_details.to_dict()['picture']
    return jsonify(worker_info)
Пример #6
0
def post_worker_controller(**params):
    try:
        user = get_user(params['data_user']['email'])
        if user.to_dict()['worker']:
            return jsonify(user.to_dict())
        else:
            update_user(user.to_dict()['email'], **{'worker': True})
    except ModelNotFound:
        user = create_new_user(params['data_user'])
        logging.info(user)
    worker = create_new_worker(params['data_worker'])
    return jsonify(worker.to_dict())
Пример #7
0
def get_service_controller(**params):
    try:
        if 'status' in params.keys() and 'email' in params.keys():
            if 'order' in params.keys():
                services = get_services(params['email'], params['filter'],
                                        params['status'], params['order'])
            else:
                services = get_services(params['email'], params['filter'],
                                        params['status'])
        elif 'status' in params.keys() and 'email' not in params.keys():
            if 'order' in params.keys():
                services = get_services(status=params['status'],
                                        order=params['order'])
            else:
                services = get_services(status=params['status'])
        elif 'status' not in params.keys() and 'email' in params.keys():
            services = get_services(params['email'], params['filter'])
        else:
            services = get_services()
    except ModelNotFound:
        logging.info('No existen servicios')
        return jsonify([])

    response = []
    for service in services:
        service_info = service.to_dict()
        people = []
        for one_person in service_info['user']:
            person = get_user_config_id_controller({
                'type': 'person',
                'id': one_person
            })
            people.append(person['name'])
        service_info['user'] = people
        address = get_user_config_id_controller({
            'type': 'address',
            'id': service_info['address']
        })
        service_info['address'] = '' + address['street'] + ' ' + str(
            address['number']) + ' ' + address['city']
        client = get_user(service_info['client'])
        service_info['client_details'] = client.to_dict()
        if service_info['worker'] is not None and service_info['worker'] != '':
            worker = get_worker_controller_id(
                {'email': service_info['worker']})
            service_info['worker_details'] = worker.json
        else:
            worker = None
            service_info['worker_details'] = worker
        response.append(service_info)
    return jsonify(response)
Пример #8
0
def get_worker_controller(params):
    try:
        if len(params) == 0:
            workers = get_workers()
        else:
            service = get_service_id(params['service'])
            workers = get_workers_to_service(service.to_dict())
    except ModelNotFound:
        logging.info('No existen trabajadores')
        return jsonify([])

    response = []
    for worker in workers:
        worker_info = worker.to_dict()
        user_details = get_user(worker_info['email'])
        worker_info['name'] = user_details.to_dict()['name']
        worker_info['dni'] = user_details.to_dict()['dni']
        worker_info['picture'] = user_details.to_dict()['picture']
        response.append(worker_info)
    return jsonify(response)
Пример #9
0
def is_worker(email):
    try:
        user = get_user(email)
        return user.worker
    except ModelNotFound:
        raise NotFound('userNotFound')
Пример #10
0
def is_admin(email):
    try:
        user = get_user(email)
        return user.admin
    except ModelNotFound:
        raise NotFound('userNotFound')
Пример #11
0
def get_user_profile_controller(params):
    email = params['email']
    user = get_user(email)
    return jsonify(user.to_dict())