Exemplo n.º 1
0
def add_course(request):
    if request.method == 'GET':
        form = CourseForm()
        return render(request, 'add_course.html', {'form': form})
    elif request.method == 'POST':
        form = CourseForm(request.POST)
        form.save()
        return HttpResponseRedirect(reverse('course:courses'))
Exemplo n.º 2
0
def create(request):
    if request.method == "POST":
        form = CourseForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
    else:
        form = CourseForm()

    return render(request, 'admin/course/create.html')
Exemplo n.º 3
0
def edit_course(request, id):
    course = Course.objects.get(course_id=id)
    init = {
        'exam': (True if course.exam == 1 else False),
        'exercises': course.exercises,
        'laboratories': course.laboratories,
        'project': course.project,
        'seminars': course.seminars,
        'if_exer': (True if course.exercises else False),
        'if_lab': (True if course.laboratories else False),
        'if_proj': (True if course.project else False),
        'if_sem': (True if course.seminars else False)
    }

    if request.method == "POST":
        form = CourseForm(request.POST, instance=course, initial=init)
        if form.is_valid():
            if request.POST.get('del_btn'):
                object = Course.objects.get(course_id=id)
                object.delete()
                return redirect(courses)
            else:
                course = form.save(commit=False)
                if request.POST.get('exam'):
                    course.exam = 1
                course.save()
                return redirect(courses)
    else:
        form = CourseForm(instance=course, initial=init)
    return render(request, 'create-course.html', {"form": form, "edit": 1})
Exemplo n.º 4
0
def create(request):

    if request.method == 'POST':
        form = CourseForm(request.POST)
        if form.is_valid():
            created = form.save(commit=False)
            created.save()
            created.teacher.add(request.user.userinformation)

            Schedule.objects.create(_type=request.POST['schedule_type'],
                                    course=created)

            assign_perm('change_course', request.user, created)
            assign_perm('delete_course', request.user, created)

            return redirect('course', created.id)
    else:
        form = CourseForm(
            initial={
                'description': DEFAULT_COURSE_DESCRIPTION,
                'max_participants': 30,
                'archiving': 't'
            })
        if 'subject' in request.GET:
            subj = int(request.GET['subject'][0])
            if Subject.objects.filter(id=subj).exists():
                form.initial['subject'] = subj

    return render(request, 'course/create.html', {
        'title': _('New Course'),
        'form': form
    })
Exemplo n.º 5
0
def edit_course(request):
    if request.method == 'GET':
        if 'id' in request.GET and Course.objects.filter(
                id=request.GET['id']).count() > 0:
            course = Course.objects.get(id=request.GET['id'])
            form = CourseForm(instance=course)
            return render(request, 'edit_course.html', {
                'id': request.GET['id'],
                'form': form
            })
        else:
            return render(request, 'not_found.html', {})
    elif request.method == 'POST':
        cid = request.POST['course_id']
        course = Course.objects.get(id=cid)
        form = CourseForm(request.POST, instance=course)
        form.save()
        return HttpResponseRedirect(reverse('course:courses'))
Exemplo n.º 6
0
def create_course(request):
    if request.method == "POST":
        form = CourseForm(request.POST)
        course = form.save(commit=False)
        if request.POST.get('exam'):
            course.exam = 1
        course.save()
        return redirect(courses)
    else:
        form = CourseForm()
    return render(request, 'create-course.html', {"form": form})
Exemplo n.º 7
0
def course_add(request, template_name="course/add.html"):
    if request.method == "POST":
        form = CourseForm(request.POST)
        if form.is_valid():
            course = form.save(commit=False)
            course.admin = request.user
            course.save()
            course.developers.add(course.leader)
            return HttpResponseRedirect(reverse('course_activate', 
                        kwargs={"cid":course.id}))
    else:
        form = CourseForm()
    
    return render_to_response(template_name, {
        'form' : form,
    }, context_instance=RequestContext(request))
Exemplo n.º 8
0
def add_course(request: HttpRequest, course_id: int = None):
    course = None
    if course_id:
        course = get_object_or_404(models.Course, pk=course_id)
    if request.method == "POST":
        course_form = CourseForm(instance=course,
                                 data=request.POST,
                                 files=request.FILES)
        if course_form.is_valid():
            course: models.Course = course_form.save(commit=False)
            course.created_by = request.user
            course.save()
            messages.success(request,
                             f"Course {course.title} created successfully")
    else:
        course_form = CourseForm(instance=course)
    return render(request, "course/course_create.html",
                  {"course_form": course_form})
Exemplo n.º 9
0
def mycourses(request):
	subs = Subscription.objects.filter(user=request.user)
	courses = []
	for sub in subs:
		courses.append(sub.course)

	if request.method == 'POST':
		course_form = CourseForm(request.POST, request.FILES)
		print course_form.errors
		if course_form.is_valid():
			course = course_form.save()
			author = Author(user=request.user, course=course)
			author.save()

	else:
		course_form = CourseForm()

	return render(request, 'home/mycourses.html', {'courses': courses, 'course_form': course_form})
Exemplo n.º 10
0
def create(request):

    if request.method == 'POST':
        form = CourseForm(request.POST)
        if form.is_valid():
            created = form.save(commit=False)
            created.save()
            created.teacher.add(request.user.userinformation)

            Schedule.objects.create(_type=request.POST['schedule_type'], course=created)

            assign_perm(
                'change_course',
                request.user,
                created
            )
            assign_perm(
                'delete_course',
                request.user,
                created
            )

            return redirect('course', created.id)
    else:
        form = CourseForm(initial={
            'description': DEFAULT_COURSE_DESCRIPTION,
            'max_participants': 30,
            'archiving': 't'
        })
        if 'subject' in request.GET:
            subj = int(request.GET['subject'][0])
            if Subject.objects.filter(id=subj).exists():
                form.initial['subject'] = subj

    return render(
        request,
        'course/create.html',
        {
            'title': _('New Course'),
            'form': form
        }
    )
Exemplo n.º 11
0
def create_course(request):
	if settings.DEBUG:
		print('is_authenticated: {}'.format(request.user.is_authenticated()))
	
	if not request.user.is_authenticated():
		return HttpResponseRedirect(reverse('login'))

	if request.method == 'POST':
		course_form = CourseForm(request.POST, user=request.user)
		if course_form.is_valid():
			course = course_form.save(commit=False)

			course.creator = request.user

			student_key = generate_key()
			while Course.objects.filter(student_key=student_key).exists():
				student_key = generate_key()
			
			course.student_key = student_key
			
			instructor_key = generate_key()
			while Course.objects.filter(instructor_key=instructor_key).exists():
				instructor_key = generate_key()

			course.instructor_key = instructor_key

			course.save()
			kwargs = {
				'username' : request.user.username
			}
			return HttpResponseRedirect(reverse('course_list', kwargs=kwargs))
		else:
			print(course_form.errors)
	else:
		course_form = CourseForm(user=request.user)

	context = {
		'form' : course_form,
	}
	return render(request, 'course/create_course.html', context=context)