From 154110e5106412da530bd65a5fd3682fcfe19020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhn-Vitus=20Sa=C3=9F?= Date: Tue, 22 Apr 2025 18:28:50 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Bewertungen=20verstecken=20wenn=20keine=20v?= =?UTF-8?q?orhanden=20und=20M=C3=B6glichkeit=20zum=20deaktivieren=20von=20?= =?UTF-8?q?Bewertungen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- django/config/qivip_config.json | 3 +++ django/core/settings.py | 4 ++++ django/play/consumers/game.py | 6 +++--- django/play/views.py | 6 ++++-- django/templates/library/overview_quiz.html | 10 +++++++++- django/templates/play/game/finished.html | 4 ++++ 6 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 django/config/qivip_config.json diff --git a/django/config/qivip_config.json b/django/config/qivip_config.json new file mode 100644 index 0000000..d4db3da --- /dev/null +++ b/django/config/qivip_config.json @@ -0,0 +1,3 @@ +{ + "ENABLE_RATING_SYSTEM": true +} \ No newline at end of file diff --git a/django/core/settings.py b/django/core/settings.py index 31ac5f5..e2c442d 100644 --- a/django/core/settings.py +++ b/django/core/settings.py @@ -10,6 +10,7 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/5.1/ref/settings/ """ +import json from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. @@ -27,6 +28,9 @@ DEBUG = True ALLOWED_HOSTS = ['127.0.0.1', 'localhost', '*'] +# Konfigurationsdatei für Projekt +with open(BASE_DIR / 'config' / 'qivip_config.json') as config_file: + QIVIP_CONFIG = json.load(config_file) # Application definition diff --git a/django/play/consumers/game.py b/django/play/consumers/game.py index b764851..f46cad3 100644 --- a/django/play/consumers/game.py +++ b/django/play/consumers/game.py @@ -4,10 +4,8 @@ from channels.generic.websocket import AsyncWebsocketConsumer from channels.db import database_sync_to_async from django.utils import timezone from django.urls import reverse -from django.db import models -from datetime import timedelta - from play.models import QuizGame, QuizGameParticipant, QuizAnswer +from django.conf import settings class GameConsumer(AsyncWebsocketConsumer): @@ -244,6 +242,8 @@ class GameConsumer(AsyncWebsocketConsumer): @database_sync_to_async def save_rating(self, participant_id, rating): + if not settings.QIVIP_CONFIG['ENABLE_RATING_SYSTEM']: + return False from library.models import QuizRating try: game = QuizGame.objects.get(join_code=self.join_code) diff --git a/django/play/views.py b/django/play/views.py index c2dbc3a..279e6fb 100644 --- a/django/play/views.py +++ b/django/play/views.py @@ -2,9 +2,10 @@ from django.utils import timezone from django.shortcuts import render from django.shortcuts import render, redirect, get_object_or_404, reverse from play.models import QuizGame, QuizGameParticipant -from library.models import QivipQuiz, QivipQuestion +from library.models import QivipQuiz from django.http import HttpResponseRedirect, HttpResponseNotFound from django.contrib import messages +from django.conf import settings import json @@ -144,7 +145,8 @@ def finished(request, join_code): context = { 'join_code': join_code, 'is_host': str(game.host_id) == str(request.session.get('host_id')), - 'participant_id': participant_id if participant else None + 'participant_id': participant_id if participant else None, + 'rating_enabled': settings.QIVIP_CONFIG['ENABLE_RATING_SYSTEM'] } return render(request, 'play/game/finished.html', context) except QuizGame.DoesNotExist: diff --git a/django/templates/library/overview_quiz.html b/django/templates/library/overview_quiz.html index 50e8b09..710dbc2 100644 --- a/django/templates/library/overview_quiz.html +++ b/django/templates/library/overview_quiz.html @@ -167,6 +167,7 @@
+ {% if quiz.rating_count > 0 %} {% for i in '12345'|make_list %} {% if forloop.counter <= quiz.average_rating|floatformat:0|add:0 %} @@ -175,6 +176,9 @@ {% endif %} {% endfor %} ({{ quiz.rating_count }}) + {% else %} + Noch keine Bewertungen + {% endif %}
@@ -355,6 +359,7 @@
+ {% if quiz.rating_count > 0 %} {% for i in '12345'|make_list %} {% if forloop.counter <= quiz.average_rating|floatformat:0|add:0 %} @@ -362,7 +367,10 @@ {% endif %} {% endfor %} - ({{ quiz.rating_count }}) + ({{ quiz.rating_count }}) + {% else %} + Noch keine Bewertungen + {% endif %}
diff --git a/django/templates/play/game/finished.html b/django/templates/play/game/finished.html index 9290126..6cac803 100644 --- a/django/templates/play/game/finished.html +++ b/django/templates/play/game/finished.html @@ -11,6 +11,7 @@ {% if not is_host %} + {% if rating_enabled %}

Wie hat dir das Quiz gefallen?

@@ -22,6 +23,9 @@

+ {% else %} +

Bewertungen sind deaktiviert

+ {% endif %} {% endif %}
From af919b9ea5041f962002b2df4aee9f9ca246c29a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhn-Vitus=20Sa=C3=9F?= Date: Tue, 22 Apr 2025 18:31:51 +0200 Subject: [PATCH 2/2] README updaten --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 4eedbbf..ad9f646 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ 3. [Superuser erstellen](#superuser-erstellen) 4. [Tailwind-Nutzung](#tailwind-nutzung) 5. [Issue - Merge Request - Merge](#issue-mergerequest-merge) +6. [Konfiguration](#konfiguration) ## Initialisierung des Projekts @@ -161,3 +162,11 @@ Hier der vereinbarte Arbeitsablauf: 2. Merge Request anlegen - dadurch wird der Branch automatisch angelegt. Dieser kann mit `git pull` geholt und mit `git checkout ` bearbeitet werden. 3. Nach dem Hochladen kann der Merge in den Master durchgeführt werden. + +## Konfiguration + +Die Konfiguration des Projekts befindet sich im `config/qivip_config.json`. + +| Variable | Bedeutung | Optionen | +| --- | --- | --- | +| ENABLE_RATING_SYSTEM | Soll das Bewertungssystem aktiviert werden? | true [Standard], false | \ No newline at end of file