diff --git a/django/core/settings.py b/django/core/settings.py index 162b0f8..10c7c97 100644 --- a/django/core/settings.py +++ b/django/core/settings.py @@ -43,6 +43,7 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'channels', + 'django_cleanup', ] MIDDLEWARE = [ diff --git a/django/library/migrations/0047_merge_20250418_1334.py b/django/library/migrations/0047_merge_20250418_1334.py new file mode 100644 index 0000000..7419abf --- /dev/null +++ b/django/library/migrations/0047_merge_20250418_1334.py @@ -0,0 +1,14 @@ +# Generated by Django 5.1.7 on 2025-04-18 11:34 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('library', '0035_alter_qivipquestion_time_per_question'), + ('library', '0046_alter_qivipquizfavorite_favorite_date'), + ] + + operations = [ + ] diff --git a/django/library/migrations/0048_qivipquestion_image.py b/django/library/migrations/0048_qivipquestion_image.py new file mode 100644 index 0000000..85a5c57 --- /dev/null +++ b/django/library/migrations/0048_qivipquestion_image.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.7 on 2025-04-18 11:34 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('library', '0047_merge_20250418_1334'), + ] + + operations = [ + migrations.AddField( + model_name='qivipquestion', + name='image', + field=models.ImageField(blank=True, height_field=900, max_length=200, null=True, upload_to='question_images/', verbose_name='Bild', width_field=1000), + ), + ] diff --git a/django/library/migrations/0049_alter_qivipquestion_image.py b/django/library/migrations/0049_alter_qivipquestion_image.py new file mode 100644 index 0000000..3ee5e21 --- /dev/null +++ b/django/library/migrations/0049_alter_qivipquestion_image.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.7 on 2025-04-18 19:04 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('library', '0048_qivipquestion_image'), + ] + + operations = [ + migrations.AlterField( + model_name='qivipquestion', + name='image', + field=models.ImageField(blank=True, null=True, upload_to='question_images/', verbose_name='Bild'), + ), + ] diff --git a/django/library/models.py b/django/library/models.py index 8c1da34..23d46a3 100644 --- a/django/library/models.py +++ b/django/library/models.py @@ -74,6 +74,7 @@ class QivipQuestion(models.Model): 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") + image = models.ImageField(verbose_name="Bild", upload_to="question_images/", blank=True, null=True) def __str__(self): return self.data[:50] diff --git a/django/library/views.py b/django/library/views.py index c770750..5efed6e 100644 --- a/django/library/views.py +++ b/django/library/views.py @@ -348,6 +348,7 @@ def new_question(request): if request.method == 'POST': question_text = request.POST.get('question', '') + question_image = request.FILES['question_image'] # Handle different question types if question_type == 'true_false': @@ -387,6 +388,7 @@ def new_question(request): question = QivipQuestion() question.data = json.dumps(json_data) question.quiz_id = quiz + question.image = question_image question.time_per_question = request.POST.get('time_per_question', '30') question.save() #return modified(request, pk=quiz.pk) @@ -435,6 +437,7 @@ def edit_question(request, pk): try: question_data = json.loads(question.data) if question.data else {} question_type = question_data.get('type', 'multiple_choice') + question_image = question.image # For true/false questions, get the correct answer from the options if question_type == 'true_false': @@ -479,7 +482,11 @@ def edit_question(request, pk): if request.method == 'POST': question_text = request.POST.get('question', '') - + try: + question_image = request.FILES['question_image'] + except Exception: + pass + # Handle different question types if question_type == 'true_false': correct_answer = request.POST.get('correct_answer') == 'true' @@ -521,6 +528,7 @@ def edit_question(request, pk): question.data = json.dumps(json_data) question.time_per_question = request.POST.get('time_per_question', '30') + question.image = question_image question.save() #return modified(request, question.quiz_id.pk) return redirect('library:detail_quiz', pk=question.quiz_id.pk) @@ -532,6 +540,7 @@ def edit_question(request, pk): 'quiz_id': question.quiz_id.pk, 'quiz': question.quiz_id, 'time_per_question': question.time_per_question, + 'image': question_image, } return render(request, template_name, context) diff --git a/django/play/views.py b/django/play/views.py index 173bbeb..253f55e 100644 --- a/django/play/views.py +++ b/django/play/views.py @@ -219,7 +219,8 @@ def question(request, join_code): 'host_id': quiz_game.host_id, 'start_time': int(quiz_game.question_start_time.timestamp() * 1000), 'question_index': quiz_game.current_question_index, - 'total_questions': len(questions) + 'total_questions': len(questions), + 'question_image': current_question.image }) # Handle participant view @@ -239,7 +240,7 @@ def question(request, join_code): 'participant': participant, 'start_time': int(quiz_game.question_start_time.timestamp() * 1000), 'question_index': quiz_game.current_question_index, - 'total_questions': len(questions) + 'total_questions': len(questions), }) def waiting_room(request, join_code): diff --git a/django/templates/library/question/question_multiple_choice.html b/django/templates/library/question/question_multiple_choice.html index 7a9c0d4..b8ca900 100644 --- a/django/templates/library/question/question_multiple_choice.html +++ b/django/templates/library/question/question_multiple_choice.html @@ -10,7 +10,7 @@
-
+ {% csrf_token %} @@ -23,6 +23,15 @@
+ + {% if image %} + Bild der Frage + {% endif %} +
+ + +
+
diff --git a/django/templates/library/question/question_true_false.html b/django/templates/library/question/question_true_false.html index 8c8bd84..75d02d2 100644 --- a/django/templates/library/question/question_true_false.html +++ b/django/templates/library/question/question_true_false.html @@ -11,7 +11,7 @@
- + {% csrf_token %} @@ -24,6 +24,14 @@
+ {% if image %} + Bild der Frage + {% endif %} +
+ + +
+
diff --git a/django/templates/play/game/question_host.html b/django/templates/play/game/question_host.html index 84f1d7f..777dd88 100644 --- a/django/templates/play/game/question_host.html +++ b/django/templates/play/game/question_host.html @@ -5,6 +5,12 @@

Frage {{ question_index|add:1 }} von {{ total_questions }}

{{ question_data.question }}

+ + {% if question_image %} +
+ Bild der Frage +
+ {% endif %}
diff --git a/requirements.txt b/requirements.txt index 296b7a5..b3e400d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,5 @@ django~=5.1.4 channels~=4.2.0 # WebSocket support daphne~=4.1.2 # ASGI server pillow~=11.1.0 # Image handling -whitenoise~=6.6.0 # Static file serving \ No newline at end of file +whitenoise~=6.6.0 # Static file serving +django-cleanup \ No newline at end of file