def create_location(): request_body = json.loads(request.data) location = Location(name=request_body.get('name', 'unnamed-location')) db.session.add(location) db.session.commit() return json.dumps({'success': True, 'data': location.serialize()}), 201
def add_location(longitude, latitude): from db import Location, db location = Location() location.longitude = longitude location.latitude = latitude db.session.add(location) db.session.commit() return location
def get_or_create_location(loc_elem, ctx): name = unicode(loc_elem.get('name')) q = session.query(Location).filter_by( name=name, region_id=ctx['region'].id, ) try: loc = q.one() except NoResultFound: loc = Location() loc.name = name loc.region = ctx['region'] session.add(loc) return loc
def _get_or_create_location(city, state, zipcode, restaurant_id): location = Location.query.filter_by(zipcode=zipcode).first() if location is not None: return location new_location = Location(city=city, state=state, zipcode=zipcode, restaurant_id=restaurant_id) db.session.add(new_location) db.session.commit() return new_location
def query_location(name=None, latitude=None, longitude=None): location = None session = Session(expire_on_commit=False) if name is not None and len(name) > 0: name = unquote(name) location = session.query(Location).filter( Location.name.like(name)).first() if (latitude is not None and len(latitude) > 0 and longitude is not None and len(longitude) > 0): if location is None: # print('create') location = Location(name=name.upper(), latitude=latitude, longitude=longitude) session.add(location) else: # print('update') location.latitude = latitude location.longitude = longitude location.lastseen = datetime.now() session.commit() else: # not on our database if location is None: # print('import') rloc = locator.geocode(name) location = Location(name=name.upper(), latitude=rloc.latitude, longitude=rloc.longitude) session.add(location) session.commit() else: location = session.query(Location).order_by(Location.name.asc()).all() session.close() return to_csv(location)
def get_or_create_location(user, location_name, location_description): location, _ = Location.get_or_create(title=location_name, defaults={'created_by': user.pk, 'description': location_description}) return location