當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。