コード例 #1
0
ファイル: views.py プロジェクト: RogerHount/sdacademy
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})
コード例 #2
0
ファイル: views.py プロジェクト: gklymchuk/sdacademy
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})
コード例 #3
0
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})
コード例 #4
0
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})
コード例 #5
0
ファイル: views.py プロジェクト: PetroVlasov/sdacademy
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})    
コード例 #6
0
ファイル: views.py プロジェクト: jesuisdima/sdacademy
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))
コード例 #7
0
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)
コード例 #8
0
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})
コード例 #9
0
ファイル: views.py プロジェクト: RogerHount/sdacademy
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})
コード例 #10
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})
コード例 #11
0
 def get(self, request, *args, **kwargs):
     course = Course.objects.get(pk=kwargs['pk'])
     form = LessonModelForm(initial={'course': course.id})
     return render(request, self.template_name, {"form": form})