示例#1
0
def addCourse(request):
    if not request.is_ajax():
        return HttpResponseBadRequest()
        pass
    # print "HERE!@$##@$%$#@%$#@%$#@%$@#%"
    # response_data = {}
    # response_data['message'] = 'You messed up bad'
    # response_data = "hey"
    # return redirect('login:index')

    # return HttpResponse(json.dumps(response_data), content_type='application/json')

    form = AddCourseForm(request.user, request.POST)

    if form.is_valid():
        # form.save()
        course_number = form.cleaned_data['course_number']
        course_subject = form.cleaned_data['course_subject'].strip()  #.upper()
        semester = form.cleaned_data['semester']

        if request.user.university != semester.university:
            raise PermissionDenied
        if semester not in request.user.university.current_sems:
            raise PermissionDenied

        try:
            course = Course.objects.get(
                course_number=course_number,
                course_subject=course_subject,
                semester=semester,
            )
        except Course.DoesNotExist:
            created_by = request.user
            course = Course.objects.create(
                course_number=course_number,
                course_subject=course_subject,
                semester=semester,
                created_by=created_by,
            )
            messager.create_course(request, course)

        #Using a 'through' table so can't do this anymore.
        #request.user.courses.add(course)

        if not UsersInCourses.objects.filter(course=course,
                                             student=request.user).exists():
            m1 = UsersInCourses.objects.create(course=course,
                                               student=request.user)
            # messager.join_course(request, course)#  - It is pretty obvious they have joined a course.
        response_data = {'course_url': course.get_absolute_url()}

    else:
        response_data = {
            'errors':
            dict([(k, [unicode(e) for e in v])
                  for k, v in form.errors.items()])
        }

    return HttpResponse(json.dumps(response_data),
                        content_type='application/json')
示例#2
0
def teacher(request):
    add_course_form = AddCourseForm(request.POST or None)
    queryset_course = Course.objects.filter(user__username=request.user)

    path = request.path.split('/')[1]
    redirect_path = path
    path = path.title()

    context = {
        'title': 'Teacher',
        'add_course_form': add_course_form,
        'queryset_course': queryset_course,
        'path': path,
        'redirect_path': redirect_path
    }

    if add_course_form.is_valid():
        instance = add_course_form.save(commit=False)
        course_name = add_course_form.cleaned_data['name']
        course_category = add_course_form.cleaned_data['category']
        instance.user = request.user
        instance.save()
        return redirect(reverse('teacher'))

    return render(request, 'users/teacher_dashboard.html', context)
示例#3
0
def professor(request):
    add_course_form = AddCourseForm(request.POST or None)
    queryset_course = Course.objects.filter(user__username=request.user)

    context = {
        "title": "Professor",
        "add_course_form": add_course_form,
        "queryset_course": queryset_course,
    }

    if add_course_form.is_valid():
        course_name = add_course_form.cleaned_data.get("course_name")
        instance = add_course_form.save(commit=False)
        instance.user = request.user
        instance.text = add_course_form.cleaned_data.get("text")
        key = add_course_form.cleaned_data.get("link")

        if 'embed' not in key and 'youtube' in key:
            key = key.split('=')[1]
            instance.link = 'https://www.youtube.com/embed/' + key

        
        instance.save()
        return redirect(reverse('professor_course', kwargs={'course_name': course_name}))

    return render(request, "users/professor_dashboard.html", context)
