예제 #1
0
def create_test(request):
    login = check_sign_in(request)
    if login and (login.is_staff or login.is_superuser):
        if request.is_ajax():
            category = get_object_or_404(Category,id=int(request.POST['category']))

            test = Test(
                title = request.POST['title'],
                description = request.POST['description'],
                helps = str_to_bool(request.POST['helps']),
                time_completion = str_to_bool(request.POST['timeCompl']),
                creator = auth.get_user(request),
                category = category,
                two_mark = request.POST['two_mark'],
                three_mark = request.POST['three_mark'],
                four_mark = request.POST['four_mark']
            )
            test.save()

            return JsonResponse({'testID': test.id, 'error': False})
        else:
            categories = Category.objects.all()
            return render_to_response('create_test.html', {'login': login, 'categories': categories})
    else:
        raise Http404('Вы не имете доступа!')
예제 #2
0
def settings_test(request, id):
	test = get_object_or_404(Test, id=id)
	if test.creator == auth.get_user(request):
		if request.is_ajax():
			category = get_object_or_404(Category,id=int(request.POST['category']))

			test.title = request.POST['title']
			test.description = request.POST['description']
			test.helps = str_to_bool(request.POST['helps'])
			test.time_completion = str_to_bool(request.POST['timeCompl'])
			test.public_access = str_to_bool(request.POST['public_access'])
			test.two_mark = request.POST['two_mark']
			test.three_mark = request.POST['three_mark']
			test.four_mark = request.POST['four_mark']
			test.category = category
			test.questions_count = request.POST['quest_count']
			test.save()

			return JsonResponse({'success': 'Данные сохранены!'})
		else:
			login = check_sign_in(request)
			categories = Category.objects.all()
			return render_to_response('create_test.html', {'login': login, 'test': test, 'categories': categories})
	else:
		return redirect('/')
예제 #3
0
def test_access(request, id):
    test = get_object_or_404(Test, id=id)
    login = check_sign_in(request)
    if test.creator == login:
        if request.is_ajax():
            #Формируем данные
            if request.method == 'GET':
                specializations = SpecializationSerializer(Specialization.objects.all(), many=True).data
                groups_access = GroupSerializer(test.group_access.all(), many=True).data
                groups = GroupSerializer(Group.objects.all().order_by('course','name'), many=True).data
                for group in groups:
                    if group in groups_access:
                        group['access'] = True
                    else:
                        group['access'] = False
                courses = list(map(lambda x: {'id': x, 'name': str(x)}, range(1, 5)))
                return JsonResponse({'specs': specializations, 'groups': groups, 'courses': courses})
            elif request.method == 'POST':
                group = get_object_or_404(Group, id=request.POST.get('group', ''))
                if str_to_bool(request.POST.get('append', False)):
                    test.group_access.add(group)
                else:
                    test.group_access.remove(group)
                return JsonResponse({'success': True})
            elif request.method == "DELETE":
                test.group_access.clear()
                return JsonResponse({'success': True})
        else:
            return render_to_response('test_access.html',{'login': login, 'test': test, 'optionName': 'access'})
    else:
        raise Http404('Вы не имете доступа!')