示例#1
0
	def  get(self, request):
		data = {
			'deleted': False
		}
		answersR = repo.AnswerRepository(Answers)
		ans_id = request.GET.get('id', None)
		quiz_id = answersR.get_quiz_id(ans_id)
		quiz = repo.QuizRepository(Quiz)
		owner_id = quiz.get_owner_id(quiz_id)
		questions = repo.QuestionRepository(Questions)
		question_id = answersR.get_question_id(ans_id)
		question_type = questions.get_question_type(question_id)
		answer_points = answersR.get_answer_points(ans_id)
		is_done = questions.get_done_status(question_id)

		is_deleted = False
		if request.user.id == owner_id:
			answersR.answer_delete(ans_id)
			is_deleted = True
			data = {
				'deleted': True
		}
		if is_deleted:
			if question_type != 'grammar':
				if is_done == True:
					if answer_points != 0:
						questions.update_is_done(question_id, False)
			else:
				answersRepo = repo.AnswerRepository(Answers)
				answers_count = answersRepo.get_answers_count(question_id)
				if is_done == True and answers_count == 0:
					questions.update_is_done(question_id, False)

		return JsonResponse(data)
示例#2
0
def update_quiz(request, pk, template_name='teachers/update/update_quiz.html'):
	quiz= get_object_or_404(Quiz, pk=pk)
	quizzes = repo.QuizRepository(Quiz)
	owner_id = quizzes.get_owner_id(pk)
	is_active = quizzes.is_active(pk)

	if request.user.id == owner_id and not is_active:
		questions = repo.QuestionRepository(Questions)
		sum_question_points = questions.sum_all_quiz_questions_points(pk)
		cur_quiz_points = quizzes.get_quiz_points(pk)

		form = QuizForm(request.POST or None, instance=quiz)
		if form.is_valid():
			quiz = form.save(commit=False)
			form_points_data = form.cleaned_data["max_points"]
			quiz.max_points = round(form_points_data, 1)
			if_points_changed = round(form_points_data - cur_quiz_points, 1)

			if if_points_changed != 0:
				course_id = quizzes.get_course_id(pk)
				all_q_points = quizzes.get_all_quiz_points(course_id)
				c_points = quizzes.get_course_points(pk)
				free_points = c_points - all_q_points + cur_quiz_points
				free_points = round(free_points, 1)

				if form_points_data > free_points:
					quiz.max_points = cur_quiz_points
					messages.error(request, 'Available course points: %f. '%free_points, extra_tags='alert')
				if sum_question_points > form_points_data:
					quiz.max_points = cur_quiz_points
					messages.error(request, 'Question points in this quiz are: %f. '%sum_question_points, extra_tags='alert')
			quiz.save()
			return HttpResponse(render_to_string('teachers/update/item_edit_form_success.html'))
		return render(request, template_name, {'form':form, 'id': pk, 'sum_questions_points': sum_question_points})
	raise Http404
示例#3
0
def construct_quiz(quiz_id):
	quesrtr = repo.QuestionRepository(Questions)
	ar = repo.AnswerRepository(Answers)

	questions = quesrtr.get_by_quiz_id(quiz_id)
	#questions = list(questions)
	#random.shuffle(questions)
	quiz = {}

	for question in questions:
		temp = {}
		temp[question.id] = {}
		temp[question.id]['qname'] = question.name
		temp[question.id]['qtype'] = question.qtype
		temp[question.id]['answers'] = {}

		if question.qtype != 'open':
			answers = ar.get_answer_points_and_name_by_question(question.id)
			count_true = 0
			answers = list(answers)
			random.shuffle(answers)
			for answer in answers:
				temp[question.id]['answers'][answer.id] = {}
				temp[question.id]['answers'][answer.id]['answer'] = answer.name
				temp[question.id]['answers'][answer.id]['points'] = answer.points
				if answer.correct == True:
					count_true += 1
			temp[question.id]['cor_ans'] = count_true
		quiz.update(temp)				
	return quiz
