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


Python VideoToExercise.save方法代码示例

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


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

示例1: add_exercise

# 需要导入模块: from c2g.models import VideoToExercise [as 别名]
# 或者: from c2g.models.VideoToExercise import save [as 别名]
def add_exercise(request):
    #    try:
    #        common_page_data = get_common_page_data(request, course_prefix, course_suffix)
    #    except:
    #        raise Http404

    # don't catch video DoesNotExist here because we want some tangible error to happen if
    # the video id changes in form submission, like emailing us
    video = Video.objects.get(id=request.POST["video_id"])

    video_time = request.POST["videotime"]

    file_content = request.FILES["exercise"]
    file_name = file_content.name

    exercise = Exercise()
    exercise.handle = request.POST["course_prefix"] + "--" + request.POST["course_suffix"]
    exercise.fileName = file_name
    exercise.file.save(file_name, file_content)
    exercise.save()

    videoToEx = VideoToExercise(video=video, exercise=exercise, is_deleted=False, video_time=video_time)
    videoToEx.save()
    return HttpResponseRedirect(
        reverse(
            "courses.videos.views.manage_exercises",
            args=(request.POST["course_prefix"], request.POST["course_suffix"], video.slug),
        )
    )
开发者ID:pageman,项目名称:class2go,代码行数:31,代码来源:views.py

示例2: add_existing_exercises

# 需要导入模块: from c2g.models import VideoToExercise [as 别名]
# 或者: from c2g.models.VideoToExercise import save [as 别名]
def add_existing_exercises(request):

    # don't catch video DoesNotExist here because we want some tangible error action to happen if
    # the video id changes in form submission, like mailing us
    video = Video.objects.get(id=request.POST["video_id"])

    exercise_ids = request.POST.getlist("exercise")
    exercises = Exercise.objects.filter(id__in=exercise_ids)
    for exercise in exercises:
        # if this exercise has been deleted previously then just un-delete it
        videoToExs = VideoToExercise.objects.filter(
            video=video, exercise_id=exercise.id, mode="draft", is_deleted=1
        ).order_by("-id")
        if videoToExs.exists():
            videoToEx = videoToExs[0]
            videoToEx.is_deleted = 0
            videoToEx.video_time = 0
            videoToEx.save()
        # else create a new one
        else:
            videoToEx = VideoToExercise(video=video, exercise=exercise, is_deleted=0, video_time=0, mode="draft")
            videoToEx.save()

    return HttpResponseRedirect(
        reverse(
            "courses.videos.views.manage_exercises",
            args=(request.POST["course_prefix"], request.POST["course_suffix"], video.slug),
        )
    )
开发者ID:jeffreybreen,项目名称:class2go,代码行数:31,代码来源:views.py

示例3: add_existing_exercises

# 需要导入模块: from c2g.models import VideoToExercise [as 别名]
# 或者: from c2g.models.VideoToExercise import save [as 别名]
def add_existing_exercises(request):
    video = Video.objects.get(id=request.POST['video_id'])
    exercise_ids = request.POST.getlist('exercise')
    exercises = Exercise.objects.filter(id__in=exercise_ids)
    for exercise in exercises:
        video_time = 0
        videoToEx = VideoToExercise(video=video, exercise=exercise, is_deleted=False, video_time=video_time, mode="draft")
        videoToEx.save()
    return HttpResponseRedirect(reverse('courses.videos.views.manage_exercises', args=(request.POST['course_prefix'], request.POST['course_suffix'], video.slug,)))
开发者ID:gootyfer,项目名称:class2go,代码行数:11,代码来源:views.py

示例4: manage_exercises

