def exercise_message(exercise, user_exercise_graph, sees_graph=False, review_mode=False): """Render UserExercise html for APIActionResults["exercise_message_html"] listener in khan-exercise.js. This is called **each time** a problem is either attempted or a hint is called (via /api/v1.py) returns nothing unless a user is struggling, proficient, etc. then it returns the appropriat template See Also: APIActionResults sees_graph is part of an ab_test to see if a small graph will help """ # TODO(david): Should we show a message if the user gets a problem wrong # after proficiency, to explain that this exercise needs to be reviewed? exercise_states = user_exercise_graph.states(exercise.name) if review_mode and user_exercise_graph.has_completed_review(): filename = 'exercise_message_review_finished.html' elif (exercise_states['proficient'] and not exercise_states['reviewing'] and not review_mode): if sees_graph: filename = 'exercise_message_proficient_withgraph.html' else: filename = 'exercise_message_proficient.html' elif exercise_states['struggling']: filename = 'exercise_message_struggling.html' suggested_prereqs = [] if exercise.prerequisites: proficient_exercises = user_exercise_graph.proficient_exercise_names() for prereq in exercise.prerequisites: if prereq not in proficient_exercises: suggested_prereqs.append({ 'ka_url': Exercise.get_relative_url(prereq), 'display_name': Exercise.to_display_name(prereq), }) exercise_states['suggested_prereqs'] = apijsonify.jsonify( suggested_prereqs) else: return None return shared_jinja.get().render_template(filename, **exercise_states)
def url(self): if self.exercise_name: return Exercise.get_relative_url(self.exercise_name) else: return "/exercisedashboard"
def url(self): if self.exercise_name: return Exercise.get_relative_url(self.exercise_name) else: return "/#browse"