Exemple #1
0
def add_video(request,lesson_id):
    if request.method == 'POST': # If the form has been submitted...
        video_form = VideoForm(request.POST,request.FILES) # A form bound to the POST data
        if video_form.is_valid(): # All validation rules pass
            # Process the data in form.cleaned_data
            video = video_form.save(commit=False)
            video.lesson = get_object_or_404(Lesson,pk=lesson_id)
            video.save()
            messages.success(request,_('Video added successfully'))
            return HttpResponseRedirect(reverse('elearning.views.building_course', args=(video.lesson.subject.course.id,))) # Redirect after POST
        else:
            messages.error(request,_('Failed to add Video'))
    else:
        video_form = VideoForm() # An unbound form

    return render_to_response('elearning/add_video.html',{'video_form':video_form},context_instance = RequestContext(request))
Exemple #2
0
def add_lesson(request,subject_id):
    subject = get_object_or_404(Subject,pk=subject_id,course__status__name__in=["building",'evaluation period'])
    if request.method == 'POST': # If the form has been submitted...
        lesson_form = LessonForm(request.POST) # A form bound to the POST data
        video_form = VideoForm(request.POST,request.FILES) # A form bound to the POST data
        if lesson_form.is_valid() and video_form.is_valid(): # All validation rules pass
            # Process the data in form.cleaned_data
            lesson = lesson_form.save(commit=False)
            lesson.subject = subject
            lesson.order = 1
            lesson.save()
            video = video_form.save(commit=False)
            video.lesson = lesson
            video.save()
            messages.success(request,_('Lesson added successfully'))
            return HttpResponseRedirect(reverse('elearning.views.building_course', args=(lesson.subject.course.id,))) # Redirect after POST
        else:
            messages.error(request,_('Failed to add the lesson'))
    else:
        lesson_form = LessonForm() # An unbound form
        video_form = VideoForm() # An unbound form
    return render_to_response('elearning/add_lesson.html',{'lesson_form':lesson_form,'video_form': video_form,'subject': subject},context_instance = RequestContext(request))
Exemple #3
0
def edit_lesson(request,lesson_id):
    lesson = get_object_or_404(Lesson,pk=lesson_id,subject__course__status__name__in=["building",'evaluation period'])
    try:
        video = Video.objects.get(pk=lesson.video.id,lesson__subject__course__status__name__in=["building",'evaluation period'])
    except ObjectDoesNotExist:
        video = None
    if request.method == 'POST': # If the form has been submitted...
        lesson_form = LessonForm(request.POST,instance=lesson) # A form bound to the POST data
        video_form = VideoForm(request.POST,request.FILES,instance=video)
        if lesson_form.is_valid() and video_form.is_valid(): # All validation rules pass
            # Process the data in form.cleaned_data
            lesson = lesson_form.save(commit=False)
            lesson.save()
            video = video_form.save(commit=False)
            video.lesson = lesson
            video.save()
            messages.success(request,_('Lesson updated successfully'))
            return HttpResponseRedirect(reverse('elearning.views.building_course', args=(lesson.subject.course.id,))) # Redirect after POST
        else:
            messages.error(request,_('Failed to updated the lesson'))
    else:
        lesson_form = LessonForm(instance=lesson) # An unbound form
        video_form = VideoForm(instance=video) # An unbound form
    return render_to_response('elearning/edit_lesson.html',{'lesson_form':lesson_form,'video_form':video_form},context_instance = RequestContext(request))