示例#4
0
def construct_quiz_teacher(quiz_id):
	quesrtr = repo.QuestionRepository(Questions)
	ar = repo.AnswerRepository(Answers)

	questions = quesrtr.get_by_quiz_id(quiz_id)

	quiz = {}

	for question in questions:
		temp = {}
		temp[question.id] = {}
		temp[question.id]['qname'] = question.name
		temp[question.id]['qtype'] = question.qtype
		temp[question.id]['points'] = question.points
		temp[question.id]['description'] = question.description
		temp[question.id]['answers'] = {}

		if question.qtype != 'open':
			answers = ar.get_answer_points_and_name_by_question(question.id)
			for answer in answers:
				temp[question.id]['answers'][answer.id] = {}
				temp[question.id]['answers'][answer.id]['answer'] = answer.name
				temp[question.id]['answers'][answer.id]['points'] = answer.points
				temp[question.id]['answers'][answer.id]['correct'] = answer.correct
		quiz.update(temp)
	return quiz
示例#5
0
def grammar_answers_for_check(quiz_id, stud_id):
	quesrtr = repo.QuestionRepository(Questions)
	grammar_questions = quesrtr.get_grammar_questions(quiz_id)
	sgar = repo.StudentGrammarAnswersRepository(StudentGrammarAnswers)
	gqsr = repo.GrammarQuestionSanctionsRepository(GrammarQuestionSanctions)
	qsrr = repo.QuizSolveRecordRepository(QuizSolveRecord)
	solve_info_id = qsrr.get_solve_info_id(quiz_id, stud_id)
	if grammar_questions:
		for gq in grammar_questions:
			student_answer = sgar.get_stud_grammar_answer_info(solve_info_id, gq['id'])
			if not student_answer:
				gq['exist'] = False
			else:
				
				sanctions = gqsr.form_error_sanction_dict_error_names(gq['id'])
				ethalonts = checkerop.get_etalons(gq['id'])
				
				ethalon = ""
				for eth in ethalonts:
					ethalon += eth['name'] + ". "
				gq['checked_result'] = json.loads(student_answer[0]['check_result'])
				#gq['points'] = gq[0]['points']
				gq['exist'] = True
				gq['stud_answer'] = student_answer[0]['answer']
				gq['corrected_sent'] = student_answer[0]['corrected_sent']
				gq['suggested_points'] = student_answer[0]['points']
				gq['sanctions'] = sanctions
				gq['ethalons'] = ethalon
				print(ethalon)
	return grammar_questions
示例#6
0
def save_checked_answers(request, pk, spk):
	quiz = repo.QuizRepository(Quiz)
	owner_id = quiz.get_owner_id(pk)
	course_id = quiz.get_course_id(pk)
	cpr = repo.CourseParticipantsRepository(CourseParticipants)
	is_participant = cpr.is_user_participant(spk, course_id)

	if request.user.id == owner_id and is_participant:
		new_points = request.POST['data']
		new_points = json.loads(new_points)

		quesrtr = repo.QuestionRepository(Questions)
		soar = repo.StudentOpenAnswersRepository(StudentOpenAnswers)
		qsrr = repo.QuizSolveRecordRepository(QuizSolveRecord)
		sgar = repo.StudentGrammarAnswersRepository(StudentGrammarAnswers)
		solve_info_id = qsrr.get_solve_info_id(pk, spk)

		#new_points[i]['name'] - id
		#new_points[i]['value'] - points
		sum_points = 0
		for i in range(1, len(new_points)):
			question_id = int(new_points[i]['name'])
			question_info = quesrtr.get_open_grammar_question_id_points(pk, question_id)
			if question_info != -1:
				if question_info['qtype'] == 'open':
					points = round(float(new_points[i]['value']), 1)
					open_question_points = float(question_info['points'])
					if points <= open_question_points:
						soar.update_answer_points(solve_info_id, question_id, points)
						sum_points += points
					else:
						soar.update_answer_points(solve_info_id, question_id, open_question_points)
						sum_points += open_question_points					
				else:
					if question_info['qtype'] == 'grammar':
						if isfloat(new_points[i]['value']):
							points = round(float(new_points[i]['value']), 1)
							grammar_points = float(question_info['points'])
							if points <= grammar_points:
								sgar.update_answer_points(solve_info_id, question_id, points)
								sum_points += points
							else:
								sgar.update_answer_points(solve_info_id, question_id, grammar_points)
								sum_points += grammar_points	
						else:
							sgar.update_answer_corrected(solve_info_id, question_id, new_points[i]['value'])


				
		student_points = qsrr.get_points(solve_info_id)
		qsrr.update_quiz_points_and_status(solve_info_id, student_points + sum_points, True)
		return JsonResponse({
			'success': True,
			'url': reverse('teachers:view_quiz_for_check', kwargs={'pk': pk}), #, args=[{'courses': courses}]
			})
	raise Http404
