def create(event, context): data = json.loads(event['body']) if not validate_location_json(data): raise Exception('Invalid content provided.') try: location = LocationModel(name=data['name'], street_1=data['street_1'], street_2=data.get('street_2', None), city=data['city'], state=data['state'], zip_code=data['zip_code'], country=data['country'], type_id=data['type_id']) location.save() response = {'statusCode': 200, 'body': json.dumps(dict(location))} except Exception as ex: response = { 'statusCode': 500, 'body': json.dumps({'errorMessage': 'There was a problem saving'}) } return response
def create_location(): if request.method == "POST": name = request.form["name"] new_location = LocationModel(name=name) new_location.save() else: return render_template("add-location.html") pass
def update(event, context): id = event['pathParameters']['id'] location = LocationModel.get(id) if location is None: raise Exception('Not found') return data = json.loads(event['body']) try: location.name = data.get('name', location.name) location.street_1 = data.get('street_1', location.street_1) location.street_2 = data.get('street_2', location.street_2) location.city = data.get('city', location.city) location.state = data.get('state', location.state) location.zip_code = data.get('zip_code', location.zip_code) location.type_id = data.get('type_id', location.type_id) location.save() response = {'statusCode': 200, 'body': json.dumps(dict(location))} except Exception as ex: response = { 'statusCode': 500, 'body': json.dumps({'errorMessage': 'There was a problem saving'}) } return response
def list(event, context): results = LocationModel.scan() return { 'statusCode': 200, 'body': json.dumps({'locations': [dict(result) for result in results]}) }
def _add_locations(lines_as_ordered_dicts, case): return { location: LocationModel( facies_name=location.facies, zone_name=location.zone, region_name=location.region, license=location.license, case=case, ) for location in _get_unique_locations(lines_as_ordered_dicts) }
def get(event, context): id = event['pathParameters']['id'] try: location = LocationModel.get(id) response = {'statusCode': 200, 'body': json.dumps(dict(location))} except Exception as ex: response = { 'statusCode': 500, 'body': json.dumps({'errorMessage': 'There was a problem deleting'}) } return response
def save_location (self,name,phone_number,id): if id>0: location_k = ndb.Key('LocationModel',long(id)) location = location_k.get() else: #lib = LibraryModel(id='Library',name='My Library') #lib.put() location = LocationModel() location.name = name location.phone_number = phone_number location.username = users.get_current_user().email() location.put()
def list_location (self): #lib = ndb.Key('LibraryModel','Library') # get locations for table location_query = LocationModel.query() return location_query