Beispiel #1
0
def lesson_create(request, slug):
	course = get_object_or_404(Course, slug=slug)
	if request.method == 'POST':
		form = LessonForm(request.POST)
		if form.is_valid:
			lesson = form.save(commit= False)
			lesson.course = course
			lesson.user = course.user
			lesson.save()
			return redirect(lesson.get_absolute_url())

	else:
		form = LessonForm()

	return render(request, 'lessons/lesson_form.html', {'form': form})



















	
def get_lesson_form(lesson):

	try:
		r = LessonLearnt.objects.get(id=lesson)
	except LessonLearnt.DoesNotExist:
		return ''
	f = LessonForm(instance=r)
	return f.as_table()
Beispiel #3
0
def get_lesson_form(lesson):

    try:
        r = LessonLearnt.objects.get(id=lesson)
    except LessonLearnt.DoesNotExist:
        return ''
    f = LessonForm(instance=r)
    return f.as_table()
    def create(self, request, project_number):
        """ Create a new Lesson """

        log.debug("POST request from user %s to create a new lesson" % request.user)
        proj = Project.objects.get(project_number=project_number)

        if not check_project_write_acl(proj, request.user):
            log.debug("Refusing POST request for project %s from user %s" % ( project_number, request.user ))
            return rc.FORBIDDEN

        # Go ahead and create the lesson....
        form = LessonForm(request.POST)
        t = form.save()
        proj.lessons.add(t)
        proj.save()
        return t
Beispiel #5
0
def edit_lesson(request, reviewprogram_id, lesson_id):
    reviewprogram = ReviewProgram.objects.get(id=reviewprogram_id)
    lesson = Lesson.objects.get(id=lesson_id)
    if request.user == reviewprogram.instructor:
        form = LessonForm(instance=lesson)
        if request.method == 'POST' and 'update' in request.POST:
            form = LessonForm(instance=lesson, data=request.POST)
            if form.is_valid():
                update(form, lesson)
                # add_questions(reviewprogram, mocktest)
                messages.success(request, 'Lesson updated successfully!')
                return redirect('/manage/' + reviewprogram_id + '/lessons/')
        if request.method == 'POST' and 'delete' in request.POST:
            delete(lesson)
            messages.success(request, 'Lesson deleted successfully!')
            return redirect('/manage/' + reviewprogram_id + '/lessons/')
        return render(request, 'edit_lesson.html', {
            'form': form,
            'reviewprogram': reviewprogram,
            'lesson': lesson
        })
    return redirect('/manage/' + reviewprogram_id + '/lessons/')
    def update(self, request, project_number, lesson_id):
        """ Update the lesson """

        log.debug("PUT request from user %s for lesson %s" % ( request.user, lesson_id ))
        proj = Project.objects.get(project_number=project_number)
        lesson = LessonLearnt.objects.get(id=lesson_id)
        log.debug("Fetched object from database %s" % lesson)

        if not check_project_write_acl(proj, request.user):
            log.debug("Refusing PUT request for project %s from user %s" % ( project_number, request.user ))
            return rc.FORBIDDEN

        form = LessonForm(request.POST, instance=lesson)
        if form.is_valid():
            t = form.save()
            log.debug('Saving %s back to database' % t)
            return t
        else:
            resp = rc.BAD_REQUEST
            resp.write(form.errors)
            log.debug('Validation errors with %s' % t)
            return resp
Beispiel #7
0
def addLesson(request):
    user = request.user
    if user.is_authenticated():
        lessonForm = LessonForm(request.POST)
        if request.method == 'POST':
            print(lessonForm)
            lesson = Lesson()
            if lessonForm.is_valid():
                print(lessonForm)
                lesson.group = lessonForm.cleaned_data['group']
                lesson.discipline = lessonForm.cleaned_data['discipline']
                lesson.dateAndTtime = lessonForm.cleaned_data['dateAndTtime']
                lesson.room = lessonForm.cleaned_data['room']
                lesson.lessonID = lessonForm.cleaned_data['lessonID']
                lesson.status = lessonForm.cleaned_data['status']
                lesson.user = lessonForm.cleaned_data['user']
                lesson.save()
                return HttpResponseRedirect('/admin')
        return render_to_response('dokladedit.html', { 'form': lessonForm}, context_instance=RequestContext(request))
    #text = """<html><body><h1>Hello world</h1><p>asdfgvbasdbg</p></body></html>"""
    #text2 = "hello again"
    #return HttpResponse(text)
    return render(request,'vote/create.html', {})
Beispiel #8
0
def addLesson(request):
    user = request.user
    if user.is_authenticated():
        lessonForm = LessonForm(request.POST)
        if request.method == 'POST':
            print(lessonForm)
            lesson = Lesson()
            if lessonForm.is_valid():
                print(lessonForm)
                lesson.group = lessonForm.cleaned_data['group']
                lesson.discipline = lessonForm.cleaned_data['discipline']
                lesson.dateAndTtime = lessonForm.cleaned_data['dateAndTtime']
                lesson.room = lessonForm.cleaned_data['room']
                lesson.lessonID = lessonForm.cleaned_data['lessonID']
                lesson.status = lessonForm.cleaned_data['status']
                lesson.user = lessonForm.cleaned_data['user']
                lesson.save()
                return HttpResponseRedirect('/admin')
        return render_to_response('dokladedit.html', {'form': lessonForm},
                                  context_instance=RequestContext(request))
    #text = """<html><body><h1>Hello world</h1><p>asdfgvbasdbg</p></body></html>"""
    #text2 = "hello again"
    #return HttpResponse(text)
    return render(request, 'vote/create.html', {})
Beispiel #9
0
def create_lesson(request, reviewprogram_id):
    reviewprogram = ReviewProgram.objects.get(id=reviewprogram_id)

    # if MockTestSection.objects.filter(reviewprogram=reviewprogram).exists():
    form = LessonForm(reviewprogram=reviewprogram)
    if request.method == 'POST':
        form = LessonForm(reviewprogram=reviewprogram, data=request.POST)
        if form.is_valid():
            lessons = form.save(commit=False)
            lessons.reviewprogram = reviewprogram
            lessons.postedby = request.user
            lessons.save()
            # add_questions(reviewprogram, mocktest)
            messages.success(request, 'Lessons created successfully!')
            return redirect('/manage/' + reviewprogram_id + '/lessons/')
    return render(request, 'create_lesson.html', {
        'form': form,
        'reviewprogram': reviewprogram
    })
    # messages.error(request, 'ReviewProgram has no questions!')
    return redirect('/manage/' + reviewprogram_id)