# 需要导入模块: from c2g.models import VideoToExercise [as 别名]
# 或者: from c2g.models.VideoToExercise import save [as 别名]
def manage_exercises(request, course_prefix, course_suffix, video_slug):
    #Get all necessary information about the problemset
    try:
        common_page_data = get_common_page_data(request, course_prefix, course_suffix)
    except:
        raise Http404
    data = {'common_page_data': common_page_data}
    manage_form = ManageExercisesForm(initial={'course':common_page_data['course'].id})
    video = Video.objects.getByCourse(common_page_data['course']).get(slug=video_slug)
    videoToExs = VideoToExercise.objects.filter(video__course=common_page_data['course'], is_deleted=False, video__slug=video_slug).order_by('video_time')
    used_exercises = []
    exercise_attempted = False
    if len(ProblemActivity.objects.filter(video_to_exercise__video=video.image)) > 0:
        exercise_attempted = True
    #Get the list of exercises currently in this problem set
    for videoToEx in videoToExs:
        used_exercises.append(videoToEx.exercise.id)
    #Get all the exercises in the course but not in this problem set to list in add from existing
    #Q objects allow queryset objects to be ORed together
    exercises = Exercise.objects.all().filter(Q(problemSet__course=common_page_data['course'])|Q(video__course=common_page_data['course'])).exclude(id__in=used_exercises).distinct()
    additional_form = AdditionalExercisesForm(initial={'course':common_page_data['course'].id}, used_exercises=exercises)
    reorder_form = ReorderExercisesForm(current_exercises=videoToExs)

    #Form processing action if form was submitted
    if request.method == 'POST':
        manage_form = ManageExercisesForm(request.POST, request.FILES)
        additional_form = AdditionalExercisesForm(request.POST, used_exercises=exercises)

        if manage_form.is_valid():
            video = Video.objects.get(id=request.POST['video_id'])
            file_content = request.FILES['file']
            file_name = file_content.name

            exercise = Exercise()
            exercise.handle = request.POST['course_prefix'] + '--' + request.POST['course_suffix']
            exercise.fileName = file_name
            exercise.file.save(file_name, file_content)
            exercise.save()

            video_time = request.POST['video_time']
            videoToEx = VideoToExercise(video=video, exercise=exercise, video_time=video_time, is_deleted=0, mode='draft')
            videoToEx.save()
            return HttpResponseRedirect(reverse('courses.videos.views.manage_exercises', args=(request.POST['course_prefix'], request.POST['course_suffix'], video.slug,)))

    #If form was not submitted then the form should be displayed or if there were errors the page needs to be rendered again
    data['manage_form'] = manage_form
    data['additional_form'] = additional_form
    data['reorder_form'] = reorder_form
    data['course_prefix'] = course_prefix
    data['course_suffix'] = course_suffix
    data['video'] = video
    data['videoToExs'] = videoToExs
    data['exercise_attempted'] = exercise_attempted
    data['exercises'] = exercises
    data['exercise_attempted'] = exercise_attempted
    return render_to_response('videos/manage_exercises.html', data, context_instance=RequestContext(request))
开发者ID:gootyfer,项目名称:class2go,代码行数:58,代码来源:views.py

示例5: add_exercise

# 需要导入模块: from c2g.models import VideoToExercise [as 别名]
# 或者: from c2g.models.VideoToExercise import save [as 别名]
def add_exercise(request):
#    try:
#        common_page_data = get_common_page_data(request, course_prefix, course_suffix)
#    except:
#        raise Http404

    video = Video.objects.get(id=request.POST['video_id'])
    video_time = request.POST['videotime']

    file_content = request.FILES['exercise']
    file_name = file_content.name

    exercise = Exercise()
    exercise.handle = request.POST['course_prefix'] + '--' + request.POST['course_suffix']
    exercise.fileName = file_name
    exercise.file.save(file_name, file_content)
    exercise.save()

    videoToEx = VideoToExercise(video=video, exercise=exercise, is_deleted=False, video_time=video_time)
    videoToEx.save()
    return HttpResponseRedirect(reverse('courses.videos.views.manage_exercises', args=(request.POST['course_prefix'], request.POST['course_suffix'], video.slug,)))
开发者ID:gootyfer,项目名称:class2go,代码行数:23,代码来源:views.py

示例6: manage_exercises

