コード例 #1
0
ファイル: views.py プロジェクト: TkhiienLok/my-quiz-site
 def get(self, request, *args, **kwargs):
     quiz = get_object_or_404(Quiz, slug__iexact=kwargs.get("slug"))
     has_rights_to_edit = self.request.user.is_authenticated and (
         quiz.author.user == self.request.user
         or self.request.user.is_superuser)
     try:
         score = quiz.score_set.get(student=self.request.user, quiz=quiz)
         questions = quiz.question_set.all()
         correct_answers = ",".join(score.get_correct_answers)
         context = {
             'quiz': quiz,
             'score': score,
             'questions': questions,
             'correct_answers_string': correct_answers,
             'has_rights_to_edit': has_rights_to_edit,
         }
         return render(request, 'quiz/quiz_score.html', context)
     except Score.DoesNotExist:
         form_list = quiz_forms(quiz)
         context = {
             'form_list': form_list,
             'quiz': quiz,
             'has_rights_to_edit': has_rights_to_edit,
         }
         return render(request, 'quiz/quiz_detail.html', context)
コード例 #2
0
ファイル: views.py プロジェクト: TimGebhardt/django-quiz
def quiz_detail(request, slug):
	quiz = get_object_or_404(Quiz, slug__iexact=slug)
	try:
		score = quiz.score_set.get(student=request.user, quiz=quiz)
		questions = quiz.question_set.all()
		return render_to_response('quiz/quiz_score.html', { 'quiz': quiz, 'score': score, 'questions': questions })
	except Score.DoesNotExist:
		form_list = quiz_forms(quiz)
		return render_to_response('quiz/quiz_detail.html', { 'form_list': form_list, 'quiz': quiz }, context_instance=RequestContext(request))
コード例 #3
0
ファイル: views.py プロジェクト: nashrafeeg/django-quiz
def quiz_detail(request, slug):
    quiz = get_object_or_404(Quiz, slug__iexact=slug)
    try:
        score = quiz.score_set.get(student=request.user, quiz=quiz)
        questions = quiz.question_set.all()
        corrent_anwser = score.corrent_anwsers
        return render_to_response(
            "quiz/quiz_score.html",
            {"quiz": quiz, "score": score, "questions": questions, "corrent_anwser": corrent_anwser},
        )
    except Score.DoesNotExist:
        form_list = quiz_forms(quiz)
        return render_to_response(
            "quiz/quiz_detail.html", {"form_list": form_list, "quiz": quiz}, context_instance=RequestContext(request)
        )
コード例 #4
0
ファイル: views.py プロジェクト: openman/django-quiz
def process_quiz(request, slug):
	quiz = get_object_or_404(Quiz, slug__iexact=slug)
	
	if request.method == 'POST':
		form_list = quiz_forms(quiz, request.POST)
		score = Score()
		score.student = request.user
		score.quiz = quiz
		score.save()
		
		for form in form_list:
			if form.is_correct():
				score.corrent_anwsers = form.question
				score.save()
		
		return HttpResponseRedirect(score.get_absolute_url())
	
	return HttpResponseRedirect(quiz.get_absolute_url())
コード例 #5
0
def process_quiz(request, slug):
    quiz = get_object_or_404(Quiz, slug__iexact=slug)

    if request.method == 'POST':
        form_list = quiz_forms(quiz, request.POST)
        score = Score()
        score.student = request.user
        score.quiz = quiz
        score.save()

        for form in form_list:
            if form.is_correct():
                score.corrent_anwsers = form.question
                score.save()

        return HttpResponseRedirect(score.get_absolute_url())

    return HttpResponseRedirect(quiz.get_absolute_url())
コード例 #6
0
def quiz_detail(request, slug):
    quiz = get_object_or_404(Quiz, slug__iexact=slug)
    try:
        score = quiz.score_set.get(student=request.user, quiz=quiz)
        questions = quiz.question_set.all()
        corrent_anwser = score.corrent_anwsers
        return render_to_response(
            'quiz/quiz_score.html', {
                'quiz': quiz,
                'score': score,
                'questions': questions,
                'corrent_anwser': corrent_anwser
            })
    except Score.DoesNotExist:
        form_list = quiz_forms(quiz)
        return render_to_response('quiz/quiz_detail.html', {
            'form_list': form_list,
            'quiz': quiz
        },
                                  context_instance=RequestContext(request))