def put_new_city(): session = get_session() content = g.data locale = get_post_locale(session) city = City() name_id = str(uuid4()) locale_string = LocaleString(id=name_id, locale=locale, text=content['name']) city.name_id = name_id city.name.set(locale_string) description_id = str(uuid4()) locale_string = LocaleString(id=description_id, locale=locale, text=content['description']) city.description_id = name_id city.description.set(locale_string) city.image_link = content['image_link'] session.add(city) session.commit() session.close() return 'ok'
def post_city_by_id(city_id): session = get_session() city = session.query(City).get(city_id) locale = get_post_locale(session) if city is None: session.close() abort(404, "City with id = %s not found" % city_id) return content = g.data city.name.set( LocaleString(id=city.name_id, locale=locale, text=content['name'])) city.description.set( LocaleString(id=city.description_id, locale=locale, text=content['description'])) city.image_link = content['image_link'] session.commit() session.close() return 'ok'
def put_new_category(): session = get_session() content = g.data locale = get_post_locale(session) category = Category() name_id = str(uuid4()) locale_string = LocaleString(id=name_id, locale=locale, text=content['name']) category.name_id = name_id category.name.set(locale_string) category.label = content['label'] session.add(category) session.commit() session.close() return 'ok'
def post_category_by_id(category_id): session = get_session() category = session.query(Category).get(category_id) locale = get_post_locale(session) if category is None: session.close() abort(404, "Category with id = %s not found" % category_id) return content = g.data category.name.set( LocaleString(id=category.name_id, locale=locale, text=content['name'])) category.label = content['label'] session.commit() session.close() return 'ok'
def put_new_place(): session = get_session() content = g.data locale = get_post_locale(session) if session.query(City).get(content['city_id']) is None: session.close() abort(400, "City with id = %s not found" % content['city_id']) return geolocation = Geolocation( latitude=content['latitude'], longitude=content['longitude'] ) categories = [] for category_id in content['categories']: category = session.query(Category).get(category_id) if category is None: session.close() abort(400, "Category with id = %s not found" % category_id) return categories.append(category) place = Place( image_link=content['image_link'], city_id=content['city_id'], geolocation=geolocation, categories=categories ) name_id = str(uuid4()) locale_string = LocaleString( id=name_id, locale=locale, text=content['name'] ) place.name_id = name_id place.name.set(locale_string) description_id = str(uuid4()) locale_string = LocaleString( id=description_id, locale=locale, text=content['description'] ) place.description_id = description_id place.description.set(locale_string) address_id = str(uuid4()) locale_string = LocaleString( id=address_id, locale=locale, text=content['address'] ) place.address_id = address_id place.address.set(locale_string) if 'audioguide_link' in content: audioguide_link_id = str(uuid4()) locale_link = LocaleLink( id=audioguide_link_id, locale=locale, path=content['audioguide_link'] ) place.audioguide_link_id = audioguide_link_id place.audioguide_link.set(locale_link) session.add(place) session.commit() session.close() return 'ok'
def post_place_by_id(object_id): session = get_session() place = session.query(Place).get(object_id) locale = get_post_locale(session) if place is None: session.close() abort(404, "Place with id = %s not found" % object_id) return content = g.data if session.query(City).get(content['city_id']) is None: session.close() abort(400, "City with id = %s not found" % content['city_id']) return place.image_link = content['image_link'] place.city_id = content['city_id'] geolocation = session.query(Geolocation).get(place.geolocation_id) geolocation.latitude = content['latitude'] geolocation.longitude = content['longitude'] place.name.set(LocaleString( id=place.name_id, locale=locale, text=content['name'] )) place.description.set(LocaleString( id=place.description_id, locale=locale, text=content['description'] )) place.address.set(LocaleString( id=place.address_id, locale=locale, text=content['address'] )) if 'audioguide_link' in content: if place.audioguide_link_id is not None: place.audioguide_link.set(LocaleLink( id=place.audioguide_link_id, locale=locale, path=content['audioguide_link'] )) else: audioguide_link_id = str(uuid4()) locale_link = LocaleLink( id=audioguide_link_id, locale=locale, path=content['audioguide_link'] ) place.audioguide_link_id = audioguide_link_id place.audioguide_link.set(locale_link) else: if place.audioguide_link_id is not None: locale_link = session.query(LocaleLink).filter( LocaleLink.id == place.audioguide_link_id, LocaleLink.locale == locale ).first() session.delete(locale_link) categories = [] for category_id in content['categories']: category = session.query(Category).get(category_id) if category is None: session.close() abort(400, "Category with id = %s not found" % category_id) return categories.append(category) place.categories = categories session.commit() session.close() return 'ok'
def put_new_route(): content = g.data session = get_session() locale = get_post_locale(session) places = [] for index, place_info in enumerate(content['places']): if session.query(Place).get(place_info['id']) is None: session.close() abort(400, "Place with id = %s not found" % (place_info['id'])) return route_place_info = RoutePlaceInfo( place_id=place_info['id'], order=index, ) if 'description' in place_info: description_id = str(uuid4()) locale_string = LocaleString( id=description_id, locale=locale, text=place_info['description'] ) route_place_info.description_id = description_id route_place_info.description.set(locale_string) if 'audioguide_link' in place_info: audioguide_link_id = str(uuid4()) locale_link = LocaleLink( id=audioguide_link_id, locale=locale, path=place_info['audioguide_link'] ) route_place_info.audioguide_link_id = audioguide_link_id route_place_info.audioguide_link.set(locale_link) places.append(route_place_info) route = Route( places=places, city_id=content['city_id'] ) name_id = str(uuid4()) locale_string = LocaleString( id=name_id, locale=locale, text=content['name'] ) route.name_id = name_id route.name.set(locale_string) description_id = str(uuid4()) locale_string = LocaleString( id=description_id, locale=locale, text=content['description'] ) route.description_id = description_id route.description.set(locale_string) session.add(route) session.commit() session.close() return 'ok'
def post_historical_person_by_id(object_id): session = get_session() content = g.data locale = get_post_locale(session) historical_person = session.query(HistoricalPerson).get(object_id) if historical_person is None: session.close() abort(404, "Historical person with id = %s not found" % object_id) return if session.query(City).get(content['city_id']) is None: session.close() abort(400, "City with id = %s not found" % content['city_id']) return historical_person.image_link = content['image_link'] historical_person.city_id = content['city_id'] historical_person.birthdate = content['birthdate'] if 'deathdate' in content: historical_person.deathdate = content['deathdate'] historical_person.name.set( LocaleString(id=historical_person.name_id, locale=locale, text=content['name'])) historical_person.second_name.set( LocaleString(id=historical_person.second_name_id, locale=locale, text=content['second_name'])) if 'patronymic' in content: if historical_person.patronymic_id is not None: historical_person.patronymic.set( LocaleString(id=historical_person.patronymic_id, locale=locale, text=content['patronymic'])) else: patronymic_id = str(uuid4()) locale_string = LocaleString(id=patronymic_id, locale=locale, text=content['patronymic']) historical_person.patronymic_id = patronymic_id historical_person.patronymic.set(locale_string) else: if historical_person.patronymic_id is not None: locale_string = session.query(LocaleString).filter( LocaleString.id == historical_person.patronymic_id, LocaleString.locale == locale).first() session.delete(locale_string) if 'audioguide_link' in content: if historical_person.audioguide_link_id is not None: historical_person.audioguide_link.set( LocaleLink(id=historical_person.audioguide_link_id, locale=locale, path=content['audioguide_link'])) else: audioguide_link_id = str(uuid4()) locale_link = LocaleLink(id=audioguide_link_id, locale=locale, path=content['audioguide_link']) historical_person.audioguide_link_id = audioguide_link_id historical_person.audioguide_link.set(locale_link) else: if historical_person.audioguide_link_id is not None: locale_link = session.query(LocaleLink).filter( LocaleLink.id == historical_person.audioguide_link_id, LocaleLink.locale == locale).first() session.delete(locale_link) historical_person.description.set( LocaleString(id=historical_person.description_id, locale=locale, text=content['description'])) categories = [] for category_id in content['categories']: category = session.query(Category).get(category_id) if category is None: session.close() abort(400, "Category with id = %s not found" % category_id) return categories.append(category) historical_person.categories = categories related_objects = [] if 'related_objects' in content: for object_id in content['related_objects']: obj = session.query(Object).get(object_id) if obj is None: session.close() abort(400, "Related object with id = %s not found" % object_id) return related_objects.append(obj) historical_person.related_objects = related_objects session.commit() session.close() return 'ok'
def put_new_historical_person(): content = g.data session = get_session() locale = get_post_locale(session) if session.query(City).get(content['city_id']) is None: session.close() abort(400, "City with id = %s not found" % content['city_id']) return categories = [] for category_id in content['categories']: category = session.query(Category).get(category_id) if category is None: session.close() abort(400, "Category with id = %s not found" % category_id) return categories.append(category) historical_person = HistoricalPerson( image_link=content['image_link'], city_id=content['city_id'], birthdate=content['birthdate'], categories=categories, ) if 'deathdate' in content: historical_person.deathdate = content['deathdate'] related_objects = [] if 'related_objects' in content: for object_id in content['related_objects']: with session.no_autoflush: obj = session.query(Object).get(object_id) if obj is None: session.close() abort(400, "Related object with id = %s not found" % object_id) return related_objects.append(obj) historical_person.related_objects = related_objects name_id = str(uuid4()) locale_string = LocaleString(id=name_id, locale=locale, text=content['name']) historical_person.name_id = name_id historical_person.name.set(locale_string) second_name_id = str(uuid4()) locale_string = LocaleString(id=second_name_id, locale=locale, text=content['second_name']) historical_person.second_name_id = second_name_id historical_person.second_name.set(locale_string) if 'patronymic' in content: patronymic_id = str(uuid4()) locale_string = LocaleString(id=patronymic_id, locale=locale, text=content['patronymic']) historical_person.patronymic_id = patronymic_id historical_person.patronymic.set(locale_string) description_id = str(uuid4()) locale_string = LocaleString(id=description_id, locale=locale, text=content['description']) historical_person.description_id = description_id historical_person.description.set(locale_string) if 'audioguide_link' in content: audioguide_link_id = str(uuid4()) locale_link = LocaleLink(id=audioguide_link_id, locale=locale, path=content['audioguide_link']) historical_person.audioguide_link_id = audioguide_link_id historical_person.audioguide_link.set(locale_link) session.add(historical_person) session.commit() session.close() return 'ok'
def post_public_place_by_id(object_id): session = get_session() public_place = session.query(PublicPlace).get(object_id) locale = get_post_locale(session) if public_place is None: session.close() abort(404, "Public place with id = %s not found" % object_id) return content = g.data if session.query(City).get(content['city_id']) is None: session.close() abort(400, "City with id = %s not found" % content['city_id']) return public_place.image_link = content['image_link'] public_place.city_id = content['city_id'] public_place.phone_number = content['phone_number'], public_place.site = content['site'], geolocation = session.query(Geolocation).get(public_place.geolocation_id) geolocation.latitude = content['latitude'] geolocation.longitude = content['longitude'] public_place.name.set( LocaleString(id=public_place.name_id, locale=locale, text=content['name'])) public_place.description.set( LocaleString(id=public_place.description_id, locale=locale, text=content['description'])) public_place.address.set( LocaleString(id=public_place.address_id, locale=locale, text=content['address'])) if 'audioguide_link' in content: if public_place.audioguide_link_id is not None: public_place.audioguide_link.set( LocaleLink(id=public_place.audioguide_link_id, locale=locale, path=content['audioguide_link'])) else: audioguide_link_id = str(uuid4()) locale_link = LocaleLink(id=audioguide_link_id, locale=locale, path=content['audioguide_link']) public_place.audioguide_link_id = audioguide_link_id public_place.audioguide_link.set(locale_link) else: if public_place.audioguide_link_id is not None: locale_link = session.query(LocaleLink).filter( LocaleLink.id == public_place.audioguide_link_id, LocaleLink.locale == locale).first() session.delete(locale_link) if 'avg_bill' in content: if public_place.avg_bill_id is not None: public_place.avg_bill.set( LocaleString(id=public_place.avg_bill_id, locale=locale, text=content['avg_bill'])) else: avg_bill_id = str(uuid4()) locale_string = LocaleString(id=avg_bill_id, locale=locale, text=content['avg_bill']) public_place.avg_bill_id = avg_bill_id public_place.avg_bill.set(locale_string) else: if public_place.avg_bill_id is not None: locale_string = session.query(LocaleString).filter( LocaleString.id == public_place.avg_bill_id, LocaleString.locale == locale).first() session.delete(locale_string) if 'visit_cost' in content: if public_place.visit_cost_id is not None: public_place.visit_cost.set( LocaleString(id=public_place.visit_cost_id, locale=locale, text=content['visit_cost'])) else: visit_cost_id = str(uuid4()) locale_string = LocaleString(id=visit_cost_id, locale=locale, text=content['visit_cost']) public_place.visit_cost_id = visit_cost_id public_place.visit_cost.set(locale_string) else: if public_place.visit_cost_id is not None: locale_string = session.query(LocaleString).filter( LocaleString.id == public_place.visit_cost_id, LocaleString.locale == locale).first() session.delete(locale_string) categories = [] for category_id in content['categories']: category = session.query(Category).get(category_id) if category is None: session.close() abort(400, "Category with id = %s not found" % category_id) return categories.append(category) public_place.categories = categories timetable = [] for timetable_item in content['timetable']: timetable.append( Timetable( week_day=WeekDay(timetable_item['day']), open_time=timetable_item['open_time'], close_time=timetable_item['close_time'], )) public_place.timetable = timetable session.commit() session.close() return 'ok'
def put_new_public_place(): session = get_session() content = g.data locale = get_post_locale(session) if session.query(City).get(content['city_id']) is None: session.close() abort(400, "City with id = %s not found" % content['city_id']) return geolocation = Geolocation(latitude=content['latitude'], longitude=content['longitude']) categories = [] for category_id in content['categories']: category = session.query(Category).get(category_id) if category is None: session.close() abort(400, "Category with id = %s not found" % category_id) return categories.append(category) timetable = [] for timetable_item in content['timetable']: timetable.append( Timetable( week_day=WeekDay(timetable_item['day']), open_time=timetable_item['open_time'], close_time=timetable_item['close_time'], )) public_place = PublicPlace(image_link=content['image_link'], city_id=content['city_id'], geolocation=geolocation, categories=categories, timetable=timetable) if 'phone_number' in content: public_place.phone_number = content['phone_number'] if 'site' in content: public_place.site = content['site'] name_id = str(uuid4()) locale_string = LocaleString(id=name_id, locale=locale, text=content['name']) public_place.name_id = name_id public_place.name.set(locale_string) description_id = str(uuid4()) locale_string = LocaleString(id=description_id, locale=locale, text=content['description']) public_place.description_id = description_id public_place.description.set(locale_string) address_id = str(uuid4()) locale_string = LocaleString(id=address_id, locale=locale, text=content['address']) public_place.address_id = address_id public_place.address.set(locale_string) if 'audioguide_link' in content: audioguide_link_id = str(uuid4()) locale_link = LocaleLink(id=audioguide_link_id, locale=locale, path=content['audioguide_link']) public_place.audioguide_link_id = audioguide_link_id public_place.audioguide_link.set(locale_link) if 'avg_bill' in content: avg_bill_id = str(uuid4()) locale_string = LocaleString(id=avg_bill_id, locale=locale, text=content['avg_bill']) public_place.avg_bill_id = avg_bill_id public_place.avg_bill.set(locale_string) if 'visit_cost' in content: visit_cost_id = str(uuid4()) locale_string = LocaleString(id=visit_cost_id, locale=locale, text=content['visit_cost']) public_place.visit_cost_id = visit_cost_id public_place.visit_cost.set(locale_string) session.add(public_place) session.commit() session.close() return 'ok'