Exemple #1
0
def create_test(request):
	login = check_sign_in(request)
	if login:
		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,
				questions_count = request.POST['quest_count'],
				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:
		return redirect('/')
Exemple #2
0
def test_list(request):
    if request.method == 'GET':
        tests = Test.objects.filter(public_access=True)
        serializer = TestSerializer(tests, many=True)
        return Response(serializer.data)
    elif request.method == "POST":
        user = User.objects.get(id=request.data['user'])
        category = Category.objects.get(url=request.data['category'])
        test = Test(
            title = request.data['title'],
            description = request.data['desc'],
            helps = request.data['helps'],
            time_completion = request.data['time'],
            creator = user,
            category = category,
            questions_count = request.data['count_questions'],
            two_mark = request.data['two_mark']['last'],
            three_mark = request.data['three_mark']['last'],
            four_mark = request.data['four_mark']['last']
        )

        test.save()
        serializer = TestSerializer(test)
        return Response(serializer.data, status=status.HTTP_201_CREATED)