Esempio n. 1
0
def add_lesson(request, pk):
    course = Course.objects.get(pk=pk)
    form = LessonModelForm(initial={'course': course})
    if request.method == 'POST':
        form = LessonModelForm(request.POST)
        if form.is_valid():
            subject = form.cleaned_data['subject']
            form.save()
            messages.success(request, 'Lesson %s has been successfully added.' % subject)
            return redirect('courses:detail', pk=pk)
    return render(request, 'courses/add_lesson.html', {'form': form})
def add_lesson(request, course_id):
    cd = Course.objects.get(id=course_id)
    if request.POST:
        form = LessonModelForm(request.POST)
        if form.is_valid():
            form.save()
            text = "Lesson " + form.cleaned_data['subject'] + " has been successfully added."
            messages.success(request, text)
            return redirect('courses:detail',course_id)
    else:
        form = LessonModelForm(initial={'course':course_id})
        form.fields['course'].queryset = Course.objects.all()
    return render(request, 'courses/add_lesson.html', {'form': form})
def add_lesson(request, pk):
    course = Course.objects.get(id=pk)
    if request.method == "POST":
        form = LessonModelForm(request.POST, initial = {'course':course.id})
        if form.is_valid():
            data = form.cleaned_data
            
            form.save()    
        messages.success(request, 'Lesson {} has been successfully added.'.format(data['subject']))
        return redirect('courses:detail', pk)


    else:
        form = LessonModelForm()
        
    return render(request, "courses/add_lesson.html", {'form':form})
Esempio n. 4
0
def add_lesson(request, id_of_course):
    if request.method == "POST":
        form = LessonModelForm(request.POST)
        if form.is_valid():
            lesson = form.save()
            messages.success(request, "Lesson %s has been successfully added." % (lesson.subject))
            return redirect("courses:detail", id_of_course=id_of_course)
    else:
        form = LessonModelForm(initial={"course": id_of_course})

    return render(request, "courses/add_lesson.html", {"form": form})
def add_lesson(request, id):
    course = Course.objects.get(id=id)
    form = LessonModelForm(initial={'course': course})
    if request.method == 'POST':
        form = LessonModelForm(request.POST)
        if form.is_valid():
            lesson = form.save()
            messages.success(request, ('Lesson %s has been successfully added.' % lesson.subject))
            return redirect('courses:detail', lesson.course.id)
    context = {'form': form, 'course': course}
    return render(request, 'courses/add_lesson.html', context)
def add_lesson(request, course_id):
    if request.method == 'POST':
        form = LessonModelForm(request.POST)
        if form.is_valid():
            lesson = form.save()
            messages.success(request, u'Lesson %s has been successfully added.' % (lesson.subject))
            return redirect('courses:detail', lesson.course.id)
    else:
        course=Course.objects.get(id=course_id)
        form = LessonModelForm(initial = {'course': course})
    return render(request, 'courses/add_lesson.html', {'form' : form})
Esempio n. 7
0
def add_lesson(request, pk):
    courses = Course.objects.filter(pk=pk)
    course = Course.objects.get(pk=pk)
    lessons_all = Lesson.objects.filter(course=courses)
    if request.method == 'POST':
        model_form = LessonModelForm(request.POST)
        if model_form.is_valid():
            lesson = model_form.save()
            messages.success(request, 'Lesson %s has been successfully added.' % lesson.subject) 
            return redirect('courses:detail', pk=pk)
    else:
        model_form = LessonModelForm(initial={"course": pk})
    return render(request, 'courses/add_lesson.html', {'model_form': model_form})    
Esempio n. 8
0
def add_lesson(request, id_of_course):
    if request.method == 'POST':
        form = LessonModelForm(request.POST)
        if form.is_valid():
            lesson = form.save()
            messages.success(
                request,
                "Lesson %s has been successfully added." % (lesson.subject))
            return redirect('courses:detail', id_of_course=id_of_course)
    else:
        form = LessonModelForm(initial={'course': id_of_course})

    return render(request, 'courses/add_lesson.html', {'form': form})
Esempio n. 9
0
def add_lesson(request, course_id):
    get_object_or_404(Course, pk=course_id)
    if request.method == 'POST':
        form = LessonModelForm(request.POST)
        if form.is_valid():
            lesson = form.save()
            messages.success(
                request,
                'Lesson %s has been successfully added.' % lesson.subject)
            return redirect(
                reverse('courses:detail', kwargs={'course_id': course_id}))
    else:
        form = LessonModelForm(initial={'course': course_id})

    return render(request, 'courses/add_lesson.html', {'form': form})
Esempio n. 10
0
def add_lesson(request, pk):
	application_course = Course.objects.get(id=pk)
	if request.method == "POST":
		model_form = LessonModelForm(request.POST)
		if model_form.is_valid():
			application = model_form.save()
			messages.success(request, 
				'Lesson %s has been successfully added.' % application.subject)
			return redirect('courses:detail', application_course.id)
	else:
		model_form = LessonModelForm(initial={'course':application_course})
	template = loader.get_template('courses/add_lesson.html')
	context = RequestContext(request, {
    'model_form': model_form,
        })
	return HttpResponse(template.render(context))