def update_person(email, data): """ Actualiza la información del lenguaje de un usuario en datastore. :param new_lang: Nuevo lenguaje de. usuario. :return: objeto de la clase User """ query = client.query(kind=DATASTORE_PEOPLE_KIND_NAME) query.add_filter('client', '=', email) results = list(query.fetch()) if not results: raise ModelNotFound('userNotExist') entity = results[0] # Se crea la entidad y se sustituye el cambio. entity.update(data) # Se actualiza en datastore. client.put(entity) # Se devuelve el objeto que representa al usuario. updated_person = AssociatedPerson( **entity ) updated_person.id = entity.id return updated_person
def update_worker(filter, id, data): if filter == 'id': key = client.key(DATASTORE_WORKERS_KIND_NAME, int(id)) query = client.query(kind=DATASTORE_WORKERS_KIND_NAME) query.add_filter('__key__', '=', key) if filter == 'email': query = client.query(kind=DATASTORE_WORKERS_KIND_NAME) query.add_filter('email', '=', id) results = list(query.fetch()) if not results: raise ModelNotFound('serviceNotExist') entity = results[0] if 'schedule' in data.keys(): worker = Worker(**entity) worker.id = entity.id schedule = worker.to_dict()['schedule'] schedule.append(data['schedule']) data['schedule'] = schedule entity.update(data) client.put(entity) updated_worker = Worker(**entity) updated_worker.id = entity.id return updated_worker
def create_new_worker(data): key = client.key(DATASTORE_WORKERS_KIND_NAME) entity = datastore.Entity(key=key) new_worker_data = { 'email': data['email'], 'phone': data['phone'], 'status': 'working', 'incorporation_date': datetime.datetime.strptime(data['incorporation_date'], '%d/%m/%Y'), 'final_date': None, 'free': True, 'type': data['type'], 'created': datetime.datetime.now(), 'accept_more_service': True, 'schedule': [] } entity.update(new_worker_data) # Se guarda en datastore. client.put(entity) worker = Worker(**entity) worker.id = entity.id return worker
def create_new_user(params): key = client.key(DATASTORE_USERS_KIND_NAME) entity = datastore.Entity(key=key) new_user_data = { 'email': params['email'], 'dni': params['dni'], 'name': params['name'], 'language': 'es', 'admin': (True if params['admin'] else False) if 'admin' in params.keys() else False, 'user': (True if params['user'] else False) if 'user' in params.keys() else False, 'worker': (True if params['worker'] else False) if 'worker' in params.keys() else False, 'created': datetime.now(), 'picture': params['picture'] } entity.update(new_user_data) # Se guarda en datastore. client.put(entity) user = User(**entity) user.id = entity.id return user
def create_new_address(data, email): key = client.key(DATASTORE_ADDRESS_KIND_NAME) entity = datastore.Entity(key=key) new_user_data = { 'client': email, 'street': data['street'], 'number': data['number'], 'portal': data['portal'], 'piso': data['piso'], 'cp': data['cp'], 'locality': data['locality'], 'city': data['city'], 'country': data['country'], 'aditional': data['aditional'], 'address': data['address'], 'type': data['type'], 'floor': data['floor'], 'room': data['room'] } entity.update(new_user_data) # Se guarda en datastore. client.put(entity) address = Address(**entity) address.id = entity.id return address
def create_new_service(data): key = client.key(DATASTORE_SERVICES_KIND_NAME) entity = datastore.Entity(key=key) new_service_data = { 'client': data['client'], 'phone': data['phone'], 'user': data['user'], 'address': data['address'], 'start_date': datetime.datetime.strptime(data['start_date'], '%d/%m/%Y'), 'end_date': datetime.datetime.strptime(data['end_date'], '%d/%m/%Y'), 'open_end_date': data['open_end_date'], 'status': 'pending', 'type': data['type'], 'worker': None, 'occupation_type': data['occupation_type'], 'schedule': data['schedule'], 'rejected_by': [], 'created': datetime.datetime.now() } entity.update(new_service_data) # Se guarda en datastore. client.put(entity) service = Service(**entity) service.id = entity.id return service
def update_service(id, data): key = client.key(DATASTORE_SERVICES_KIND_NAME, int(id)) query = client.query(kind=DATASTORE_SERVICES_KIND_NAME) query.add_filter('__key__', '=', key) results = list(query.fetch()) if not results: raise ModelNotFound('serviceNotExist') entity = results[0] if 'rejected_by' in data.keys(): user = data['rejected_by'] service = Service(**entity) service.id = entity.id rejected_by = service.to_dict()['rejected_by'] rejected_by.append(user) data['rejected_by'] = rejected_by if data['status'] == 'accepted': service = Service(**entity) service.id = entity.id service_info = service.to_dict() schedule = service_info['schedule'] worker = service_info['worker'] update_worker('email', worker, {'schedule': schedule}) entity.update(data) client.put(entity) updated_service = Service(**entity) updated_service.id = entity.id return updated_service
def create_new_phone(phone, email): key = client.key(DATASTORE_PHONES_KIND_NAME) entity = datastore.Entity(key=key) new_user_data = {'number': phone, 'user': email} entity.update(new_user_data) # Se guarda en datastore. client.put(entity) phone = Phone(**entity) phone.id = entity.id return phone
def new_message(params): key = client.key(DATASTORE_MESSAGES_KIND_NAME) entity = datastore.Entity(key=key) new_message_data = { 'id_chat': str(params['id_chat']), 'from_user': params['from_user'], 'to_user': params['to_user'], 'msg': params['msg'], 'date': datetime.utcnow() } entity.update(new_message_data) # Se guarda en datastore. client.put(entity) message = Messages(**entity) message.id = entity.id return message
def update_price(id, data): key = client.key(DATASTORE_PRICES_KIND_NAME, int(id)) query = client.query(kind=DATASTORE_PRICES_KIND_NAME) query.add_filter('__key__', '=', key) results = list(query.fetch()) if not results: raise ModelNotFound('priceNotExist') entity = results[0] # Se crea la entidad y se sustituye el cambio. entity.update(data) # Se actualiza en datastore. client.put(entity) # Se devuelve el objeto que representa al usuario. updated_price = Price(**entity) updated_price.id = entity.id return updated_price
def create_new_person(data, email): key = client.key(DATASTORE_PEOPLE_KIND_NAME) entity = datastore.Entity(key=key) new_user_data = { 'client': email, 'name': data['name'], 'age': data['age'], 'dependence': data['dependence'] or None, 'disability': data['disability'] or None, 'desc_disability': data['desc_disability'], 'pattern': data['pattern'] or None, 'observations': data['observations'], 'type': data['type'] } entity.update(new_user_data) # Se guarda en datastore. client.put(entity) person = AssociatedPerson( **entity ) person.id = entity.id return person