Esempio n. 1
0
def update_goal():
	"""Will register a subgoal  or goal as complete."""
	user = model.get_user_by_email(flask_session["email"])
	goal_id = request.args.get("goal_id")
	current_goal = model.get_goal_by_id(goal_id)
	# list of all subgoals associated with the goal we are viewing. 
	possible_subgoals = model.get_subgoals_by_goal_id(goal_id)

	# creating a list of subgoals to mark as completed.
	subgoal_to_commit = []

	for subgoal in possible_subgoals:
		subgoal_id = request.args.get(subgoal.description)
		# If the box is checked, it will register the subgoal as complete. 
		if subgoal_id != None:
			subgoal_obj = model.get_subgoal_by_id(int(subgoal_id))
			subgoal_obj.date_completed = datetime.now()
			model.sqla_session.commit()

	# Determines if the goal was marked as complete. If it was, it updates the database.

	goal_complete = request.args.get("final_goal")
	
	if goal_complete != None:
		current_goal.date_completed = datetime.now()
		model.sqla_session.commit()


	#TODO: redirect back to the goal that was being viewed, not to the goal list. 

	return redirect("/goals")
Esempio n. 2
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)