示例#7
0
	def  get(self, request):
		questionR = repo.QuestionRepository(Questions)
		que_id = request.GET.get('id', None)
		owner_id = questionR.get_owner_id(que_id)
		if request.user.id == owner_id:
			questionR.question_delete(que_id)
			data = {
				'deleted': True
			}
			return JsonResponse(data)
示例#8
0
def question_add(request, pk):
	quiz= get_object_or_404(Quiz, pk=pk)
	owner_id = quiz.owner_id
	is_active = quiz.is_active

	if request.user.id == owner_id and not is_active:
		questionR = repo.QuestionRepository(Questions)
		quiz_points = quiz.max_points
		sum_questions_points = questionR.sum_all_quiz_questions_points(pk)

		free_points = quiz_points - sum_questions_points
		free_points = round(free_points, 1)

		if request.method == 'POST':
			can_save = True
			is_grammar = False
			form = QuestionForm(request.POST)
			if form.is_valid():
				question = form.save(commit=False)
				question.quiz_id = pk
				if (form.cleaned_data["qtype"] == 'open'):
					question.done = True 
				cleaned_data_user = form.cleaned_data["points"]
				if free_points >= cleaned_data_user:
					question.points = round(cleaned_data_user, 1) 
					if "spelling-points" in request.POST.keys():
						is_grammar = True
						sp = float(request.POST["spelling-points"])
						gp = float(request.POST["grammar-points"])
						tp = float(request.POST["translate-points"])
						op = float(request.POST["order-points"])
						ep = float(request.POST["ethalon-points"])
						lang = request.POST["lang"]
						langRepo = repo.LanguagesRepository(Languages)
						lang_query = langRepo.get_language(lang)
						if lang_query != -1:
							if sp > cleaned_data_user or gp > cleaned_data_user or tp > cleaned_data_user or op > cleaned_data_user or ep > cleaned_data_user:
								can_save = False
								messages.error(request, 'You cant have points for mistake more that total question points!', extra_tags='alert')
						else:
							can_save = False
					if can_save:
						question.save()
						if is_grammar:
							gsr = repo.GrammarQuestionSanctionsRepository(GrammarQuestionSanctions)
							gsr.add_grammar_sanctions(question.id, sp, gp, tp, op, ep, lang_query[0].id)
						messages.success(request, 'You may now add answers/options to the question.')
						return redirect('/teachers/course/quiz/%d/questions/'%pk)
				else:
					messages.error(request, 'You put more points than you have left. Available points: %f'%free_points, extra_tags='alert')
		else:
			form = QuestionForm()
		return render(request, 'teachers/add/question_add.html', {'form': form, 'free_points': free_points, 'quiz_id': quiz.id})
	raise Http404
示例#9
0
def view_question_info(request, pk, template_name='teachers/info/question_info.html'):
	#question= get_object_or_404(Questions, pk=pk)
	questionR = repo.QuestionRepository(Questions)
	owner_id = questionR.get_owner_id(pk)
	questions = questionR.get_by_id(pk)
	grammar_points = []
	if questions[0].qtype == 'grammar':
		grammar_points = questionR.get_grammar_points(pk)
	if request.user.id == owner_id:
		return render(request, template_name, {'id': pk, 'questions': questions, 'grammar_points': grammar_points})
	raise Http404
示例#10
0
	def  get(self, request):
		quizR = repo.QuizRepository(Quiz)
		questionR = repo.QuestionRepository(Questions)
		quiz_id = request.GET.get('id', None)
		owner_id = quizR.get_owner_id(quiz_id)
		if request.user.id == owner_id:
			quizR.update_is_active(quiz_id, False)
			messages.success(request, 'Success!')
			data = {
				'deactivated': True
			}
			return JsonResponse(data)
