예제 #1
0
파일: views.py 프로젝트: tomasd/schools-old
def course_lessons(request, slug):
    course = get_object_or_404(Course, slug=slug)

    course_lesson = Lesson(course=course)
    if request.method == "POST":
        form = LessonForm(request.POST, instance=course_lesson)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(form.instance.get_absolute_url())
    else:
        form = LessonForm(instance=course_lesson)

    return render_to_response(
        "courses/course_lesson_list.html",
        {"course": course, "lesson_list": course.lesson_set.all(), "create_lesson": form},
        context_instance=RequestContext(request),
    )
예제 #2
0
파일: views.py 프로젝트: tomasd/schools-old
def course_lesson_detail(request, slug, lesson_id):
    course = get_object_or_404(Course, slug=slug)
    course_lesson = get_object_or_404(course.lesson_set.all(), pk=lesson_id)

    if request.method == "POST":
        lesson_form = LessonForm(request.POST, instance=course_lesson)
        if lesson_form.is_valid():
            lesson_form.save()
            return HttpResponseRedirect(lesson_form.instance.get_absolute_url())
    else:
        lesson_form = LessonForm(instance=course_lesson)

    return render_to_response(
        "courses/course_lesson_form.html",
        {"course": course, "form": lesson_form, "lesson_list": course.lesson_set.all()},
        context_instance=RequestContext(request),
    )