当前位置: 首页>>代码示例>>Python>>正文


Python Exercise.get_by_name方法代码示例

本文整理汇总了Python中models.Exercise.get_by_name方法的典型用法代码示例。如果您正苦于以下问题:Python Exercise.get_by_name方法的具体用法?Python Exercise.get_by_name怎么用?Python Exercise.get_by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Exercise的用法示例。


在下文中一共展示了Exercise.get_by_name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: exercise_message

# 需要导入模块: from models import Exercise [as 别名]
# 或者: from models.Exercise import get_by_name [as 别名]
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:
                    prereq_ex = Exercise.get_by_name(prereq)
                    suggested_prereqs.append({
                          'ka_url': prereq_ex.relative_url,
                          'display_name': prereq_ex.display_name,
                          })
        exercise_states['suggested_prereqs'] = apijsonify.jsonify(
                suggested_prereqs)

    else:
        return None

    return shared_jinja.get().render_template(filename, **exercise_states)
开发者ID:di445,项目名称:server,代码行数:48,代码来源:templatetags.py

示例2: url

# 需要导入模块: from models import Exercise [as 别名]
# 或者: from models.Exercise import get_by_name [as 别名]
 def url(self):
     exercise = Exercise.get_by_name(self.exercise_name)
     return exercise.relative_url
开发者ID:johnfelipe,项目名称:server,代码行数:5,代码来源:models.py


注:本文中的models.Exercise.get_by_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。