diff --git a/django/library/forms.py b/django/library/forms.py index 958ae7b..7cb8773 100644 --- a/django/library/forms.py +++ b/django/library/forms.py @@ -4,12 +4,12 @@ from .models import QivipQuiz, QivipQuestion class QuizForm(forms.ModelForm): class Meta: model = QivipQuiz - fields = ['name', 'description','image', 'status', 'category', "difficulty","credits"] + fields = ['name', 'description','image', 'status', 'category','difficulty','credits'] class QuestionForm(forms.ModelForm): class Meta: model = QivipQuestion - fields = ['quiz_id', 'data'] + fields = ['quiz_id', 'data','time_per_question'] from django import forms diff --git a/django/library/migrations/0033_qivipquestion_time_per_question.py b/django/library/migrations/0033_qivipquestion_time_per_question.py new file mode 100644 index 0000000..fd5a7a1 --- /dev/null +++ b/django/library/migrations/0033_qivipquestion_time_per_question.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.7 on 2025-04-08 14:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('library', '0032_qivipquiz_average_rating_qivipquiz_rating_count_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='qivipquestion', + name='time_per_question', + field=models.CharField(choices=[('10', 10), ('15', 15), ('30', 30), ('60', 60), ('90', 90), ('120', 120), ('180', 180), ('nicht gesetzt', 'nicht gesetzt')], default=30, help_text='Zeit pro Frage in Sekunden', max_length=13), + ), + ] diff --git a/django/library/migrations/0034_alter_qivipquestion_time_per_question.py b/django/library/migrations/0034_alter_qivipquestion_time_per_question.py new file mode 100644 index 0000000..3c50abb --- /dev/null +++ b/django/library/migrations/0034_alter_qivipquestion_time_per_question.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.7 on 2025-04-08 14:19 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('library', '0033_qivipquestion_time_per_question'), + ] + + operations = [ + migrations.AlterField( + model_name='qivipquestion', + name='time_per_question', + field=models.CharField(choices=[('10', 10), ('15', 15), ('30', 30), ('60', 60), ('90', 90), ('120', 120), ('180', 180)], default=30, help_text='Zeit pro Frage in Sekunden', max_length=13), + ), + ] diff --git a/django/library/migrations/0035_alter_qivipquestion_time_per_question.py b/django/library/migrations/0035_alter_qivipquestion_time_per_question.py new file mode 100644 index 0000000..b8825eb --- /dev/null +++ b/django/library/migrations/0035_alter_qivipquestion_time_per_question.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.7 on 2025-04-08 14:21 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('library', '0034_alter_qivipquestion_time_per_question'), + ] + + operations = [ + migrations.AlterField( + model_name='qivipquestion', + name='time_per_question', + field=models.CharField(choices=[('10', 10), ('15', 15), ('30', 30), ('60', 60), ('90', 90), ('120', 120), ('180', 180)], default=30, help_text='Zeit pro Frage in Sekunden', max_length=3), + ), + ] diff --git a/django/library/models.py b/django/library/models.py index 1477a3d..8c1da34 100644 --- a/django/library/models.py +++ b/django/library/models.py @@ -19,6 +19,9 @@ class QivipQuiz(models.Model): "nicht gesetzt":"nicht gesetzt", } + + + def validate_description(value): if value.strip() == "In dem Quiz geht es um ...": @@ -55,12 +58,22 @@ class QivipQuizFavorite(models.Model): # Create your models here. class QivipQuestion(models.Model): + + TIME_VALUES = { + "10": 10, + "15": 15, + "30": 30, + "60": 60, + "90": 90, + "120": 120, + "180": 180, + } uuid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True) quiz_id = models.ForeignKey(QivipQuiz, on_delete=models.CASCADE, related_name='questions') creation_date = models.DateTimeField(auto_now_add=True) update_date = models.DateTimeField(auto_now=True) data = models.TextField() - + time_per_question = models.CharField(max_length=3, choices=list(TIME_VALUES.items()), default=30, help_text="Zeit pro Frage in Sekunden") def __str__(self): return self.data[:50] diff --git a/django/library/views.py b/django/library/views.py index 8c9eccb..c770750 100644 --- a/django/library/views.py +++ b/django/library/views.py @@ -387,6 +387,7 @@ def new_question(request): question = QivipQuestion() question.data = json.dumps(json_data) question.quiz_id = quiz + question.time_per_question = request.POST.get('time_per_question', '30') question.save() #return modified(request, pk=quiz.pk) return redirect('library:detail_quiz', pk=quiz.pk) @@ -401,6 +402,7 @@ def new_question(request): {'value': 'Falsch', 'is_correct': False} ] } + standard_time_per_question = 30 elif question_type == 'multiple_choice': question_data = { 'type': question_type, @@ -410,12 +412,14 @@ def new_question(request): {'value': '', 'is_correct': False} ] } + standard_time_per_question = 30 template_name = f'library/question/question_{question_type}.html' context = { 'question': question_data, 'quiz_id': quiz_id, - 'quiz': quiz + 'quiz': quiz, + 'standard_time_per_question': standard_time_per_question, } return render(request, template_name, context) @@ -516,6 +520,7 @@ def edit_question(request, pk): } question.data = json.dumps(json_data) + question.time_per_question = request.POST.get('time_per_question', '30') question.save() #return modified(request, question.quiz_id.pk) return redirect('library:detail_quiz', pk=question.quiz_id.pk) @@ -525,7 +530,8 @@ def edit_question(request, pk): context = { 'question': {'data': question_data}, # Wrap in data structure expected by template 'quiz_id': question.quiz_id.pk, - 'quiz': question.quiz_id + 'quiz': question.quiz_id, + 'time_per_question': question.time_per_question, } return render(request, template_name, context) diff --git a/django/play/views.py b/django/play/views.py index 296ed6f..ab6488e 100644 --- a/django/play/views.py +++ b/django/play/views.py @@ -243,6 +243,7 @@ def question(request, join_code): return render(request, 'play/game/question_host.html', { 'quiz_game': quiz_game, 'question_data': question_data, + 'current_question':current_question, 'host_id': quiz_game.host_id, 'start_time': int(quiz_game.question_start_time.timestamp() * 1000), 'question_index': quiz_game.current_question_index, @@ -265,6 +266,7 @@ def question(request, join_code): return render(request, 'play/game/question_participant.html', { 'quiz_game': quiz_game, 'question_data': question_data, + 'current_question':current_question, 'participant': participant, 'start_time': int(quiz_game.question_start_time.timestamp() * 1000), 'question_index': quiz_game.current_question_index, diff --git a/django/templates/library/question/question_multiple_choice.html b/django/templates/library/question/question_multiple_choice.html index 40eb00a..7a9c0d4 100644 --- a/django/templates/library/question/question_multiple_choice.html +++ b/django/templates/library/question/question_multiple_choice.html @@ -9,7 +9,6 @@ Zurück zum Quiz -