示例#4
0
def addCourse(request):
    if not request.is_ajax():
        return HttpResponseBadRequest()
        pass
    # print "HERE!@$##@$%$#@%$#@%$#@%$@#%"
    # response_data = {}
    # response_data['message'] = 'You messed up bad'
    # response_data = "hey"
    # return redirect('login:index')
    
    # return HttpResponse(json.dumps(response_data), content_type='application/json') 

    form = AddCourseForm(request.user, request.POST)

    if form.is_valid():
        # form.save()
        course_number = form.cleaned_data['course_number']
        course_subject = form.cleaned_data['course_subject'].strip()#.upper()
        semester = form.cleaned_data['semester']

        if request.user.university != semester.university:
            raise PermissionDenied
        if semester not in request.user.university.current_sems:
            raise PermissionDenied

        try:
            course = Course.objects.get(
                course_number=course_number, 
                course_subject=course_subject, 
                semester=semester,
            )
        except Course.DoesNotExist:
            created_by = request.user
            course = Course.objects.create(
                course_number=course_number, 
                course_subject=course_subject, 
                semester=semester,
                created_by=created_by,
            )
            messager.create_course(request, course)
        
        #Using a 'through' table so can't do this anymore.
        #request.user.courses.add(course)

        if not UsersInCourses.objects.filter(course=course, student=request.user).exists():
            m1 = UsersInCourses.objects.create(course=course, student=request.user)
            # messager.join_course(request, course)#  - It is pretty obvious they have joined a course.    
        response_data = {'course_url':course.get_absolute_url()}

    else:
        response_data = {'errors': dict([(k, [unicode(e) for e in v]) for k,v in form.errors.items()] ) }

    return HttpResponse(json.dumps(response_data), content_type='application/json') 
示例#5
0
def professor(request):
    add_course_form = AddCourseForm(request.POST or None)
    queryset_course = Course.objects.filter(user__username=request.user)

    context = {
        "title": "Professor",
        "add_course_form": add_course_form,
        "queryset_course": queryset_course,
    }

    if add_course_form.is_valid():
        course_name = add_course_form.cleaned_data.get("course_name")
        instance = add_course_form.save(commit=False)
        instance.user = request.user
        instance.save()
        return redirect(reverse('professor_course', kwargs={'course_name': course_name}))

    return render(request, "users/professor_dashboard.html", context)
示例#6
0
def professor(request):
    add_course_form = AddCourseForm(request.POST or None)
    queryset_course = Course.objects.filter(user__username=request.user)

    context = {
        "title": "教练",
        "add_course_form": add_course_form,
        "queryset_course": queryset_course,
    }

    if add_course_form.is_valid():
        course_name = add_course_form.cleaned_data.get("course_name")
        instance = add_course_form.save(commit=False)
        instance.user = request.user
        instance.save()
        return redirect(reverse('professor_course', kwargs={'course_name': course_name}))

    return render(request, "users/professor_dashboard.html", context)
示例#7
0
def professor(request, course_name=None):
    add_course_form = AddCourseForm(request.POST or None)
    queryset_course = Course.objects.filter(
        user__username=request.user).filter(
            is_active=True).prefetch_related('chapter_set')

    course_instance = {}
    excluded_students = {}
    for q in queryset_course:
        excluded_students = UserProfile.objects.exclude(
            students_to_course=q.id).filter(is_professor=False).filter(
                is_site_admin=False)
        q.excluded_students = excluded_students

    query_first = request.GET.get("q1")
    if query_first:
        excluded_students = excluded_students.filter(
            username__icontains=query_first)

    query_second = request.GET.get("q2")
    if query_second:
        added_students = added_students.filter(
            username__icontains=query_second)

    add_chapter_form = AddChapterForm(request.POST or None)

    context = {
        "title": "Professor",
        "excluded_students": excluded_students,
        "add_course_form": add_course_form,
        "add_chapter_form": add_chapter_form,
        "queryset_course": queryset_course,
        "course_name": course_name,
    }

    if add_course_form.is_valid():
        course_name = add_course_form.cleaned_data.get("course_name")
        instance = add_course_form.save(commit=False)
        instance.user = request.user
        instance.save()
        return redirect(
            reverse('professor_course', kwargs={'course_name': course_name}))

    return render(request, "users/professor_dashboard.html", context)
示例#8
0
    def get_sidebar_data(self):
        from courses.forms import AddCourseForm

        sidebar_data = []
        for semester in self.university.current_sems.order_by('start_date'):
            sem_data = {}
            sem_data['semester'] = semester
            sem_data['courses'] = self.current_courses.filter(
                semester=semester)
            sem_data['add_course_form'] = AddCourseForm(
                self, initial={'semester': semester})
            sidebar_data.append(sem_data)

        return sidebar_data