Example #1
0
def review_run():
	"""Allows the user to view a previous run."""
	
	if flask_session.get("email") == None:
		flash("You must sign in to view that page.")
		return redirect("/")

	current_run_id = request.args.get("run_id")
	current_run = model.get_run_by_id(current_run_id)
	current_ratings = model.get_ratings_for_run(current_run_id)
	
	html_parse = HTMLParser.HTMLParser()
	instagram_html = current_ratings[9]
	
	instagram_html = instagram_html.text_ans
	
	instagram_html = html_parse.unescape(instagram_html)
	
	colors = {}
	for i in range(4):
		if current_ratings[i].numeric_ans < 2:
			colors[i] = "#E03A29"
		elif current_ratings[i].numeric_ans < 4:
			colors[i] = "#E4EB11"
		else:
			colors[i] = "#21BF23"

	color_zero = colors[0]
	color_one = colors[1]
	color_two = colors[2]
	color_three = colors[3]

	score = model.get_run_score(current_run_id)

	if current_run.route == 0 or current_run.route == None:
		current_route = None
	else:
		current_route = model.get_route_by_id(current_run.route)


	#creates an edit url. 

	url = "/edit_run.html?run_id=" + str(current_run_id)


	# The page variable determines which tabs are active.
	page = "run"

	location_image = model.location_badges_dictionary[current_ratings[5].select_ans]
	terrain_image = model.terrain_badges_dictionary[current_ratings[6].select_ans]
	route_image = model.route_badges_dictionary[current_ratings[7].select_ans]

	return render_template("view_run.html", run=current_run, ratings = current_ratings, terrain_dictionary = model.terrain_dictionary, route_dictionary = model.route_dictionary, score = score, color_zero = color_zero, color_one = color_one, color_two = color_two, color_three = color_three, instagram_html = instagram_html, edit_url=url, page = page, current_route = current_route, location_image = location_image, route_image = route_image, terrain_image = terrain_image)
Example #2
0
def edit_run():
	"""Allows user to edit a run."""

	if flask_session.get("email") == None:
		flash("You must sign in to view that page.")
		return redirect("/")

	run_id = request.args.get("run_id")
	run = model.get_run_by_id(run_id)

	ratings = model.get_ratings_for_run(run.id) 
	
	html_parse = HTMLParser.HTMLParser()
	instagram_html = ratings[9]
	
	instagram_html = instagram_html.text_ans
	
	instagram_html = html_parse.unescape(instagram_html)

	page = "run"

	return render_template("edit_run.html", run = run, ratings = ratings, instagram_html = instagram_html, page = page)
Example #3
0
def update_run_on_database():
	"""Updates the editied run on the database."""

	if flask_session.get("email") == None:
		flash("You must sign in to view that page.")
		return redirect("/")

	# Getting all the relevant info.
	user = model.get_user_by_email(flask_session["email"]) 
	run_id = request.form.get("run_id")
	run_object = model.get_run_by_id(run_id)
	date_run = request.form.get("new_run_date_and_time")

	if date_run == "":
		date_run = run_object.date_run
	else:
		date_run = datetime.strptime(date_run, "%Y-%m-%dT%H:%M")
	zipcode = request.form.get("zipcode")
	distance = float(request.form.get("distance"))
	duration = int(request.form.get("duration"))
	pre_run = int(request.form.get("pre_run"))
	during_run = int(request.form.get("during_run"))
	post_run = int(request.form.get("post_run"))
	energy = int(request.form.get("energy"))
	feeling = request.form.get("feeling")
	location = request.form.get("location")
	terrain = request.form.get("terrain")
	route = request.form.get("route")
	thoughts = request.form.get("thoughts")
	instagram_html = request.form.get("instagram_embed")

	# modifying run
	run_object.zipcode = zipcode
	run_object.approx_dist = distance
	run_object.approx_time = duration
	if date_run != " ":
		run_object.date_run = date_run
	model.sqla_session.commit()

	# Modifying ratings. 

	ratings = model.get_ratings_for_run(run_id)

	ratings[0].numeric_ans = pre_run
	ratings[1].numeric_ans = during_run
	ratings[2].numeric_ans = post_run
	ratings[3].numeric_ans = energy
	ratings[4].select_ans = feeling
	ratings[5].select_ans = location
	ratings[6].select_ans = terrain
	ratings[7].select_ans = route

	model.sqla_session.commit() 

	
	#checking to see if there are new text entries and commiting them 
	# if they have been updated. 

	instagram_html = request.form.get("instagram_embed")

	if len(instagram_html)< 20:
		pass
	else:
		ratings[9].text_ans = instagram_html

	if len(thoughts) < 2 or thoughts == None:
		pass
	else:
		ratings[8].text_ans = thoughts
	model.sqla_session.commit()
	
	redirect_url = "/view_run.html?run_id=" + str(run_id)
	flash("Run Successfully Updated!")
	return redirect(redirect_url)