From f405016f9670c51194673f7c627a5353eeb66e9d Mon Sep 17 00:00:00 2001 From: nik8 Date: Wed, 9 Apr 2025 14:22:46 +0200 Subject: [PATCH 1/3] zwischenstand --- django/library/forms.py | 2 +- .../0033_qivipquestion_time_per_question.py | 18 ++++++++++++++++++ ...34_alter_qivipquestion_time_per_question.py | 18 ++++++++++++++++++ ...35_alter_qivipquestion_time_per_question.py | 18 ++++++++++++++++++ django/library/models.py | 15 ++++++++++++++- .../question/question_multiple_choice.html | 1 - 6 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 django/library/migrations/0033_qivipquestion_time_per_question.py create mode 100644 django/library/migrations/0034_alter_qivipquestion_time_per_question.py create mode 100644 django/library/migrations/0035_alter_qivipquestion_time_per_question.py diff --git a/django/library/forms.py b/django/library/forms.py index c454b71..b5ab887 100644 --- a/django/library/forms.py +++ b/django/library/forms.py @@ -9,7 +9,7 @@ class QuizForm(forms.ModelForm): 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 ceb2eb5..db3acba 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 ...": @@ -48,12 +51,22 @@ class QivipQuiz(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/templates/library/question/question_multiple_choice.html b/django/templates/library/question/question_multiple_choice.html index 40eb00a..4b0587c 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 -
{% csrf_token %} From 77714d22a9c0a7893b00f9f991f68a0c90e6c2cc Mon Sep 17 00:00:00 2001 From: ben8 Date: Thu, 10 Apr 2025 14:43:43 +0200 Subject: [PATCH 2/3] Zeit_bisher_im_Backend #76 --- django/library/forms.py | 2 +- django/play/views.py | 2 ++ django/templates/play/game/question_host.html | 2 +- django/templates/play/game/question_participant.html | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/django/library/forms.py b/django/library/forms.py index b5ab887..1a5ad63 100644 --- a/django/library/forms.py +++ b/django/library/forms.py @@ -9,7 +9,7 @@ class QuizForm(forms.ModelForm): class QuestionForm(forms.ModelForm): class Meta: model = QivipQuestion - fields = ['quiz_id', 'data', 'time_per_question'] + fields = ['quiz_id', 'data','time_per_question'] from django import forms diff --git a/django/play/views.py b/django/play/views.py index 6887cc0..82991d6 100644 --- a/django/play/views.py +++ b/django/play/views.py @@ -210,6 +210,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, @@ -229,6 +230,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/play/game/question_host.html b/django/templates/play/game/question_host.html index 7a4f17c..84f1d7f 100644 --- a/django/templates/play/game/question_host.html +++ b/django/templates/play/game/question_host.html @@ -35,7 +35,7 @@ const joinCode = '{{ quiz_game.join_code }}'; const hostId = '{{ host_id }}'; const questionStartTime = {{ start_time }}; - const questionDuration = 30000; // 30 seconds in milliseconds + const questionDuration = '{{ current_question.time_per_question }}'*1000; //Zeit pro Frage (indviduell eingestellt) const gameSocket = initializeGameSocket(joinCode); let answeredParticipants = 0; let totalParticipants = 0; diff --git a/django/templates/play/game/question_participant.html b/django/templates/play/game/question_participant.html index 2caf10d..2800f35 100644 --- a/django/templates/play/game/question_participant.html +++ b/django/templates/play/game/question_participant.html @@ -37,7 +37,7 @@ const joinCode = '{{ quiz_game.join_code }}'; const participantId = '{{ participant.participant_id }}'; const questionStartTime = {{ start_time }}; - const questionDuration = 30000; // 30 seconds in milliseconds + const questionDuration = '{{ current_question.time_per_question }}'*1000; //Zeit pro Frage (indviduell eingestellt) const gameSocket = initializeGameSocket(joinCode); gameSocket.onmessage = function(e) { From e269264f031c8b85e992e6d9d32a57682aea189b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhn-Vitus=20Sa=C3=9F?= Date: Fri, 18 Apr 2025 12:05:50 +0200 Subject: [PATCH 3/3] Front End einbindung von Zeitauswahl --- django/library/forms.py | 2 +- django/library/models.py | 2 +- django/library/views.py | 10 ++++++++-- .../library/question/question_multiple_choice.html | 13 +++++++++++++ .../library/question/question_true_false.html | 13 +++++++++++++ 5 files changed, 36 insertions(+), 4 deletions(-) diff --git a/django/library/forms.py b/django/library/forms.py index 1a5ad63..b0a75de 100644 --- a/django/library/forms.py +++ b/django/library/forms.py @@ -4,7 +4,7 @@ from .models import QivipQuiz, QivipQuestion class QuizForm(forms.ModelForm): class Meta: model = QivipQuiz - fields = ['name', 'description','image', 'status', 'category', 'tags',"difficulty","credits"] + fields = ['name', 'description','image', 'status', 'category', 'tags','difficulty','credits'] class QuestionForm(forms.ModelForm): class Meta: diff --git a/django/library/models.py b/django/library/models.py index db3acba..8f0c8eb 100644 --- a/django/library/models.py +++ b/django/library/models.py @@ -66,7 +66,7 @@ class QivipQuestion(models.Model): 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") + 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 5f16d54..83c209f 100644 --- a/django/library/views.py +++ b/django/library/views.py @@ -283,6 +283,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) @@ -297,6 +298,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, @@ -306,12 +308,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) @@ -412,6 +416,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) @@ -421,7 +426,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/templates/library/question/question_multiple_choice.html b/django/templates/library/question/question_multiple_choice.html index 4b0587c..7a9c0d4 100644 --- a/django/templates/library/question/question_multiple_choice.html +++ b/django/templates/library/question/question_multiple_choice.html @@ -91,6 +91,19 @@
+
+ + +
+
diff --git a/django/templates/library/question/question_true_false.html b/django/templates/library/question/question_true_false.html index d5ce70d..8c8bd84 100644 --- a/django/templates/library/question/question_true_false.html +++ b/django/templates/library/question/question_true_false.html @@ -43,6 +43,19 @@
+
+ + +
+