# 需要导入模块: from c2g.models import VideoToExercise [as 别名]
# 或者: from c2g.models.VideoToExercise import save [as 别名]
def manage_exercises(request, course_prefix, course_suffix, video_slug):
    #Get all necessary information about the problemset
    try:
        common_page_data = get_common_page_data(request, course_prefix, course_suffix)
    except:
        raise Http404
    data = {'common_page_data': common_page_data}
    manage_form = ManageExercisesForm(initial={'course':common_page_data['course'].id})
    try:
        video = Video.objects.getByCourse(common_page_data['course']).get(slug=video_slug)
    except Video.DoesNotExist:
        raise Http404

    videoToExs = VideoToExercise.objects.filter(video__course=common_page_data['course'], is_deleted=False, video__slug=video_slug).order_by('video_time')
    used_exercises = []
    exercise_attempted = False
    if ProblemActivity.objects.filter(video_to_exercise__video=video.image).exists():
        exercise_attempted = True
    #Get the list of exercises currently in this problem set
    for videoToEx in videoToExs:
        used_exercises.append(videoToEx.exercise.id)
    #Get all the exercises in the course but not in this problem set to list in add from existing
    #Q objects allow queryset objects to be ORed together
    exercises = Exercise.objects.all().filter(Q(problemSet__course=common_page_data['course'])|Q(video__course=common_page_data['course'])).exclude(id__in=used_exercises).distinct()
    additional_form = AdditionalExercisesForm(initial={'course':common_page_data['course'].id}, used_exercises=exercises)
    reorder_form = ReorderExercisesForm(current_exercises=videoToExs)

    #Form processing action if form was submitted
    if request.method == 'POST':
        manage_form = ManageExercisesForm(request.POST, request.FILES)
        additional_form = AdditionalExercisesForm(request.POST, used_exercises=exercises)

        if manage_form.is_valid():
            
            #don't catch video DoesNotExist here because we want some tangible error to happen if
            #the video id changes in form submission, like emailing us
            video = Video.objects.get(id=request.POST['video_id'])
            video_time = request.POST['video_time']
            file_content = request.FILES['file']
            file_name = file_content.name

            exercises = Exercise.objects.filter(handle=course_prefix+"--"+course_suffix,is_deleted=0)
            exercise_exists = False
            for exercise in exercises:
                if exercise.fileName == file_name:
                    #We don't wipe out all problem activites associated with this
                    #existing exercise, but if it's a nontrivial overwrite, should we?
                    exercise.file = file_content
                    exercise.save()
                    exercise_exists = True

                    #If exercise already in video, don't need to create new videoToEx, just update video_time
                    #If exercise already in video but deleted, undelete
                    #Otherwise create new videoToEx
                    queryVideoToEx = VideoToExercise.objects.filter(video=video, exercise=exercise, mode='draft').order_by('-id')
                    if queryVideoToEx.exists():
                        existingVideoToEx = queryVideoToEx[0]
                        if existingVideoToEx.is_deleted == 1:
                            existingVideoToEx.is_deleted = 0
                            existingVideoToEx.video_time = video_time
                            existingVideoToEx.save()
                        else:
                            existingVideoToEx.video_time = video_time
                            existingVideoToEx.save()
                    else:
                        videoToEx = VideoToExercise(video=video, exercise=exercise, video_time=video_time, is_deleted=0, mode='draft')
                        videoToEx.save()
                    break

            if not exercise_exists:
                exercise = Exercise()
                exercise.handle = request.POST['course_prefix'] + '--' + request.POST['course_suffix']
                exercise.fileName = file_name
                exercise.file.save(file_name, file_content)
                exercise.save()

                videoToEx = VideoToExercise(video=video, exercise=exercise, video_time=video_time, is_deleted=0, mode='draft')
                videoToEx.save()
            return HttpResponseRedirect(reverse('courses.videos.views.manage_exercises', args=(request.POST['course_prefix'], request.POST['course_suffix'], video.slug,)))

    #If form was not submitted then the form should be displayed or if there were errors the page needs to be rendered again
    data['manage_form'] = manage_form
    data['additional_form'] = additional_form
    data['reorder_form'] = reorder_form
    data['course_prefix'] = course_prefix
    data['course_suffix'] = course_suffix
    data['video'] = video
    data['videoToExs'] = videoToExs
    data['exercise_attempted'] = exercise_attempted
    data['exercises'] = exercises
    data['exercise_attempted'] = exercise_attempted
    return render_to_response('videos/manage_exercises.html', data, context_instance=RequestContext(request))
