def select(id): place = None sql = "SELECT * FROM places where id = %s" values = [id] result = run_sql(sql,values)[0] if result is not None: country = country_repository.select(result['country_id']) place_type = place_type_repository.select(result['place_type_id']) place=Place(result['place_name'],result['description'],place_type,country,result['visited'],result['rating'], result['id']) return place
def select_all(): places = [] sql = "SELECT places.* FROM places inner join countries on places.country_id = countries.id order by countries.name, places.place_name" results = run_sql(sql) for row in results: country = country_repository.select(row["country_id"]) place_type = place_type_repository.select(row["place_type_id"]) place=Place(row['place_name'],row['description'],place_type,country,row['visited'],row['rating'], row['id']) places.append(place) return places
def select_filtered(visited): places = [] sql = "SELECT * FROM places where visited = %s" values = [visited] results = run_sql(sql,values) for row in results: country = country_repository.select(row['country_id']) place_type = place_type_repository.select(row['place_type_id']) place=Place(row['place_name'],row['description'],place_type ,country, row['visited'],row['rating'], row['id']) places.append(place) return places
def select_search(continent): places = [] sql = "SELECT places.* FROM places INNER JOIN countries ON places.country_id = countries.id WHERE countries.continent = %s" values = [continent] results = run_sql(sql,values) for row in results: country = country_repository.select(row['country_id']) place_type = place_type_repository.select(row['place_type_id']) place=Place(row['place_name'],row['description'],place_type ,country, row['visited'],row['rating'], row['id']) places.append(place) return places
def update_place(id): place_name = request.form["place_name"] description=request.form['description'] place_type_id = request.form["place_type_id"] place_type = place_type_repository.select(place_type_id) country_id = request.form["country_id"] country = country_repository.select(country_id) visited = request.form["visited"] rating = request.form["rating"] new_place = Place(place_name,description, place_type, country, visited,rating,id) place_repository.update(new_place) return redirect("/places")
def create_place(): place_name = request.form['place_name'] description=request.form['description'] place_type_id = request.form['place_type_id'] place_type = place_type_repository.select(place_type_id) country_id = request.form['country_id'] country = country_repository.select(country_id) visited = request.form['visited'] rating=request.form['rating'] new_place = Place(place_name,description, place_type, country, visited,rating) place_repository.save(new_place) return redirect("/places")
print(country_3.name) country_5 = Country("Madagascar", country_3.continent, country_3.visited, country_3.id) country_repository.update(country_5) test_country_4 = country_repository.select(country_3.id) print(test_country_4.name) # and turning it back print(country_3.name) country_5 = Country("Ethiopia", country_3.continent, country_3.visited, country_3.id) country_repository.update(country_5) test_country_4 = country_repository.select(country_3.id) print(test_country_4.name) #test updating place print(place_2.visited) place_5 = Place(place_2.place_name, place_2.description, place_2.place_type, place_2.country, False, place_2.rating, place_2.id) place_repository.update(place_5) test_place_5 = place_repository.select(place_2.id) print(test_place_5.visited) #test updating place_type print(place_type_3.type_name) place_type_4 = PlaceType("Marine Reserve", place_type_3.id) place_type_repository.update(place_type_4) test_place_type_5 = place_type_repository.select(place_type_3.id) print(test_place_type_5.type_name) pdb.set_trace()
def edit_place_type(id): place_type = place_type_repository.select(id) return render_template('place_types/edit.html', place_type=place_type)