示例#11
0
def add_answer(request, qpk):
	# request should be ajax and method should be POST.
	if request.is_ajax and request.method == "POST":
		# get the form data
		form = AnswerForm(request.POST)
		# save the data and after fetch the object in instance
		if form.is_valid():

			instance = form.save(commit=False)
			answers = repo.AnswerRepository(Answers)
			sum_answers_points = answers.sum_all_question_answers_points(qpk)
			questions = repo.QuestionRepository(Questions)
			question_type = questions.get_question_type(qpk)

			if question_type != 'grammar':
				question_points = questions.get_question_points(qpk)
				form_points_data = form.cleaned_data["points"]
				instance.points = round(form_points_data, 1)
				free_points = question_points - sum_answers_points
				free_ponts = round(free_points, 1)
				instance.question_id = qpk

				left_points = round(free_points - form_points_data, 1)
				instance.points = round(form_points_data, 1)
				if form_points_data < free_points or left_points == 0.0:
					instance.save()
					messages.success(request, 'Success!')
				else:
					instance.points = 0
					instance.save()
					messages.error(request, 'You put more points than you have left. Available points: %f'%free_points)
				# serialize in new friend object in json
				ser_instance = serializers.serialize('json', [ instance, ])

				if left_points == 0:
					questions.update_is_done(qpk, True)
			else:
				instance.points = 0
				instance.question_id = qpk
				instance.save()
				questions.update_is_done(qpk, True)
				messages.success(request, 'Success!')
				ser_instance = serializers.serialize('json', [ instance, ])


			# send to client side.
			return JsonResponse({"instance": ser_instance}, status=200)
		else:
			# some form errors occured.
			return JsonResponse({"error": form.errors}, status=400)

	# some error occured
	return JsonResponse({"error": ""}, status=400)
示例#12
0
def view_quiz_questions(request, pk):
	questionsR = repo.QuestionRepository(Questions)
	questions = questionsR.get_by_quiz_id(pk)
	quiz = repo.QuizRepository(Quiz)
	quizzes = quiz.get_by_id(pk)
	course_id = quiz.get_course_id(pk)
	if quizzes:
		owner_id = quizzes[0].owner_id
	else:
		owner_id = 0

	if request.user.id == owner_id:
		return render(request, 'teachers/lists/questions_list.html', {'questions': questions, 'quiz': pk, 'quizzes': quizzes, 'quiz_is_active': quizzes[0].is_active, 'course_id': course_id})
	raise Http404
示例#13
0
def check_student_grammar_answer(question_id, stud_answer, question_sanctions, grammarChecker):
	error_struct_result = ""
	ethalonts = checkerop.get_etalons(question_id)
	error_struct_result, _ , corrected_sent = grammarChecker.process_checking(ethalonts, stud_answer)
	points_sanctions = calculate_grammar_question_points(error_struct_result, question_sanctions)
	qr = repo.QuestionRepository(Questions)
	#print("\n\n\nSANCTIONS: ", points_sanctions)
	question_points = qr.get_question_points(question_id)
	points_for_question = question_points - points_sanctions
	if points_for_question < 0:
		points_for_question = 0
	points_for_question = round(points_for_question, 2)
	error_struct_result = json.dumps(error_struct_result)
	#print("nSANCTIONS", corrected_sent)
	return error_struct_result, corrected_sent, points_for_question
示例#14
0
def open_answers_for_check(quiz_id, stud_id):
	quesrtr = repo.QuestionRepository(Questions)
	open_questions = quesrtr.get_open_questions(quiz_id)
	soar = repo.StudentOpenAnswersRepository(StudentOpenAnswers)

	qsrr = repo.QuizSolveRecordRepository(QuizSolveRecord)
	solve_info_id = qsrr.get_solve_info_id(quiz_id, stud_id)
	if open_questions:
		for oq in open_questions:
			student_answer = soar.get_stud_open_answer_text(solve_info_id, oq['id'])
			if not student_answer:
				oq['exist'] = False
			else:
				oq['exist'] = True
				oq['stud_answer'] = student_answer[0]['answer']
	return open_questions
