def locations_edit(): location = location_repository.select(request.form['location_id']) countries = country_repository.select_all() return render_template("locations/edit.html", location=location, countries=countries, title="Edit/Delete location")
def update_class(id): instructor = instructor_repository.select(request.form['instructor']) location = location_repository.select(request.form["location"]) updated_class = GymClass(request.form['class_type'], instructor, request.form['date'], request.form['time'], request.form['duration'], location, id) gym_class_repository.update(updated_class) return redirect(f'/classes/{id}')
def locations_view_single(id): pass location = location_repository.select(id) photos = photo_repository.select_all_for_location(id) return render_template("locations/view_single.html", location=location, photos=photos, title=location.name)
def create_class(): instructor = instructor_repository.select(request.form['instructor']) location = location_repository.select(request.form["location"]) new_gym_class = GymClass(request.form['class_type'], instructor, request.form['date'], request.form['time'], request.form['duration'], location) gym_class_repository.save(new_gym_class) return redirect('/classes')
def create_task(): user_id = request.form['user_id'] location_id = request.form['location_id'] review = request.form['review'] user = user_repository.select(user_id) location = location_repository.select(location_id) visit = Visit(user, location, review) visit_repository.save(visit) return redirect('/visits')
def select(id): # create sql query without values sql = "SELECT * FROM photos WHERE id = %s" # create list with values required by sql query values = [id] # execute sql query result = run_sql(sql, values)[0] # convert return which is a single element list of dictionaries into a continent object photo = Photo(result["filename"], result["mine"], location_repository.select(result['location_id']),result["id"]) # return the result return photo
def select(id): # working vu_point = None sql = "SELECT * FROM vu_points WHERE id = (%s)" values = [id] result = run_sql(sql, values)[0] if result is not None: country = country_repository.select(result['country_id']) location = location_repository.select(result['location_id']) vu_point = Vu_point(result['name'], location, country, result['rating'], result['description'], result['visited'], result['id']) return vu_point
def select_all(): # working vu_points = [] sql = "SELECT * FROM vu_points" results = run_sql(sql) for row in results: country = country_repository.select(row['country_id']) location = location_repository.select(row['location_id']) vu_point = Vu_point(row['name'], location, country, row['rating'], row['description'], row['visited'], row['id']) vu_points.append(vu_point) return vu_points
def select_all(): visits = [] sql = "SELECT * FROM visits" results = run_sql(sql) for row in results: user = user_repository.select(row['user_id']) location = location_repository.select(row['location_id']) visit = Visit(user, location, row['review'], row['id']) visits.append(visit) return visits
def select(id): cast = None sql = "SELECT * FROM casts WHERE id = %s" values = [id] result = run_sql(sql, values)[0] if result is not None: wizard = wizard_repository.select(result['wizard_id']) spell = spell_repository.select(result['spell_id']) location = location_repository.select(result['location_id']) cast = Cast(result['deaths'], result['details'], wizard, spell, location, result['id']) return cast
def select_all(): # set return variable as empty list photos = [] # create sql query without values sql = "SELECT * FROM photos" # execute sql query results = run_sql(sql) # convert return which is a single element list of dictionaries into list of countries objects for result in results: photo = Photo(result["filename"], result["mine"], location_repository.select(result['location_id']),result["id"]) photos.append(photo) # return the result return photos
def vu_points(country): # working but need to pass a country object in as an argument vu_points = [] sql = "SELECT * FROM vu_points WHERE country_id = %s" values = [country.id] results = run_sql(sql, values) for row in results: # was passing row['location_id'] into the vu_point instance below but this meant when using this function, the location was an id rather than an object. By selecting the object using the location id like this, I could then pass in the variable 'location' to the object location = location_repository.select(row['location_id']) vu_point = Vu_point(row['name'], location, country, row['rating'], row['description'], row['visited'], row['id']) vu_points.append(vu_point) return vu_points
def select_all(): casts = [] sql = "SELECT * FROM casts" results = run_sql(sql) for row in results: wizard = wizard_repository.select(row['wizard_id']) spell = spell_repository.select(row['spell_id']) location = location_repository.select(row['location_id']) cast = Cast(row['deaths'], row['details'], wizard, spell, location, row['id']) casts.append(cast) return casts
def select(id): sql = "SELECT * FROM gym_classes WHERE id = %s" values = [id] result = run_sql(sql, values)[0] if result is not None: instructor = instructor_repository.select(result["instructor_id"]) location = location_repository.select(result["location_id"]) class_found = GymClass(result["class_type"], instructor, result["class_date"], result["class_time"], result["duration"], location, result["id"] ) return class_found
def edit_vu_submit(id, id2): country = country_repository.select(id) update_vu_point = vu_point_repository.select(id2) location = location_repository.select(update_vu_point.location.id) name = request.form['vu_name'] rating = request.form['rating'] description = request.form['description'] visited = request.form['visited'] location_name = request.form['location_name'] if location.name != location_name: # if the location name is not equal to the location already attached, udpate it with the new location from the form location.name = location_name location_repository.update(location) update_vu_point = Vu_point(name, location, country, rating, description, visited, id2) vu_point_repository.update(update_vu_point) return redirect("/countries-" + id)
def select_all(): all_classes = [] sql = "SELECT * FROM gym_classes ORDER BY class_date, class_time" results = run_sql(sql) for row in results: instructor = instructor_repository.select(row["instructor_id"]) location = location_repository.select(row["location_id"]) gym_class = GymClass(row["class_type"], instructor, row["class_date"], row["class_time"], row["duration"], location, row["id"] ) all_classes.append(gym_class) return all_classes
def classes(instructor): classes_found = [] sql = "SELECT * FROM gym_classes WHERE instructor_id = %s" values = [instructor.id] results = run_sql(sql, values) for row in results: location = location_repository.select(row["location_id"]) class_found = GymClass(row["class_type"], instructor, row["class_date"], row["class_time"], row["duration"], location, row["id"] ) classes_found.append(class_found) return classes_found
def classes(member): gym_classes = [] sql = """ SELECT gym_classes.* FROM gym_classes INNER JOIN attendees ON attendees.class_id = gym_classes.id WHERE member_id = %s """ values = [member.id] results = run_sql(sql, values) for row in results: instructor = instructor_repository.select(row["instructor_id"]) location = location_repository.select(row["location_id"]) gym_class = GymClass(row["class_type"], instructor, row["class_date"], row["class_time"], row["duration"], location, row["id"]) gym_classes.append(gym_class) return gym_classes
def show(id): location = location_repository.select(id) users = location_repository.users(location) return render_template("locations/show.html", location=location, users=users)
def location(id): location = location_repository.select(id) classes_sorted = sorted(location_repository.classes(location), key = lambda location: (location.date, location.time)) return render_template('/locations/show.html', location=location, classes=classes_sorted)
def edit_location(id): location_found = location_repository.select(id) return render_template('/locations/edit.html', location=location_found)
def show(id): location = location_repository.select(id) return render_template("locations/show.html", location=location)