コード例 #1
0
ファイル: views.py プロジェクト: jeffreybreen/class2go
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),
        )
    )
コード例 #2
0
ファイル: views.py プロジェクト: pageman/class2go
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),
        )
    )
コード例 #3
0
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,
                )))
コード例 #4
0
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,
                )))
コード例 #5
0
ファイル: views.py プロジェクト: gootyfer/class2go
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,)))
コード例 #6
0
ファイル: views.py プロジェクト: gootyfer/class2go
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))
コード例 #7
0
ファイル: views.py プロジェクト: eozkeskin/class2go
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:
        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,)))
コード例 #8
0
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:
        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,)))
コード例 #9
0
ファイル: views.py プロジェクト: gootyfer/class2go
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,)))
コード例 #10
0
ファイル: views.py プロジェクト: Gerund/class2go
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))
コード例 #11
0
ファイル: views.py プロジェクト: pageman/class2go
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))
コード例 #12
0
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))