示例#15
0
def update_answer(request, pk, template_name='teachers/update/item_edit_form.html'):
	answer= get_object_or_404(Answers, pk=pk)
	answersR = repo.AnswerRepository(Answers)
	quiz_id = answersR.get_quiz_id(pk)
	quiz = repo.QuizRepository(Quiz)
	owner_id = quiz.get_owner_id(quiz_id)

	if request.user.id == owner_id:
		form = AnswerForm(request.POST or None, instance=answer)

		if form.is_valid():	
			instance = form.save(commit=False)
			form_points_data = form.cleaned_data["points"]
			answer_points = answersR.get_answer_points(pk)

			are_points_changed = round(answer_points - form_points_data, 1)
			if are_points_changed != 0:
				questions = repo.QuestionRepository(Questions)
				question_id = answersR.get_question_id(pk)
				sum_answers_points = answersR.sum_all_question_answers_points(question_id)
				question_points = answersR.get_question_points(question_id)
				answer_points = answersR.get_answer_points(pk)
				free_points = question_points - sum_answers_points + answer_points
				free_points = round(free_points, 1)

				instance.points =  round(form_points_data, 1)
				is_done = questions.get_done_status(question_id)

				difference = round(free_points - form_points_data, 1)
				
				if difference >= 0:
					if(difference == 0):
						if is_done == False: 
							questions.update_is_done(question_id, True)
					else:
						if is_done == True:
							questions.update_is_done(question_id, False)
					messages.success(request, 'Success!')
				else:
					instance.points = answer_points
					messages.error(request, 'You put more points than you have left. Available points: %f'%free_points)
			instance.save()
			return HttpResponse(render_to_string('teachers/update/item_edit_form_success.html'))
		return render(request, template_name, {'form':form, 'id': pk})
	raise Http404
示例#16
0
def activate_quiz(request, pk, template_name='teachers/activate/activate_quiz.html'):
	quiz= get_object_or_404(Quiz, pk=pk)
	quizR = repo.QuizRepository(Quiz)
	#owner_id = quizR.get_owner_id(pk)
	owner_id = quiz.owner_id
	
	if request.user.id == owner_id:
		is_course_active = quizR.is_course_active(pk)
		form = QuizActivateForm(request.POST or None, instance=quiz)
		if is_course_active:
			questionR = repo.QuestionRepository(Questions)
			is_quiz_done = questionR.is_quiz_done(pk)
			sum_questions_points = questionR.sum_all_quiz_questions_points(pk)
			quiz_points = quizR.get_quiz_points(pk)
			is_active = quizR.is_active(pk)
			
			if form.is_valid():
				quiz = form.save(commit=False)
				check = check_grades(form.cleaned_data["max_points"], form.cleaned_data["good_points"], form.cleaned_data["min_points"])
				if check:
					if(sum_questions_points == quiz_points):
						if is_quiz_done:
							quiz.in_code = generate_code()
							quiz.save()
							quizR.update_is_active(pk, not is_active)
							messages.success(request, 'Success!')
							
						else:
							messages.error(request, 'You have question that dont have enough answers')
					else:
						messages.error(request, 'Sum of quiz queston is not equal quiz points')
					
				else:
					messages.error(request, 'Put points in the right order')
				return HttpResponse(render_to_string('teachers/update/item_edit_form_success.html'))
			return render(request, template_name, {'form':form, 'id': pk})
		else:
			messages.error(request, 'Please activate course first.')
			return HttpResponse(render_to_string('teachers/update/item_edit_form_success.html'))
	else:
		raise Http404
示例#17
0
def construct_main(quiz_id):
	quesrtr = repo.QuestionRepository(Questions)
	ar = repo.AnswerRepository(Answers)

	questions = quesrtr.get_id_and_type(quiz_id)

	quiz = {}

	for question in questions:
		temp = {}
		temp[question.id] = {}
		temp[question.id]['qtype'] = question.qtype
		temp[question.id]['answers'] = {}

		if question.qtype == 'multiple' or  question.qtype == 'single':
			answers = ar.get_answer_points_by_question(question.id)
			for answer in answers:
				temp[question.id]['answers'][answer.id] = answer.points
			
		quiz.update(temp)
	return quiz  
