Merge branch '71-bewertungssystem-ueberarbeiten' into 'master'

Resolve "Bewertungssystem ueberarbeiten"

Closes #71

See merge request enrichment-2024/qivip!62
This commit is contained in:
Juhn-Vitus Saß
2025-04-22 16:33:02 +00:00
7 changed files with 36 additions and 6 deletions

View File

@@ -7,6 +7,7 @@
3. [Superuser erstellen](#superuser-erstellen) 3. [Superuser erstellen](#superuser-erstellen)
4. [Tailwind-Nutzung](#tailwind-nutzung) 4. [Tailwind-Nutzung](#tailwind-nutzung)
5. [Issue - Merge Request - Merge](#issue-mergerequest-merge) 5. [Issue - Merge Request - Merge](#issue-mergerequest-merge)
6. [Konfiguration](#konfiguration)
## Initialisierung des Projekts ## 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 <branch>` bearbeitet werden. 2. Merge Request anlegen - dadurch wird der Branch automatisch angelegt. Dieser kann mit `git pull` geholt und mit `git checkout <branch>` bearbeitet werden.
3. Nach dem Hochladen kann der Merge in den Master durchgeführt 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 |

View File

@@ -0,0 +1,3 @@
{
"ENABLE_RATING_SYSTEM": true
}

View File

@@ -10,6 +10,7 @@ For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.1/ref/settings/ https://docs.djangoproject.com/en/5.1/ref/settings/
""" """
import json
from pathlib import Path from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
@@ -27,6 +28,9 @@ DEBUG = True
ALLOWED_HOSTS = ['127.0.0.1', 'localhost', '*'] 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 # Application definition

View File

@@ -4,10 +4,8 @@ from channels.generic.websocket import AsyncWebsocketConsumer
from channels.db import database_sync_to_async from channels.db import database_sync_to_async
from django.utils import timezone from django.utils import timezone
from django.urls import reverse from django.urls import reverse
from django.db import models
from datetime import timedelta
from play.models import QuizGame, QuizGameParticipant, QuizAnswer from play.models import QuizGame, QuizGameParticipant, QuizAnswer
from django.conf import settings
class GameConsumer(AsyncWebsocketConsumer): class GameConsumer(AsyncWebsocketConsumer):
@@ -244,6 +242,8 @@ class GameConsumer(AsyncWebsocketConsumer):
@database_sync_to_async @database_sync_to_async
def save_rating(self, participant_id, rating): def save_rating(self, participant_id, rating):
if not settings.QIVIP_CONFIG['ENABLE_RATING_SYSTEM']:
return False
from library.models import QuizRating from library.models import QuizRating
try: try:
game = QuizGame.objects.get(join_code=self.join_code) game = QuizGame.objects.get(join_code=self.join_code)

View File

@@ -2,9 +2,10 @@ from django.utils import timezone
from django.shortcuts import render from django.shortcuts import render
from django.shortcuts import render, redirect, get_object_or_404, reverse from django.shortcuts import render, redirect, get_object_or_404, reverse
from play.models import QuizGame, QuizGameParticipant 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.http import HttpResponseRedirect, HttpResponseNotFound
from django.contrib import messages from django.contrib import messages
from django.conf import settings
import json import json
@@ -144,7 +145,8 @@ def finished(request, join_code):
context = { context = {
'join_code': join_code, 'join_code': join_code,
'is_host': str(game.host_id) == str(request.session.get('host_id')), '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) return render(request, 'play/game/finished.html', context)
except QuizGame.DoesNotExist: except QuizGame.DoesNotExist:

View File

@@ -167,6 +167,7 @@
<!-- Rating --> <!-- Rating -->
<div class="flex items-center gap-1"> <div class="flex items-center gap-1">
{% if quiz.rating_count > 0 %}
{% for i in '12345'|make_list %} {% for i in '12345'|make_list %}
{% if forloop.counter <= quiz.average_rating|floatformat:0|add:0 %} {% if forloop.counter <= quiz.average_rating|floatformat:0|add:0 %}
<span class="text-yellow-500 text-base"></span> <span class="text-yellow-500 text-base"></span>
@@ -175,6 +176,9 @@
{% endif %} {% endif %}
{% endfor %} {% endfor %}
<span class="text-gray-600 text-sm">({{ quiz.rating_count }})</span> <span class="text-gray-600 text-sm">({{ quiz.rating_count }})</span>
{% else %}
<span class="text-gray-600 text-sm">Noch keine Bewertungen</span>
{% endif %}
</div> </div>
</div> </div>
@@ -355,6 +359,7 @@
<!-- Rating --> <!-- Rating -->
<div class="flex items-center gap-1"> <div class="flex items-center gap-1">
{% if quiz.rating_count > 0 %}
{% for i in '12345'|make_list %} {% for i in '12345'|make_list %}
{% if forloop.counter <= quiz.average_rating|floatformat:0|add:0 %} {% if forloop.counter <= quiz.average_rating|floatformat:0|add:0 %}
<span class="text-yellow-500 text-base"></span> <span class="text-yellow-500 text-base"></span>
@@ -362,7 +367,10 @@
<span class="text-gray-300 text-base"></span> <span class="text-gray-300 text-base"></span>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
<span class="text-gray-600 text-sm">({{ quiz.rating_count }})</span> <span class="text-gray-600 text-sm">({{ quiz.rating_count }})</span>
{% else %}
<span class="text-gray-600 text-sm">Noch keine Bewertungen</span>
{% endif %}
</div> </div>
</div> </div>

View File

@@ -11,6 +11,7 @@
</div> </div>
{% if not is_host %} {% if not is_host %}
{% if rating_enabled %}
<div class="bg-blue-50 rounded-lg p-6 mb-8"> <div class="bg-blue-50 rounded-lg p-6 mb-8">
<h2 class="text-2xl font-bold text-blue-800 mb-4 text-center">Wie hat dir das Quiz gefallen?</h2> <h2 class="text-2xl font-bold text-blue-800 mb-4 text-center">Wie hat dir das Quiz gefallen?</h2>
<div class="stars flex justify-center space-x-4 mb-4"> <div class="stars flex justify-center space-x-4 mb-4">
@@ -22,6 +23,9 @@
</div> </div>
<p id="rating-message" class="text-center text-blue-600 font-medium"></p> <p id="rating-message" class="text-center text-blue-600 font-medium"></p>
</div> </div>
{% else %}
<p class="text-center text-blue-600 font-medium mb-8">Bewertungen sind deaktiviert</p>
{% endif %}
{% endif %} {% endif %}
<div class="text-center"> <div class="text-center">