Ejemplo n.º 1
0
def edit_course(request, course_id):
    course_to_edit = get_object_or_404(Course, pk=course_id)

    # don't let people edit courses that other people created
    if request.user != course_to_edit.creator:
        messages.error(request, 'You can only edit courses that you have created')
        return redirect('view_course', course_id=course_id, course_slug=course_to_edit.slug)

    EditLessonFormSet = inlineformset_factory(Course, Lesson, can_delete=False, form=LessonForm, formset=OrderedLessonFormSet, extra=1)
    
    if request.method == 'POST':
        
        edit_course_form = CourseForm(request.POST, request.FILES, instance=course_to_edit)
        edit_lesson_fs = EditLessonFormSet(request.POST, instance=course_to_edit)
        new_data = request.POST.copy();

        if edit_course_form.is_valid() and edit_lesson_fs.is_valid():
            edit_course_form.save() 
            edited_lessons = edit_lesson_fs.save()
            
            messages.success(request, 'Your changes have been saved!')
            return redirect('view_course', course_id=course_id, course_slug=course_to_edit.slug) 
        
    else:
        edit_course_form = CourseForm(instance=course_to_edit)
        edit_lesson_fs = EditLessonFormSet(instance=course_to_edit)
    
    return render_to_response('add_course2.dtl', {
		'requested_course': course_to_edit,
        'course_form': edit_course_form,
        'lesson_fs': edit_lesson_fs,
        'to_client': json.dumps({'delete_lesson_url': reverse('delete_lesson')})
    },
    context_instance=RequestContext(request))
Ejemplo n.º 2
0
def add_course(request):
    if request.method == 'POST':
        form = CourseForm(request.POST or None)
        if form.is_valid():
            form.save()
            return redirect('core:index')
    form = CourseForm()
    context = {'form': form}
    return render(request, 'core/add_course.html', context)
Ejemplo n.º 3
0
def add_course(request):
    EditLessonFormSet = inlineformset_factory(Course, Lesson, can_delete=False, form=LessonForm, formset=OrderedLessonFormSet, extra=1) 
                                         
    if request.method == 'POST':
        course_form = CourseForm(request.POST, request.FILES)
        lesson_fs = EditLessonFormSet(request.POST)     
        
        if course_form.is_valid() and lesson_fs.is_valid():
            new_course = course_form.save(commit=False)
            new_course.creator = request.user
            new_course.save()
            # save tags
            course_form.save_m2m()

            lesson_fs.instance = new_course
            lesson_fs.save()

            messages.success(request, 'Your course has been created! Share it with your friends on Twitter and Facebook.')
            return redirect('view_my_profile')

    else:
        course_form = CourseForm()            
        lesson_fs = EditLessonFormSet()

	messages.success(request, 'A course is a set of resources for someone to progress through to learn about the subject. Get creative! You\'re the expert.')
    return render_to_response('add_course2.dtl', {
        'course_form': course_form,
        'lesson_fs': lesson_fs,
        'is_add_page': True
    },
    context_instance=RequestContext(request))
Ejemplo n.º 4
0
def edit_course(request, course_id):
    course_to_edit = get_object_or_404(Course, pk=course_id)

    # don't let people edit courses that other people created
    if request.user != course_to_edit.creator:
        messages.error(request,
                       'You can only edit courses that you have created')
        return redirect('view_course',
                        course_id=course_id,
                        course_slug=course_to_edit.slug)

    EditLessonFormSet = inlineformset_factory(Course,
                                              Lesson,
                                              can_delete=False,
                                              form=LessonForm,
                                              formset=OrderedLessonFormSet,
                                              extra=1)

    if request.method == 'POST':

        edit_course_form = CourseForm(request.POST,
                                      request.FILES,
                                      instance=course_to_edit)
        edit_lesson_fs = EditLessonFormSet(request.POST,
                                           instance=course_to_edit)
        new_data = request.POST.copy()

        if edit_course_form.is_valid() and edit_lesson_fs.is_valid():
            edit_course_form.save()
            edited_lessons = edit_lesson_fs.save()

            messages.success(request, 'Your changes have been saved!')
            return redirect('view_course',
                            course_id=course_id,
                            course_slug=course_to_edit.slug)

    else:
        edit_course_form = CourseForm(instance=course_to_edit)
        edit_lesson_fs = EditLessonFormSet(instance=course_to_edit)

    return render_to_response('add_course2.dtl', {
        'requested_course':
        course_to_edit,
        'course_form':
        edit_course_form,
        'lesson_fs':
        edit_lesson_fs,
        'to_client':
        json.dumps({'delete_lesson_url': reverse('delete_lesson')})
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 5
0
def add_course(request):
    EditLessonFormSet = inlineformset_factory(Course,
                                              Lesson,
                                              can_delete=False,
                                              form=LessonForm,
                                              formset=OrderedLessonFormSet,
                                              extra=1)

    if request.method == 'POST':
        course_form = CourseForm(request.POST, request.FILES)
        lesson_fs = EditLessonFormSet(request.POST)

        if course_form.is_valid() and lesson_fs.is_valid():
            new_course = course_form.save(commit=False)
            new_course.creator = request.user
            new_course.save()
            # save tags
            course_form.save_m2m()

            lesson_fs.instance = new_course
            lesson_fs.save()

            messages.success(
                request,
                'Your course has been created! Share it with your friends on Twitter and Facebook.'
            )
            return redirect('view_my_profile')

    else:
        course_form = CourseForm()
        lesson_fs = EditLessonFormSet()

        messages.success(
            request,
            'A course is a set of resources for someone to progress through to learn about the subject. Get creative! You\'re the expert.'
        )
    return render_to_response('add_course2.dtl', {
        'course_form': course_form,
        'lesson_fs': lesson_fs,
        'is_add_page': True
    },
                              context_instance=RequestContext(request))