Exemple #1
0
def view_goal():
	"""Views a goal that the user previously set."""

	# TODO goals should be able to be shown as complete, just like subgoals do at the moment.

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

	user = model.get_user_by_email(flask_session["email"])
	current_goal_id = request.args.get("goal_id")
	current_goal = model.get_goal_by_id(current_goal_id)
	subgoals = model.get_subgoals_by_goal_id(current_goal_id)
	outstanding_subgoals = model.get_outstanding_subgoal_by_goal_id(current_goal_id)
	runs_after_date = model.get_runs_after_date(user, current_goal.set_date)

	possible_matches = []

	for subgoal in outstanding_subgoals:
		for run in runs_after_date:
			if run.approx_dist >= model.distance_int_dictionary[subgoal.description]:
				possible_matches.append((subgoal, run))



	update_button = False

	if not current_goal.date_completed:
			update_button = True
			days_left = (current_goal.event_date - datetime.now()).days
	else:
		days_left = "Goal Complete!"

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

	return render_template("view_goal.html", goal=current_goal, goal_dictionary = model.goal_dictionary, subgoals = subgoals, update_button = update_button, days_left = days_left, possible_matches = possible_matches, page = page)
Exemple #2
0
def dashboard():
	"""Displays relevant info for the user, that he or she will
	see upon logging in."""

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

	user = model.get_user_by_email(flask_session["email"])
	

	runs = model.get_collection_of_runs(user.id, runs_to_get = 4)
	instagrams = []
	for run in runs:
		instagram = model.get_instagram(run[3])
		if len(instagram[0].text_ans) > 20:
			instagrams.append(instagram[0].text_ans)

	#looks for more instagrams if the first search didn't return very many
	if len(instagrams) < 4:
		instagrams = []
		runs = model.get_collection_of_runs(user.id, runs_to_get = 8)
		for run in runs:
			instagram = model.get_instagram(run[3])
			if len(instagram[0].text_ans) > 20:
				instagrams.append(instagram[0].text_ans)

	if len(instagrams) > 4:
		instagrams = instagrams[:4]


	#gets outstanding subgoals 

	outstanding_subgoals = model.get_outstanding_subgoals(user)

	possible_matches = []

	for subgoal in outstanding_subgoals:
		runs_after_date = model.get_runs_after_date(user, subgoal.goal.set_date)
		for run in runs_after_date:
			if run.approx_dist >= model.distance_int_dictionary[subgoal.description]:
				possible_matches.append((subgoal, run))

	# gets outstanding goals

	outstanding_goals = model.get_outstanding_goals(user)

	possible_goal_matches = []

	for goal in outstanding_goals:
		for run in runs_after_date:
			if run.approx_dist >= model.distance_int_dictionary[goal.description]:
				possible_goal_matches.append((goal, run))




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

	return render_template("user_landing.html", instagrams=instagrams, possible_matches = possible_matches, possible_goal_matches = possible_goal_matches, goal_dictionary = model.goal_dictionary, page = page)