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


Python Video.get_all方法代码示例

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


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

示例1: get_content_data

# 需要导入模块: from models import Video [as 别名]
# 或者: from models.Video import get_all [as 别名]
def get_content_data():
    topics = {str(t.key()):(idx, t) for idx, t in enumerate(Topic.get_visible_topics())}
    topic_names = {}
    def get_topics_of(item):
        def g():
            if not item.topic_string_keys:
                return
            seen = set()
            for tk in item.topic_string_keys:
                try:
                    idx, topic = topics[tk]
                except KeyError:
                    continue
                for depth, tk2 in enumerate(topic.ancestor_keys[:-1][::-1]):
                    try:
                        idx2, topic2 = topics[str(tk2)]
                    except KeyError:
                        continue
                    if idx2 in seen:
                        continue
                    seen.add(idx2)
                    topic_names[idx2] = topic2.title
                    # use depth for sorting by topic level
                    yield depth, idx2
        return [idx for _, idx in sorted(g())]

    videos = {video.key().id():
        dict(
            key_id=video.key().id(),
            name=video.readable_id,
            display_name=video.title,
            topics=get_topics_of(video)
        ) for video in Video.get_all()}

    exercises = {exercise.name:
        dict(
            name=exercise.name,
            display_name=exercise.display_name,
            topics=get_topics_of(exercise),
        ) for exercise in Exercise.get_all_use_cache()}

    return topic_names, videos, exercises
开发者ID:di445,项目名称:server,代码行数:44,代码来源:class_progress_report_graph.py

示例2: class_progress_report_graph_context

# 需要导入模块: from models import Video [as 别名]
# 或者: from models.Video import get_all [as 别名]
def class_progress_report_graph_context(user_data, list_students):
    if not user_data:
        return {}

    list_students = sorted(list_students, key=lambda student: student.nickname)

    student_email_pairs = [(escape(s.email), (s.nickname[:14] + '...') if len(s.nickname) > 17 else s.nickname) for s in list_students]
    emails_escapejsed = [escapejs(s.email) for s in list_students]

    exercises_all = Exercise.get_all_use_cache()
    user_exercise_graphs = UserExerciseGraph.get(list_students)

    exercises_found = []

    for exercise in exercises_all:
        for user_exercise_graph in user_exercise_graphs:
            graph_dict = user_exercise_graph.graph_dict(exercise.name)
            if graph_dict and graph_dict["total_done"]:
                exercises_found.append(exercise)
                break

    exercise_names = [(e.name, e.display_name, escapejs(e.name)) for e in exercises_found]
    exercise_list = [{'name': e.name, 'display_name': e.display_name} for e in exercises_found]

    videos_all = Video.get_all()
    all_video_progress = dict(zip(list_students, get_video_progress_for_students(list_students)))
    videos_found = reduce(set.union, all_video_progress.itervalues(), set())

    videos_found = [video for video in videos_all if video.key().id() in videos_found]
    video_list = [{'name': v.readable_id, 'display_name': v.title} for v in videos_found]

    progress_data = {}

    for (student, student_email_pair, escapejsed_student_email, user_exercise_graph) in izip(list_students, student_email_pairs, emails_escapejsed, user_exercise_graphs):

        student_email = student.email

        student_review_exercise_names = user_exercise_graph.review_exercise_names()

        progress_data[student_email] = student_data = {
            'email': student.email,
            'nickname': student.nickname,
            'profile_root': student.profile_root,
            'exercises': [],
            'videos': [],
        }

        for (exercise, (_, exercise_display, exercise_name_js)) in izip(exercises_found, exercise_names):

            exercise_name = exercise.name
            graph_dict = user_exercise_graph.graph_dict(exercise_name)

            status = ""
            status_name = ""

            if graph_dict["proficient"]:
                if exercise_name in student_review_exercise_names:
                    status_name = "review"
                else:
                    if not graph_dict["explicitly_proficient"]:
                        status_name = "proficient_implicit"
                    else:
                        status_name = "proficient"
            elif graph_dict["struggling"]:
                status_name = "struggling"
            elif graph_dict["total_done"] > 0:
                status_name = "started"

            status = STATUSES[status_name]
            if status:
                student_data['exercises'].append({
                    "status": status,
                    "status_name": status_name,
                    "progress": graph_dict["progress"],
                    "total_done": graph_dict["total_done"],
                    "last_done": graph_dict["last_done"] if graph_dict["last_done"] and graph_dict["last_done"].year > 1 else '',
                    "last_done_ago": timesince_ago(graph_dict["last_done"]) if graph_dict["last_done"] and graph_dict["last_done"].year > 1 else ''
                })
            else:
                student_data['exercises'].append({
                    "name": exercise_name,
                    "status": status,
                })

        video_progress = all_video_progress[student]
        for video in videos_found:
            status_name = video_progress.get(video.key().id(), "")
            status = STATUSES[status_name]
            student_data['videos'].append({
                    "name": video.title,
                    "status": status,
                    "status_name": status_name,
                })


    student_row_data = [data for key, data in progress_data.iteritems()]

    return {
        'exercise_names': exercise_list,
        'video_names': video_list,
#.........这里部分代码省略.........
开发者ID:johnfelipe,项目名称:server,代码行数:103,代码来源:class_progress_report_graph.py


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