diff --git a/django/library/views.py b/django/library/views.py index bd314ae..e05de20 100644 --- a/django/library/views.py +++ b/django/library/views.py @@ -130,16 +130,17 @@ def delete_quiz(request, pk): def detail_quiz(request, pk): #quiz = get_object_or_404(QivipQuiz, pk=pk, user_id=request.user) quiz = get_object_or_404(QivipQuiz, pk=pk) + show_answers = request.GET.get('show_answers', 'false').lower() == 'true' questions = QivipQuestion.objects.filter(quiz_id=quiz) - # Parse JSON data for each question for question in questions: if question.data: question.data = json.loads(question.data) - + context = { 'quiz': quiz, - 'questions': questions + 'questions': questions, + 'detail':show_answers, } return render(request, 'library/detail_quiz.html', context) """ diff --git a/django/templates/library/detail_quiz.html b/django/templates/library/detail_quiz.html index 9120802..b137cee 100644 --- a/django/templates/library/detail_quiz.html +++ b/django/templates/library/detail_quiz.html @@ -2,7 +2,6 @@ {% block content %} -

{{ quiz.name }}

@@ -28,7 +27,33 @@ {% if quiz.description %}

{{ quiz.description }}

{% endif %} +
+ {% if detail == True %} + +
+ + + +   Antworten verstecken +
+ +
+{% else %} + + +
+ + + + +   Antworten anzeigen +
+ +
+ +{% endif %} +
@@ -69,34 +94,41 @@
+ {% if detail %} + {% if question.data.type == 'multiple_choice' %} -
    - {% for option in question.data.options %} -
  • - {% if option.is_correct %} - - - - {{ option.value }} - {% else %} - - - - {{ option.value }} - {% endif %} -
  • - {% endfor %} -
- {% else %} - {% for option in question.data.options %} - {% if option.is_correct %} -

- Richtige Antwort: - {{ option.value }} -

- {% endif %} - {% endfor %} +
    + {% for option in question.data.options %} +
  • + {% if option.is_correct %} + + + + {{ option.value }} + {% else %} + + + + {{ option.value }} + {% endif %} +
  • + {% endfor %} +
+ {% else %} + {% for option in question.data.options %} + {% if option.is_correct %} +

+ Richtige Antwort: + {{ option.value }} +

{% endif %} + {% endfor %} + + {% endif %} + + + {% endif %} +