示例#18
0
def AnswersView(request, qpk):
	form = AnswerForm()

	questions = repo.QuestionRepository(Questions)
	question = questions.get_by_id(qpk)
	owner_id = questions.get_owner_id(qpk)

	if question:
		qtype = question[0].qtype
	else:
		qtype = "NONE"

	grammar_points = []
	if question[0].qtype == 'grammar':
		grammar_points = questions.get_grammar_points(qpk)	
		
	if request.user.id == owner_id and qtype != 'open':
		answersR = repo.AnswerRepository(Answers)
		answers = answersR.get_by_id_ordered(qpk)
		quiz_is_active = questions.get_quiz_status(qpk)
		quiz_id = questions.get_quiz_id(qpk)
		return render(request, "teachers/lists/answers_list.html", {"form": form, "answers": answers, "question_id": qpk, "question": question, 'quiz_is_active': quiz_is_active, 'quiz_id': quiz_id, 'qtype': qtype, 'grammar_points': grammar_points})
	raise Http404
示例#19
0
def update_question(request, pk, template_name='teachers/update/update_question.html'):
	question= get_object_or_404(Questions, pk=pk)
	questions = repo.QuestionRepository(Questions)
	owner_id = questions.get_owner_id(pk)
	is_actve = questions.get_quiz_status(pk)

	if request.user.id == owner_id and not is_actve:
		lr = repo.LanguagesRepository(Languages)
		languages = get_lang_options_for_question(lr, pk)
		cur_question_points = questions.get_question_points(pk)
		answers = repo.AnswerRepository(Answers)
		sum_answers_points, exist = answers.sum_all_question_answers_points_if_exist(pk)
	
		question_ = questions.get_by_id(pk)
		if question_:
			qtype = question_[0].qtype
		else:
			qtype = "NONE"

		grammar_points = []
		if question_[0].qtype == 'grammar':
			grammar_points = questions.get_grammar_points(pk)

		form = QuestionForm(request.POST or None, instance=question)
		if form.is_valid():
			qtype = questions.get_question_type(pk)
			update_status = -1
			question = form.save(commit=False)

			form_points_data = form.cleaned_data["points"]
			if_points_changed = round(form_points_data - cur_question_points, 1)

			if if_points_changed != 0:
				same_points = False
				question.points = round(form_points_data, 1)
				quiz_id = questions.get_quiz_id(pk)
				sum_quiz_questions = questions.sum_all_quiz_questions_points(quiz_id)
				quiz_points = questions.get_quiz_points(pk)
				aval_points = quiz_points - sum_quiz_questions + cur_question_points
				aval_points = round(aval_points, 1)

				if (form_points_data > aval_points):
					question.points = cur_question_points
					same_points = True
					messages.error(request, 'Available course points: %f. '%aval_points)
				if (form_points_data < sum_answers_points):
					question.points = cur_question_points
					messages.error(request, 'Answer points in this question are: %f. '%sum_answers_points)
				is_done = questions.get_done_status(pk)
				
				if form_points_data > sum_answers_points and not same_points:
					if is_done == True and qtype != 'grammar':
						update_status = 0
						#questions.update_is_done(pk, False)
				else:
					if is_done == False and form_points_data == sum_answers_points:
						update_status = 1
						#questions.update_is_done(pk, True)
			
			update_type = form.cleaned_data["qtype"]
			if update_type == 'open' or update_type == 'compare' or update_type == 'grammar':
				if qtype != 'open' and qtype != 'compare':
					if not exist:
						update_status = 1
					else:
						question.qtype = qtype
						update_status = -1
						#messages.error(request, 'Can not change type of the question to open or compare. There are answers in this question!')
				
				if update_type == 'compare':
					if not exist:
						update_status = 0
				else:
					if update_type == 'open':
						if not exist:
							update_status = 1
						else:
							question.qtype = qtype
							update_status = -1
							messages.error(request, 'Can not change type of the question to open. There are answers in this question!')
				if update_type == 'grammar' and qtype != 'grammar':
					question.qtype = qtype
			else:
				if qtype == 'open' or qtype == 'compare':
					if not exist:
						if update_status == -1:
							update_status = -1
						else:
							update_status = 0 
					if qtype == 'open' and update_type != 'open':
						update_status = 0 
				else:
					if qtype == 'grammar':
						update_status = 1

			question.save()	
			if update_status == 1 or qtype == 'grammar':
				gramm_update_status = 1
				if qtype == 'grammar' and update_type != 'grammar':
					gqsr = repo.GrammarQuestionSanctionsRepository(GrammarQuestionSanctions)
					gqsr.delete_sanctions(pk)
					if update_type == 'open':
						questions.update_is_done(pk, True)
					else:
						questions.update_is_done(pk, False)
					gramm_update_status = 0
				else:
					if update_type == 'grammar' and qtype == 'grammar':
						lang_id = lr.get_id_by_abr(request.POST["lang"])
						if lang_id != -1:
							gqsr = repo.GrammarQuestionSanctionsRepository(GrammarQuestionSanctions)
							gqsr.update_sanctions(pk, request.POST["spelling_points"], request.POST["grammar_points"], request.POST["translate_points"], request.POST["order_points"], request.POST["ethalon_points"], lang_id)
							gramm_update_status = 0
					else:
						if update_type == 'grammar' and qtype != 'grammar':
							gramm_update_status = 0
							messages.error(request, 'Can not change type of the question to grammar!')
				if gramm_update_status:
					questions.update_is_done(pk, True)
		
			else:
				if update_status == 0:
					questions.update_is_done(pk, False)
			
			return HttpResponse(render_to_string('teachers/update/item_edit_form_success.html'))
		return render(request, template_name, {'form':form, 'id': pk, 'sum_answers': sum_answers_points, 'mistake_points': grammar_points, 'qtype': qtype, 'languages': languages})
	raise Http404
