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 %}