Exemple #1
0
def exercise_handler(request, exercise):
    """
    Display an exercise
    """
    # Copy related videos (should be small), as we're going to tweak them
    related_videos = [copy.copy(topicdata.NODE_CACHE["Video"].get(key, None)) for key in exercise["related_video_readable_ids"]]

    videos_to_delete = []
    for idx, video in enumerate(related_videos):
        # Remove all videos that were not recognized or
        #   simply aren't on disk.
        #   Check on disk is relatively cheap, also executed infrequently
        if not video or not topic_tools.is_video_on_disk(video["youtube_id"]):
            videos_to_delete.append(idx)
            continue

        # Resolve the most related path
        video["path"] = video["paths"][0]  # default value
        for path in video["paths"]:
            if topic_tools.is_sibling({"path": path, "kind": "Video"}, exercise):
                video["path"] = path
                break
        del video["paths"]
    for idx in reversed(videos_to_delete):
        del related_videos[idx]

    context = {
        "exercise": exercise,
        "title": exercise["title"],
        "exercise_template": "exercises/" + exercise["slug"] + ".html",
        "related_videos": related_videos,
    }
    return context
Exemple #2
0
def video_handler(request, video, prev=None, next=None):
    video_exists = VideoFile.objects.filter(pk=video['youtube_id']).exists()

    # If we detect that a video exists, but it's not on disk, then
    #   force the database to update.  No race condition here for saving
    #   progress in a VideoLog: it is not dependent on VideoFile.
    if not video_exists and topic_tools.is_video_on_disk(video['youtube_id']):
        force_job("videoscan")
        video_exists = True

    if not video_exists:
        if request.is_admin:
            # TODO(bcipolli): add a link, with querystring args that auto-checks this video in the topic tree
            messages.warning(
                request,
                _("This video was not found! You can download it by going to the Update page."
                  ))
        elif request.is_logged_in:
            messages.warning(
                request,
                _("This video was not found! Please contact your teacher or an admin to have it downloaded."
                  ))
        elif not request.is_logged_in:
            messages.warning(
                request,
                _("This video was not found! You must login as an admin/teacher to download the video."
                  ))
    context = {
        "video": video,
        "title": video["title"],
        "video_exists": video_exists,
        "prev": prev,
        "next": next,
    }
    return context
Exemple #3
0
def video_handler(request, video, prev=None, next=None):
    video_exists = VideoFile.objects.filter(pk=video['youtube_id']).exists()

    # If we detect that a video exists, but it's not on disk, then
    #   force the database to update.  No race condition here for saving
    #   progress in a VideoLog: it is not dependent on VideoFile.
    if not video_exists and topic_tools.is_video_on_disk(video['youtube_id']):
        force_job("videoscan")
        video_exists = True

    if not video_exists:
        if request.is_admin:
            # TODO(bcipolli): add a link, with querystring args that auto-checks this video in the topic tree
            messages.warning(request, _("This video was not found! You can download it by going to the Update page."))
        elif request.is_logged_in:
            messages.warning(request, _("This video was not found! Please contact your teacher or an admin to have it downloaded."))
        elif not request.is_logged_in:
            messages.warning(request, _("This video was not found! You must login as an admin/teacher to download the video."))
    context = {
        "video": video,
        "title": video["title"],
        "video_exists": video_exists,
        "prev": prev,
        "next": next,
    }
    return context
Exemple #4
0
def exercise_handler(request, exercise):
    """
    Display an exercise
    """
    # Copy related videos (should be small), as we're going to tweak them
    related_videos = [
        copy.copy(topicdata.NODE_CACHE["Video"].get(key, None))
        for key in exercise["related_video_readable_ids"]
    ]

    videos_to_delete = []
    for idx, video in enumerate(related_videos):
        # Remove all videos that were not recognized or
        #   simply aren't on disk.
        #   Check on disk is relatively cheap, also executed infrequently
        if not video or not topic_tools.is_video_on_disk(video["youtube_id"]):
            videos_to_delete.append(idx)
            continue

        # Resolve the most related path
        video["path"] = video["paths"][0]  # default value
        for path in video["paths"]:
            if topic_tools.is_sibling({
                    "path": path,
                    "kind": "Video"
            }, exercise):
                video["path"] = path
                break
        del video["paths"]
    for idx in reversed(videos_to_delete):
        del related_videos[idx]

    context = {
        "exercise": exercise,
        "title": exercise["title"],
        "exercise_template": "exercises/" + exercise["slug"] + ".html",
        "related_videos": related_videos,
    }
    return context