示例#20
0
def construct_quiz_student_results(quiz_id, student_id):

	qsrr = repo.QuizSolveRecordRepository(QuizSolveRecord)
	solve_info_id = qsrr.get_solve_info_id(quiz_id, student_id)

	if solve_info_id != 0:
		sar = repo.StudentAnswersRepository(StudentAnswers)
		stud_answers = sar.get_student_answers(solve_info_id)
		quesrtr = repo.QuestionRepository(Questions)
		ar = repo.AnswerRepository(Answers)
		answers_id = [ sub['answer_id'] for sub in stud_answers ] 
		
		questions = quesrtr.get_by_quiz_id(quiz_id)

		soar = repo.StudentOpenAnswersRepository(StudentOpenAnswers)
		sgar = repo.StudentGrammarAnswersRepository(StudentGrammarAnswers)
		quiz = {}

		for question in questions:
			temp = {}
			temp[question.id] = {}
			temp[question.id]['qname'] = question.name
			temp[question.id]['qtype'] = question.qtype
			temp[question.id]['points'] = question.points
			temp[question.id]['description'] = question.description
			temp[question.id]['answers'] = {}


			if question.qtype != 'open' and question.qtype != 'compare' and question.qtype != 'grammar':
				answers = ar.get_answer_points_and_name_by_question(question.id)
				for answer in answers:
					temp[question.id]['answers'][answer.id] = {}
					temp[question.id]['answers'][answer.id]['answer'] = answer.name
					temp[question.id]['answers'][answer.id]['points'] = answer.points
					temp[question.id]['answers'][answer.id]['correct'] = answer.correct
					if answer.id in answers_id:
						temp[question.id]['answers'][answer.id]['is_answer'] = True
					else:
						temp[question.id]['answers'][answer.id]['is_answer'] = False
			else:
				if question.qtype != 'grammar':
					open_student_answers = soar.get_student_answers(solve_info_id, question.id)
					temp[question.id]['answers']['answer'] = ""
					temp[question.id]['answers']['points'] = 0
					if open_student_answers != -1:
						temp[question.id]['answers']['answer'] = open_student_answers['answer']
						temp[question.id]['answers']['points'] = open_student_answers['points']
				else:
					open_student_answers = sgar.get_student_answers(solve_info_id, question.id)
					temp[question.id]['answers']['answer'] = ""
					temp[question.id]['answers']['points'] = 0
					if open_student_answers != -1:
						temp[question.id]['answers']['answer'] = open_student_answers['answer']
						temp[question.id]['answers']['points'] = open_student_answers['points']
						temp[question.id]['answers']['result'] =  json.loads(open_student_answers['check_result'])
						temp[question.id]['answers']['corrected_sents'] =  open_student_answers['corrected_sent']
								

			quiz.update(temp)
		return quiz
	else:
		return -1