def select(id): sight = None sql = "SELECT * FROM sights WHERE id = %s" values = [id] result = run_sql(sql, values)[0] if result is not None: sight = Sight(result['name'], result['id']) return sight
def create_sight(): name = request.form['name'] city_id = request.form['city_id'] city = city_repository.select(city_id) visited = False comment = request.form['comment'] new_sight = Sight(name, city, visited, comment) sight_repository.save(new_sight) return redirect(f"/cities/{city_id}")
def select_all(): sights = [] sql = "SELECT * FROM sights" results = run_sql(sql) for row in results: sight = Sight(row['name'], row['id']) sights.append(sight) return sights
def comment(id): sight = sight_repository.select(id) sight_id = sight.id name = sight.name city = sight.city visited = sight.visited comment = request.form['comment'] commented_sight = Sight(name, city, visited, comment, id) sight_repository.update(commented_sight) return redirect(f"/sights/{sight_id}")
def update_sight(id): name = request.form['name'] sight = sight_repository.select(id) sight_id = sight.id city_id = sight.city.id city = city_repository.select(city_id) visited = sight.visited comment = sight.comment updated_sight = Sight(name, city, visited, comment, id) sight_repository.update(updated_sight) return redirect(f"/sights/{sight_id}")
def select(id): sight = None sql = "SELECT * FROM sights WHERE id = %s" values = [id] result = run_sql(sql, values)[0] if result is not None: city = city_repository.select(result['city_id']) sight = Sight(result['name'], city, result['visited'], result['comment'], result['id']) return sight
def create_trip(): city_id = request.form["city_id"] country_id = request.form["country_id"] sight_id = request.form["sight_id"] to_visit = request.form["to_visit"] new_city = City("name", city_id) new_country = Country("country", country_id) new_sight = Sight("sight", sight_id) trip = Visit(new_city, new_country, new_sight, to_visit) visit_repository.save(trip) return redirect("/trips")
def select_all(): sights = [] sql = "SELECT * FROM sights" results = run_sql(sql) for row in results: city = city_repository.select(row['city_id']) sight = Sight(row['name'], city, row['visited'], row['comment'], row['id']) sights.append(sight) return sights
def sights(id): sights = [] sql = "SELECT * FROM sights WHERE city_id = %s ORDER by name ASC" values = [id] results = run_sql(sql, values) for row in results: city = city_repository.select(row['city_id']) sight = Sight(row['name'], city, row['visited'], row['comment'], row['id']) sights.append(sight) return sights
def visit(id): sight = sight_repository.select(id) sight_id = sight.id name = sight.name city = sight.city comment = sight.comment visited = True visit_sight = Sight(name, city, visited, comment, id) sight_repository.update(visit_sight) visit_sight.city.visited = True city_repository.update(visit_sight.city) visit_sight.city.country.visited = True country_repository.update(visit_sight.city.country) return redirect(f"/sights/{sight_id}")
def sights(country): results = [] sql = """SELECT sights.* FROM sights INNER JOIN visits ON sights.id = visits.sight_id INNER JOIN countries ON countries.id = visits.country_id WHERE countries.id = %s""" values = [country.id] sql_results = run_sql(sql, values) for row in sql_results: sight = Sight(row['name'], row['id']) results.append(sight) return results
from models.city import City from models.country import Country from models.visit import Visit from models.sight import Sight import repositories.sight_repository as sight_repository import repositories.city_repository as city_repository import repositories.country_repository as country_repository import repositories.visit_repository as visit_repository sight_repository.delete_all() city_repository.delete_all() country_repository.delete_all() visit_repository.delete_all() sight_1 = Sight("Beach") sight_repository.save(sight_1) sight_2 = Sight("Cathedral") sight_repository.save(sight_2) sight_3 = Sight("Art Gallery") sight_repository.save(sight_3) city_1 = Sight("Havana") city_repository.save(city_1) city_2 = City("Barcelona") city_repository.save(city_2) city_3 = City("Florence")
def create_sights(): sight = request.form["sight"] new_sight = Sight(sight) sight_repository.save(new_sight) return redirect("/sights")