开发者ID:Gerund,项目名称:class2go,代码行数:94,代码来源:views.py

示例7: manage_exercises

# 需要导入模块: from c2g.models import VideoToExercise [as 别名]
# 或者: from c2g.models.VideoToExercise import save [as 别名]
def manage_exercises(request, course_prefix, course_suffix, video_slug):
    # Get all necessary information about the problemset
    try:
        common_page_data = get_common_page_data(request, course_prefix, course_suffix)
    except:
        raise Http404
    data = {"common_page_data": common_page_data}
    manage_form = ManageExercisesForm(initial={"course": common_page_data["course"].id})
    try:
        video = Video.objects.getByCourse(common_page_data["course"]).get(slug=video_slug)
    except Video.DoesNotExist:
        raise Http404

    videoToExs = VideoToExercise.objects.filter(
        video__course=common_page_data["course"], is_deleted=False, video__slug=video_slug
    ).order_by("video_time")
    used_exercises = []
    exercise_attempted = False
    if len(ProblemActivity.objects.filter(video_to_exercise__video=video.image)) > 0:
        exercise_attempted = True
    # Get the list of exercises currently in this problem set
    for videoToEx in videoToExs:
        used_exercises.append(videoToEx.exercise.id)
    # Get all the exercises in the course but not in this problem set to list in add from existing
    # Q objects allow queryset objects to be ORed together
    exercises = (
        Exercise.objects.all()
        .filter(Q(problemSet__course=common_page_data["course"]) | Q(video__course=common_page_data["course"]))
        .exclude(id__in=used_exercises)
        .distinct()
    )
    additional_form = AdditionalExercisesForm(
        initial={"course": common_page_data["course"].id}, used_exercises=exercises
    )
    reorder_form = ReorderExercisesForm(current_exercises=videoToExs)

    # Form processing action if form was submitted
    if request.method == "POST":
        manage_form = ManageExercisesForm(request.POST, request.FILES)
        additional_form = AdditionalExercisesForm(request.POST, used_exercises=exercises)

        if manage_form.is_valid():

            # don't catch video DoesNotExist here because we want some tangible error to happen if
            # the video id changes in form submission, like emailing us
            video = Video.objects.get(id=request.POST["video_id"])
            file_content = request.FILES["file"]
            file_name = file_content.name

            exercise = Exercise()
            exercise.handle = request.POST["course_prefix"] + "--" + request.POST["course_suffix"]
            exercise.fileName = file_name
            exercise.file.save(file_name, file_content)
            exercise.save()

            video_time = request.POST["video_time"]
            videoToEx = VideoToExercise(
                video=video, exercise=exercise, video_time=video_time, is_deleted=0, mode="draft"
            )
            videoToEx.save()
            return HttpResponseRedirect(
                reverse(
                    "courses.videos.views.manage_exercises",
                    args=(request.POST["course_prefix"], request.POST["course_suffix"], video.slug),
                )
            )

    # If form was not submitted then the form should be displayed or if there were errors the page needs to be rendered again
    data["manage_form"] = manage_form
    data["additional_form"] = additional_form
    data["reorder_form"] = reorder_form
    data["course_prefix"] = course_prefix
    data["course_suffix"] = course_suffix
    data["video"] = video
    data["videoToExs"] = videoToExs
    data["exercise_attempted"] = exercise_attempted
    data["exercises"] = exercises
    data["exercise_attempted"] = exercise_attempted
    return render_to_response("videos/manage_exercises.html", data, context_instance=RequestContext(request))
开发者ID:pageman,项目名称:class2go,代码行数:81,代码来源:views.py


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