Compare commits
61 Commits
90-404-sei
...
91-bilder-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d8e211c72 | ||
|
|
6da095c35e | ||
|
|
2dc9a077ee | ||
|
|
881bc3d6c1 | ||
|
|
b1e438229a | ||
|
|
97e4fa9505 | ||
|
|
3981dc31da | ||
|
|
7b86b0791c | ||
|
|
7faf931fb2 | ||
|
|
9245f928dc | ||
|
|
1f5a177060 | ||
|
|
ebbe4f7193 | ||
|
|
acd07bfb80 | ||
|
|
d824816be8 | ||
|
|
2c563b3471 | ||
|
|
4122f0631b | ||
|
|
2372cf7146 | ||
|
|
6305af9879 | ||
|
|
176a3cc15c | ||
|
|
fa9bb45d3f | ||
|
|
cc449997dc | ||
|
|
e813660722 | ||
|
|
1d6fab919e | ||
|
|
17195a221f | ||
|
|
3fc08cbd4e | ||
|
|
4cf6f45daf | ||
|
|
d2ad0f041f | ||
|
|
bcdfebf791 | ||
|
|
937fd4a2e4 | ||
|
|
a9343f285a | ||
|
|
d4252c1297 | ||
|
|
2052a702f0 | ||
|
|
a0292ce409 | ||
|
|
73cd52ea3d | ||
|
|
ffe636c6c7 | ||
|
|
e22ea40910 | ||
|
|
e269264f03 | ||
|
|
9fb9ab9198 | ||
|
|
4209dcbc2d | ||
|
|
70be6396aa | ||
|
|
5b4c76a1c8 | ||
|
|
9d9e1527f4 | ||
|
|
70741a5a34 | ||
|
|
8022602fc5 | ||
|
|
f0dcc2baad | ||
|
|
2221c99ad7 | ||
|
|
d84b44252e | ||
|
|
5a719de8ee | ||
|
|
7c8c142e34 | ||
|
|
093b0a7f83 | ||
|
|
a4442fe12e | ||
|
|
a59df8dd62 | ||
|
|
80390de6dc | ||
|
|
5f05964b1b | ||
|
|
d53240c710 | ||
|
|
1f3b551b94 | ||
|
|
2a7e39bbd0 | ||
|
|
04ce8104fe | ||
|
|
7ce0e6e9dd | ||
|
|
77714d22a9 | ||
|
|
f405016f96 |
22
README.md
22
README.md
@@ -61,6 +61,13 @@ Für die Entwicklung mit WebSocket-Unterstützung verwenden wir Daphne:
|
|||||||
daphne -b 127.0.0.1 -p 8000 core.asgi:application
|
daphne -b 127.0.0.1 -p 8000 core.asgi:application
|
||||||
```
|
```
|
||||||
|
|
||||||
|
3. Starte den REDIS Server
|
||||||
|
```sh
|
||||||
|
redis-server
|
||||||
|
```
|
||||||
|
> **Hinweis:** Der Redis Server muss, wenn er nicht auf dem selben Gerät unter Standardeinstellungen läuft, in der Datei play/consumers/lobby.py und core/settings.py entsprechend umkonfiguriert werden!
|
||||||
|
|
||||||
|
|
||||||
Alternativ kannst du den Django-Entwicklungsserver verwenden, wenn du keine WebSocket-Funktionalität benötigst:
|
Alternativ kannst du den Django-Entwicklungsserver verwenden, wenn du keine WebSocket-Funktionalität benötigst:
|
||||||
```sh
|
```sh
|
||||||
python3 core/manage.py runserver
|
python3 core/manage.py runserver
|
||||||
@@ -84,6 +91,19 @@ Für den Produktivbetrieb verwenden wir Daphne als ASGI-Server, der sowohl HTTP
|
|||||||
- `-b 0.0.0.0`: Bindet den Server an alle Netzwerk-Interfaces
|
- `-b 0.0.0.0`: Bindet den Server an alle Netzwerk-Interfaces
|
||||||
- `-p 8000`: Port (anpassbar)
|
- `-p 8000`: Port (anpassbar)
|
||||||
|
|
||||||
|
4. Cronjob für Bereinigung der Spiele in der Datenbank
|
||||||
|
- Zum bearbeiten der Cronjobs:
|
||||||
|
```sh
|
||||||
|
crontab -e
|
||||||
|
```
|
||||||
|
- Dann `0 0 * * * /path/to/venv/bin/python /path/to/your_project/manage.py cleanup_games` einfügen, damit um Mitternacht alle Spiele gelöscht werden
|
||||||
|
|
||||||
|
5. Starte den REDIS Server
|
||||||
|
```sh
|
||||||
|
redis-server
|
||||||
|
```
|
||||||
|
> **Hinweis:** Der Redis Server muss, wenn er nicht auf dem selben Gerät unter Standardeinstellungen läuft, in der Datei play/consumers/lobby.py und core/settings.py entsprechend umkonfiguriert werden!
|
||||||
|
|
||||||
Damit ist das Projekt erfolgreich eingerichtet und der Server kann gestartet werden!
|
Damit ist das Projekt erfolgreich eingerichtet und der Server kann gestartet werden!
|
||||||
|
|
||||||
## Superuser erstellen
|
## Superuser erstellen
|
||||||
@@ -138,6 +158,6 @@ Hier der vereinbarte Arbeitsablauf:
|
|||||||
|
|
||||||
1. Issue erstellen - das geht am einfachsten über die Webseite. Der Titel beschreibt kurz und klar, was angestrebt wird.
|
1. Issue erstellen - das geht am einfachsten über die Webseite. Der Titel beschreibt kurz und klar, was angestrebt wird.
|
||||||
|
|
||||||
2. Merge Request anlegen - dadurch wird der Bransch 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.
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'channels',
|
'channels',
|
||||||
|
'django_cleanup',
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
@@ -78,12 +79,16 @@ WSGI_APPLICATION = 'core.wsgi.application'
|
|||||||
ASGI_APPLICATION = 'core.asgi.application'
|
ASGI_APPLICATION = 'core.asgi.application'
|
||||||
|
|
||||||
CHANNEL_LAYERS = {
|
CHANNEL_LAYERS = {
|
||||||
'default': {
|
"default": {
|
||||||
'BACKEND': 'channels.layers.InMemoryChannelLayer'
|
"BACKEND": "channels_redis.core.RedisChannelLayer",
|
||||||
}
|
"CONFIG": {
|
||||||
|
"hosts": [("127.0.0.1", 6379)],
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
|
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from .models import QivipQuiz, QivipQuestion, QuizCategory
|
from .models import QivipQuiz, QivipQuestion, QivipQuizFavorite, QuizCategory
|
||||||
|
|
||||||
# Für das QivipQuiz Modell
|
# Für das QivipQuiz Modell
|
||||||
class QivipQuizAdmin(admin.ModelAdmin):
|
class QivipQuizAdmin(admin.ModelAdmin):
|
||||||
@@ -18,13 +18,13 @@ class QuizCategoryAdmin(admin.ModelAdmin):
|
|||||||
search_fields = ('name',)
|
search_fields = ('name',)
|
||||||
prepopulated_fields = {'slug': ('name',)} # Erstelle automatisch den Slug basierend auf dem Namen
|
prepopulated_fields = {'slug': ('name',)} # Erstelle automatisch den Slug basierend auf dem Namen
|
||||||
|
|
||||||
# Für das Tag Modell
|
|
||||||
class TagAdmin(admin.ModelAdmin):
|
|
||||||
list_display = ('name',) # Zeige nur den Namen des Tags
|
class QivipQuizFavoriteAdmin(admin.ModelAdmin):
|
||||||
search_fields = ('name',)
|
list_display = ('user', 'favorite', 'quiz') # Welche Felder sollen in der Übersicht angezeigt werden
|
||||||
|
|
||||||
# Registrierung der Modelle im Admin
|
# Registrierung der Modelle im Admin
|
||||||
admin.site.register(QivipQuiz, QivipQuizAdmin)
|
admin.site.register(QivipQuiz, QivipQuizAdmin)
|
||||||
admin.site.register(QivipQuestion, QivipQuestionAdmin)
|
admin.site.register(QivipQuestion, QivipQuestionAdmin)
|
||||||
admin.site.register(QuizCategory, QuizCategoryAdmin)
|
admin.site.register(QuizCategory, QuizCategoryAdmin)
|
||||||
|
admin.site.register(QivipQuizFavorite, QivipQuizFavoriteAdmin)
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ from .models import QivipQuiz, QivipQuestion
|
|||||||
class QuizForm(forms.ModelForm):
|
class QuizForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = QivipQuiz
|
model = QivipQuiz
|
||||||
fields = ['name', 'description','image', 'status', 'category', "difficulty","credits"]
|
fields = ['name', 'description','image', 'status', 'category','difficulty','credits']
|
||||||
|
|
||||||
class QuestionForm(forms.ModelForm):
|
class QuestionForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = QivipQuestion
|
model = QivipQuestion
|
||||||
fields = ['quiz_id', 'data']
|
fields = ['quiz_id', 'data','time_per_question']
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
|
||||||
|
|||||||
13
django/library/management/commands/cleanup_games.py
Normal file
13
django/library/management/commands/cleanup_games.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
from play.models import QuizGame
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = 'Bereinigt beendete Spiele'
|
||||||
|
|
||||||
|
def handle(self, *args, **kwargs):
|
||||||
|
expired_games = QuizGame.objects.filter(
|
||||||
|
updated_at__lt=timezone.now() - timezone.timedelta(minutes=5))
|
||||||
|
deleted_count = expired_games.count()
|
||||||
|
expired_games.delete()
|
||||||
|
self.stdout.write(f'{deleted_count} alte Spiele gelöscht.')
|
||||||
@@ -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),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -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),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -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),
|
||||||
|
),
|
||||||
|
]
|
||||||
18
django/library/migrations/0035_qivipquiz_favorite.py
Normal file
18
django/library/migrations/0035_qivipquiz_favorite.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-04-10 14:52
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0034_alter_qivipquiz_status'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='favorite',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-04-10 16:02
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0035_qivipquiz_favorite'),
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='favorite',
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='QuizFavorite',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('favorite', models.BooleanField(default=False)),
|
||||||
|
('quiz', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='library.qivipquiz')),
|
||||||
|
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'unique_together': {('user', 'quiz')},
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-04-10 16:05
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0036_remove_qivipquiz_favorite_quizfavorite'),
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameModel(
|
||||||
|
old_name='QuizFavorite',
|
||||||
|
new_name='QivipQuizFavorite',
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-04-10 17:08
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0037_rename_quizfavorite_qivipquizfavorite'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='qivipquizfavorite',
|
||||||
|
name='quiz',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='favorites', to='library.qivipquiz'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-04-11 12:40
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0038_alter_qivipquizfavorite_quiz'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='qivipquizfavorite',
|
||||||
|
name='favorite_date',
|
||||||
|
field=models.DateTimeField(auto_now=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-04-11 13:15
|
||||||
|
|
||||||
|
import library.models
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0039_qivipquizfavorite_favorite_date'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='description',
|
||||||
|
field=models.TextField(default='In dem Quiz geht es um ...', max_length=200, validators=[library.models.QivipQuiz.validate_description], verbose_name='Beschreibung'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-04-11 13:21
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0040_alter_qivipquiz_description'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='category',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='quiz', to='library.quizcategory', verbose_name='Kategorie'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='difficulty',
|
||||||
|
field=models.CharField(choices=[('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('nicht gesetzt', 'nicht gesetzt')], default='nicht gesetzt', help_text='1: niedrigste Schwierigkeit und 5: höchste Schwierigkeit', max_length=13, verbose_name='Schwierigkeit'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='image',
|
||||||
|
field=models.ImageField(blank=True, max_length=256, null=True, upload_to='quiz_images/', verbose_name='Bild'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='name',
|
||||||
|
field=models.CharField(max_length=75, verbose_name='Name des Quizzes'),
|
||||||
|
),
|
||||||
|
]
|
||||||
19
django/library/migrations/0042_qivipquiz_favorite.py
Normal file
19
django/library/migrations/0042_qivipquiz_favorite.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-04-11 13:43
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0041_alter_qivipquiz_category_alter_qivipquiz_difficulty_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='favorite',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='quizzes', to='library.qivipquizfavorite'),
|
||||||
|
),
|
||||||
|
]
|
||||||
17
django/library/migrations/0043_remove_qivipquiz_favorite.py
Normal file
17
django/library/migrations/0043_remove_qivipquiz_favorite.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-04-11 15:25
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0042_qivipquiz_favorite'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='favorite',
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-04-11 16:03
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0043_remove_qivipquiz_favorite'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='qivipquizfavorite',
|
||||||
|
name='favorite_date',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='favorite_date',
|
||||||
|
field=models.DateTimeField(auto_now=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-04-11 16:34
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0044_remove_qivipquizfavorite_favorite_date_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='favorite_date',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='qivipquizfavorite',
|
||||||
|
name='favorite_date',
|
||||||
|
field=models.DateTimeField(auto_now=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-04-11 16:50
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0045_remove_qivipquiz_favorite_date_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='qivipquizfavorite',
|
||||||
|
name='favorite_date',
|
||||||
|
field=models.DateTimeField(blank=True, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
14
django/library/migrations/0047_merge_20250418_1334.py
Normal file
14
django/library/migrations/0047_merge_20250418_1334.py
Normal file
@@ -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 = [
|
||||||
|
]
|
||||||
18
django/library/migrations/0048_qivipquestion_image.py
Normal file
18
django/library/migrations/0048_qivipquestion_image.py
Normal file
@@ -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),
|
||||||
|
),
|
||||||
|
]
|
||||||
18
django/library/migrations/0049_alter_qivipquestion_image.py
Normal file
18
django/library/migrations/0049_alter_qivipquestion_image.py
Normal file
@@ -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'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -20,11 +20,14 @@ class QivipQuiz(models.Model):
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def validate_description(value):
|
def validate_description(value):
|
||||||
if value.strip() == "In dem Quiz geht es um ...":
|
if value.strip() == "In dem Quiz geht es um ...":
|
||||||
raise ValidationError("Bitte gib eine aussagekräftige Beschreibung ein.")
|
raise ValidationError("Bitte gib eine aussagekräftige Beschreibung ein.")
|
||||||
|
|
||||||
image = models.ImageField(max_length=256, upload_to='quiz_images/', blank=True, null=True) # Bild speichern in media/quiz_images/
|
image = models.ImageField(max_length=256,verbose_name="Bild", upload_to='quiz_images/', blank=True, null=True) # Bild speichern in media/quiz_images/
|
||||||
uuid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
|
uuid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
|
||||||
user_id = models.ForeignKey(User, on_delete=models.CASCADE, related_name='quiz')
|
user_id = models.ForeignKey(User, on_delete=models.CASCADE, related_name='quiz')
|
||||||
#creator = models.ForeignKey(User, on_delete=models.SET_NULL,blank=True, null=True, related_name='creator_quiz')
|
#creator = models.ForeignKey(User, on_delete=models.SET_NULL,blank=True, null=True, related_name='creator_quiz')
|
||||||
@@ -32,10 +35,10 @@ class QivipQuiz(models.Model):
|
|||||||
creation_date = models.DateTimeField(auto_now_add=True)
|
creation_date = models.DateTimeField(auto_now_add=True)
|
||||||
update_date = models.DateTimeField(auto_now=True)
|
update_date = models.DateTimeField(auto_now=True)
|
||||||
status = models.CharField(max_length=10, choices=list(STATUS_VALUES.items()), default="öffentlich")
|
status = models.CharField(max_length=10, choices=list(STATUS_VALUES.items()), default="öffentlich")
|
||||||
category = models.ForeignKey('QuizCategory', related_name='quiz', on_delete=models.CASCADE)
|
category = models.ForeignKey('QuizCategory',verbose_name="Kategorie", related_name='quiz', on_delete=models.CASCADE)
|
||||||
name = models.CharField(max_length=75)
|
name = models.CharField(max_length=75,verbose_name="Name des Quizzes")
|
||||||
description = models.TextField(validators=[validate_description],max_length=200,blank=False, default="In dem Quiz geht es um ...")
|
description = models.TextField(validators=[validate_description],max_length=200,blank=False, default="In dem Quiz geht es um ...", verbose_name="Beschreibung")
|
||||||
difficulty= models.CharField(max_length=13, choices=list(DIFFICULTY_VALUES.items()), default="nicht gesetzt", help_text="1: niedrigste Schwierigkeit und 5: höchste Schwierigkeit")
|
difficulty= models.CharField(verbose_name="Schwierigkeit", max_length=13, choices=list(DIFFICULTY_VALUES.items()), default="nicht gesetzt", help_text="1: niedrigste Schwierigkeit und 5: höchste Schwierigkeit")
|
||||||
credits=models.TextField(blank=True, editable=True)
|
credits=models.TextField(blank=True, editable=True)
|
||||||
average_rating = models.FloatField(default=3.0)
|
average_rating = models.FloatField(default=3.0)
|
||||||
rating_count = models.IntegerField(default=0)
|
rating_count = models.IntegerField(default=0)
|
||||||
@@ -43,16 +46,35 @@ class QivipQuiz(models.Model):
|
|||||||
|
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
class QivipQuizFavorite(models.Model):
|
||||||
|
user = models.ForeignKey(User, on_delete=models.CASCADE) # Verknüpfung zu User
|
||||||
|
quiz = models.ForeignKey(QivipQuiz, on_delete=models.CASCADE, related_name='favorites') # Verknüpfung zu Quiz
|
||||||
|
favorite = models.BooleanField(default=False) # Favoritenstatus
|
||||||
|
favorite_date = models.DateTimeField(null=True, blank=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
unique_together = ('user', 'quiz') # Sicherstellen, dass es nur ein Favorit pro User und Quiz gibt
|
||||||
|
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
class QivipQuestion(models.Model):
|
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)
|
uuid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
|
||||||
quiz_id = models.ForeignKey(QivipQuiz, on_delete=models.CASCADE, related_name='questions')
|
quiz_id = models.ForeignKey(QivipQuiz, on_delete=models.CASCADE, related_name='questions')
|
||||||
creation_date = models.DateTimeField(auto_now_add=True)
|
creation_date = models.DateTimeField(auto_now_add=True)
|
||||||
update_date = models.DateTimeField(auto_now=True)
|
update_date = models.DateTimeField(auto_now=True)
|
||||||
data = models.TextField()
|
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):
|
def __str__(self):
|
||||||
return self.data[:50]
|
return self.data[:50]
|
||||||
|
|
||||||
|
|||||||
@@ -15,5 +15,6 @@ urlpatterns = [
|
|||||||
path('question/edit/<int:pk>/', views.edit_question, name='edit_question'),
|
path('question/edit/<int:pk>/', views.edit_question, name='edit_question'),
|
||||||
path('question/delete/<int:pk>/', views.delete_question, name='delete_question'),
|
path('question/delete/<int:pk>/', views.delete_question, name='delete_question'),
|
||||||
path('detail/copy/<int:pk>/', views.copy_quiz, name='copy_quiz'),
|
path('detail/copy/<int:pk>/', views.copy_quiz, name='copy_quiz'),
|
||||||
|
path('favorite_quiz/<int:pk>/', views.favorite_quiz, name='favorite_quiz'),
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
|
from django.utils import timezone
|
||||||
import uuid
|
import uuid
|
||||||
|
from django.http import HttpResponse, HttpResponseRedirect
|
||||||
from django.shortcuts import render, redirect, get_object_or_404
|
from django.shortcuts import render, redirect, get_object_or_404
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from .models import QivipQuiz, QivipQuestion
|
from .models import QivipQuiz, QivipQuestion, QivipQuizFavorite
|
||||||
from .forms import QuizForm, QuestionForm
|
from .forms import QuizForm, QuestionForm
|
||||||
import json
|
import json
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
@@ -17,12 +19,23 @@ from django.contrib.auth.models import User
|
|||||||
def overview_quiz(request):
|
def overview_quiz(request):
|
||||||
# Filter
|
# Filter
|
||||||
form = QuizFilterForm(request.GET)
|
form = QuizFilterForm(request.GET)
|
||||||
|
try:
|
||||||
|
favorite_quizzes_data = QivipQuizFavorite.objects.filter(user=request.user, favorite=True).order_by("-favorite_date")
|
||||||
|
favorite_quiz_ids = favorite_quizzes_data.values_list('quiz', flat=True)
|
||||||
|
favorite_quizzes = QivipQuiz.objects.filter(id__in=favorite_quiz_ids)
|
||||||
|
except:
|
||||||
|
favorite_quizzes_data = QivipQuizFavorite.objects.none()
|
||||||
|
favorite_quizzes = QivipQuizFavorite.objects.none()
|
||||||
|
favorite_quiz_ids = favorite_quizzes.none()
|
||||||
|
favorite_quizzes = QivipQuiz.objects.none()
|
||||||
|
|
||||||
# Initialize querysets
|
# Initialize querysets
|
||||||
if request.user.is_authenticated:
|
if request.user.is_authenticated:
|
||||||
filter_my_quizzes = QivipQuiz.objects.filter(user_id=request.user).annotate(max_amout_questions=Count('questions'))
|
filter_my_quizzes = QivipQuiz.objects.filter(user_id=request.user).annotate(max_amout_questions=Count('questions'))
|
||||||
|
favorite_quizzes = favorite_quizzes.filter(id__in=favorite_quiz_ids).annotate(max_amout_questions=Count('questions'))
|
||||||
filter_other_quizzes = QivipQuiz.objects.exclude(user_id=request.user)
|
filter_other_quizzes = QivipQuiz.objects.exclude(user_id=request.user)
|
||||||
else:
|
else:
|
||||||
|
favorite_quizzes = QivipQuiz.objects.none()
|
||||||
filter_my_quizzes = QivipQuiz.objects.none()
|
filter_my_quizzes = QivipQuiz.objects.none()
|
||||||
filter_other_quizzes = QivipQuiz.objects.all()
|
filter_other_quizzes = QivipQuiz.objects.all()
|
||||||
|
|
||||||
@@ -30,11 +43,49 @@ def overview_quiz(request):
|
|||||||
filter_other_quizzes = filter_other_quizzes.annotate(max_amout_questions=Count('questions'))
|
filter_other_quizzes = filter_other_quizzes.annotate(max_amout_questions=Count('questions'))
|
||||||
filter_other_quizzes = filter_other_quizzes.filter(max_amout_questions__gte=1, status='öffentlich')
|
filter_other_quizzes = filter_other_quizzes.filter(max_amout_questions__gte=1, status='öffentlich')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
|
|
||||||
search = form.cleaned_data.get('search')
|
search = form.cleaned_data.get('search')
|
||||||
username= form.cleaned_data.get('user')
|
username= form.cleaned_data.get('user')
|
||||||
max_amout_questions= form.cleaned_data.get('max_amout_questions')
|
max_amout_questions= form.cleaned_data.get('max_amout_questions')
|
||||||
min_amout_questions= form.cleaned_data.get('min_amout_questions')
|
min_amout_questions= form.cleaned_data.get('min_amout_questions')
|
||||||
|
|
||||||
|
filters = {}
|
||||||
|
if username:
|
||||||
|
try:
|
||||||
|
user = User.objects.get(username=username)
|
||||||
|
filters['user_id'] = user.id
|
||||||
|
except User.DoesNotExist:
|
||||||
|
favorite_quizzes = QivipQuiz.objects.none()
|
||||||
|
filter_my_quizzes = QivipQuiz.objects.none()
|
||||||
|
filter_other_quizzes=QivipQuiz.objects.none()
|
||||||
|
|
||||||
|
if search:
|
||||||
|
filters['name__icontains'] = search
|
||||||
|
if min_amout_questions:
|
||||||
|
filters['max_amout_questions__gte'] = min_amout_questions
|
||||||
|
if max_amout_questions:
|
||||||
|
filters['max_amout_questions__lte'] = max_amout_questions
|
||||||
|
|
||||||
|
try:
|
||||||
|
filter_other_quizzes = filter_other_quizzes.filter(**filters)
|
||||||
|
except:
|
||||||
|
filter_other_quizzes=QivipQuiz.objects.none()
|
||||||
|
try:
|
||||||
|
filter_my_quizzes = filter_my_quizzes.filter(**filters)
|
||||||
|
except:
|
||||||
|
filter_my_quizzes=QivipQuiz.objects.none()
|
||||||
|
|
||||||
|
try:
|
||||||
|
favorite_quizzes = favorite_quizzes.filter(**filters)
|
||||||
|
except:
|
||||||
|
favorite_quizzes=QivipQuiz.objects.none()
|
||||||
|
|
||||||
|
"""
|
||||||
if search: # Suche nach Namen
|
if search: # Suche nach Namen
|
||||||
filter_other_quizzes = filter_other_quizzes.filter(name__icontains=search)
|
filter_other_quizzes = filter_other_quizzes.filter(name__icontains=search)
|
||||||
filter_my_quizzes = filter_my_quizzes.filter(name__icontains=search)
|
filter_my_quizzes = filter_my_quizzes.filter(name__icontains=search)
|
||||||
@@ -63,7 +114,7 @@ def overview_quiz(request):
|
|||||||
filter_other_quizzes=filter_other_quizzes.exclude(user_id=request.user)
|
filter_other_quizzes=filter_other_quizzes.exclude(user_id=request.user)
|
||||||
except:
|
except:
|
||||||
filter_other_quizzes=filter_other_quizzes
|
filter_other_quizzes=filter_other_quizzes
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
# Pagination for my quizzes
|
# Pagination for my quizzes
|
||||||
@@ -80,8 +131,28 @@ def overview_quiz(request):
|
|||||||
except:
|
except:
|
||||||
other_quizzes = other_quizzes_paginator.page(1)
|
other_quizzes = other_quizzes_paginator.page(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
favorite_quizzes = favorite_quizzes.filter(
|
||||||
|
favorites__user=request.user, # Filtere nach dem User
|
||||||
|
favorites__favorite=True # Filtere nach favorisierten Quizzes
|
||||||
|
).order_by('-favorites__favorite_date')
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# Pagination for favorite_quizzes
|
||||||
|
favorite_quizzes_paginator = Paginator(favorite_quizzes, 8) # 8 quizzes per page
|
||||||
|
try:
|
||||||
|
favorite_quizzes = favorite_quizzes_paginator.page(request.GET.get('my_page', 1))
|
||||||
|
except:
|
||||||
|
favorite_quizzes = favorite_quizzes_paginator.page(1)
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
'show_search': True,
|
'show_search': True,
|
||||||
|
'favorite_quiz_ids': favorite_quiz_ids,
|
||||||
|
'favorite_quizzes':favorite_quizzes,
|
||||||
'my_quizzes': my_quizzes,
|
'my_quizzes': my_quizzes,
|
||||||
'other_quizzes': other_quizzes,
|
'other_quizzes': other_quizzes,
|
||||||
'form': form,
|
'form': form,
|
||||||
@@ -89,7 +160,34 @@ def overview_quiz(request):
|
|||||||
|
|
||||||
return render(request, 'library/overview_quiz.html', context)
|
return render(request, 'library/overview_quiz.html', context)
|
||||||
|
|
||||||
|
# Neues Quiz erstellen
|
||||||
|
@login_required
|
||||||
|
def favorite_quiz(request, pk):
|
||||||
|
quiz= get_object_or_404(QivipQuiz, pk=pk)
|
||||||
|
favorite = QivipQuizFavorite.objects.filter(user=request.user, quiz=quiz).first()
|
||||||
|
|
||||||
|
if favorite:
|
||||||
|
favorite.favorite=not favorite.favorite
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if favorite.favorite==True:
|
||||||
|
favorite.favorite_date = timezone.now()
|
||||||
|
|
||||||
|
statement="Das Quiz '"+ favorite.quiz.name+ "' wurde erfolgreich zu den Favoriten hinzugefügt!"
|
||||||
|
messages.success(request,statement )
|
||||||
|
favorite.save()
|
||||||
|
else:
|
||||||
|
favorite.favorite_date = None
|
||||||
|
favorite.delete()
|
||||||
|
statement="Das Quiz '"+ favorite.quiz.name+ "' wurde erfolgreich von den Favoriten entfernt!"
|
||||||
|
messages.error(request, statement)
|
||||||
|
|
||||||
|
|
||||||
|
else:
|
||||||
|
QivipQuizFavorite.objects.create(user=request.user, quiz=quiz, favorite=True, favorite_date=timezone.now())
|
||||||
|
|
||||||
|
return redirect(request.META.get('HTTP_REFERER', 'library:overview_quiz'))
|
||||||
|
|
||||||
|
|
||||||
# Neues Quiz erstellen
|
# Neues Quiz erstellen
|
||||||
@@ -102,7 +200,7 @@ def new_quiz(request):
|
|||||||
quiz.user_id = request.user
|
quiz.user_id = request.user
|
||||||
#quiz.creator = request.user
|
#quiz.creator = request.user
|
||||||
quiz.save()
|
quiz.save()
|
||||||
form.save_m2m() # Speichert die Many-to-Many Beziehungen (Tags)
|
#form.save_m2m() # Speichert die Many-to-Many Beziehungen (Tags)
|
||||||
return redirect('library:detail_quiz', pk=quiz.pk)
|
return redirect('library:detail_quiz', pk=quiz.pk)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@@ -151,33 +249,7 @@ def detail_quiz(request, pk):
|
|||||||
'detail':show_answers,
|
'detail':show_answers,
|
||||||
}
|
}
|
||||||
return render(request, 'library/detail_quiz.html', context)
|
return render(request, 'library/detail_quiz.html', context)
|
||||||
"""
|
|
||||||
def modified(request, pk):
|
|
||||||
|
|
||||||
original_quiz = get_object_or_404(QivipQuiz, pk=pk)
|
|
||||||
words=original_quiz.modified_description.split()
|
|
||||||
word_exist=0
|
|
||||||
print(original_quiz.creator.username)
|
|
||||||
print(request.user.username)
|
|
||||||
|
|
||||||
for word in words:
|
|
||||||
|
|
||||||
if word==request.user.username or word+","==request.user.username:
|
|
||||||
word_exist=1
|
|
||||||
|
|
||||||
|
|
||||||
if word_exist==0 and len(words)!=0 and request.user.username!=original_quiz.creator.username:
|
|
||||||
original_quiz.modified_description +=", "+ request.user.username
|
|
||||||
|
|
||||||
|
|
||||||
elif word_exist==0 and request.user.username!=original_quiz.creator.username:
|
|
||||||
original_quiz.modified_description +=" "+ request.user.username
|
|
||||||
|
|
||||||
original_quiz.save()
|
|
||||||
|
|
||||||
return redirect('library:detail_quiz', pk=pk)
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def copy_quiz(request, pk):
|
def copy_quiz(request, pk):
|
||||||
@@ -194,6 +266,8 @@ def copy_quiz(request, pk):
|
|||||||
new_quiz.user_id = request.user # Neuer Besitzer ist der aktuelle User
|
new_quiz.user_id = request.user # Neuer Besitzer ist der aktuelle User
|
||||||
new_quiz.name += " - Kopie" # Optional: Name anpassen
|
new_quiz.name += " - Kopie" # Optional: Name anpassen
|
||||||
new_quiz.base_quiz_id = pk
|
new_quiz.base_quiz_id = pk
|
||||||
|
new_quiz.rating_count = 0
|
||||||
|
new_quiz.average_rating = 3.0
|
||||||
#new_quiz.creator = original_quiz.creator or request.user
|
#new_quiz.creator = original_quiz.creator or request.user
|
||||||
new_quiz.save() # Speichern als neues Objekt
|
new_quiz.save() # Speichern als neues Objekt
|
||||||
# Optional: Beschreibung anpassen
|
# Optional: Beschreibung anpassen
|
||||||
@@ -244,6 +318,7 @@ def new_question(request):
|
|||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
question_text = request.POST.get('question', '')
|
question_text = request.POST.get('question', '')
|
||||||
|
question_image = request.FILES.get('question_image', None)
|
||||||
|
|
||||||
# Handle different question types
|
# Handle different question types
|
||||||
if question_type == 'true_false':
|
if question_type == 'true_false':
|
||||||
@@ -283,6 +358,8 @@ def new_question(request):
|
|||||||
question = QivipQuestion()
|
question = QivipQuestion()
|
||||||
question.data = json.dumps(json_data)
|
question.data = json.dumps(json_data)
|
||||||
question.quiz_id = quiz
|
question.quiz_id = quiz
|
||||||
|
question.image = question_image
|
||||||
|
question.time_per_question = request.POST.get('time_per_question', '30')
|
||||||
question.save()
|
question.save()
|
||||||
#return modified(request, pk=quiz.pk)
|
#return modified(request, pk=quiz.pk)
|
||||||
return redirect('library:detail_quiz', pk=quiz.pk)
|
return redirect('library:detail_quiz', pk=quiz.pk)
|
||||||
@@ -297,6 +374,7 @@ def new_question(request):
|
|||||||
{'value': 'Falsch', 'is_correct': False}
|
{'value': 'Falsch', 'is_correct': False}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
standard_time_per_question = 30
|
||||||
elif question_type == 'multiple_choice':
|
elif question_type == 'multiple_choice':
|
||||||
question_data = {
|
question_data = {
|
||||||
'type': question_type,
|
'type': question_type,
|
||||||
@@ -306,12 +384,14 @@ def new_question(request):
|
|||||||
{'value': '', 'is_correct': False}
|
{'value': '', 'is_correct': False}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
standard_time_per_question = 30
|
||||||
|
|
||||||
template_name = f'library/question/question_{question_type}.html'
|
template_name = f'library/question/question_{question_type}.html'
|
||||||
context = {
|
context = {
|
||||||
'question': question_data,
|
'question': question_data,
|
||||||
'quiz_id': quiz_id,
|
'quiz_id': quiz_id,
|
||||||
'quiz': quiz
|
'quiz': quiz,
|
||||||
|
'standard_time_per_question': standard_time_per_question,
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(request, template_name, context)
|
return render(request, template_name, context)
|
||||||
@@ -327,6 +407,7 @@ def edit_question(request, pk):
|
|||||||
try:
|
try:
|
||||||
question_data = json.loads(question.data) if question.data else {}
|
question_data = json.loads(question.data) if question.data else {}
|
||||||
question_type = question_data.get('type', 'multiple_choice')
|
question_type = question_data.get('type', 'multiple_choice')
|
||||||
|
question_image = question.image
|
||||||
|
|
||||||
# For true/false questions, get the correct answer from the options
|
# For true/false questions, get the correct answer from the options
|
||||||
if question_type == 'true_false':
|
if question_type == 'true_false':
|
||||||
@@ -371,6 +452,10 @@ def edit_question(request, pk):
|
|||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
question_text = request.POST.get('question', '')
|
question_text = request.POST.get('question', '')
|
||||||
|
try:
|
||||||
|
question_image = request.FILES['question_image']
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
# Handle different question types
|
# Handle different question types
|
||||||
if question_type == 'true_false':
|
if question_type == 'true_false':
|
||||||
@@ -412,6 +497,8 @@ def edit_question(request, pk):
|
|||||||
}
|
}
|
||||||
|
|
||||||
question.data = json.dumps(json_data)
|
question.data = json.dumps(json_data)
|
||||||
|
question.time_per_question = request.POST.get('time_per_question', '30')
|
||||||
|
question.image = question_image
|
||||||
question.save()
|
question.save()
|
||||||
#return modified(request, question.quiz_id.pk)
|
#return modified(request, question.quiz_id.pk)
|
||||||
return redirect('library:detail_quiz', pk=question.quiz_id.pk)
|
return redirect('library:detail_quiz', pk=question.quiz_id.pk)
|
||||||
@@ -421,7 +508,9 @@ def edit_question(request, pk):
|
|||||||
context = {
|
context = {
|
||||||
'question': {'data': question_data}, # Wrap in data structure expected by template
|
'question': {'data': question_data}, # Wrap in data structure expected by template
|
||||||
'quiz_id': question.quiz_id.pk,
|
'quiz_id': question.quiz_id.pk,
|
||||||
'quiz': question.quiz_id
|
'quiz': question.quiz_id,
|
||||||
|
'time_per_question': question.time_per_question,
|
||||||
|
'image': question_image,
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(request, template_name, context)
|
return render(request, template_name, context)
|
||||||
|
|||||||
@@ -9,75 +9,7 @@ from datetime import timedelta
|
|||||||
|
|
||||||
from play.models import QuizGame, QuizGameParticipant, QuizAnswer
|
from play.models import QuizGame, QuizGameParticipant, QuizAnswer
|
||||||
|
|
||||||
# Dictionary to track inactive check tasks per game
|
|
||||||
game_check_tasks = {}
|
|
||||||
|
|
||||||
|
|
||||||
class GameConsumer(AsyncWebsocketConsumer):
|
class GameConsumer(AsyncWebsocketConsumer):
|
||||||
@classmethod
|
|
||||||
async def start_inactive_check(cls, join_code, channel_layer):
|
|
||||||
"""Start the inactive player check for a game if not already running."""
|
|
||||||
if join_code not in game_check_tasks or game_check_tasks[join_code].done():
|
|
||||||
async def check_inactive_players():
|
|
||||||
game_group_name = f'game_{join_code}'
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
await asyncio.sleep(30) # Check every 30 seconds
|
|
||||||
try:
|
|
||||||
game = await database_sync_to_async(QuizGame.objects.get)(join_code=join_code)
|
|
||||||
cutoff_time = timezone.now() - timedelta(minutes=1)
|
|
||||||
|
|
||||||
# Get active and inactive participants
|
|
||||||
all_participants = await database_sync_to_async(lambda: list(
|
|
||||||
game.participants.all().values('participant_id', 'display_name', 'last_heartbeat')
|
|
||||||
))()
|
|
||||||
|
|
||||||
# Konvertiere datetime zu ISO Format String
|
|
||||||
for p in all_participants:
|
|
||||||
if p['last_heartbeat']:
|
|
||||||
p['last_heartbeat'] = p['last_heartbeat'].isoformat()
|
|
||||||
|
|
||||||
active_participants = [p for p in all_participants if p['last_heartbeat'] and timezone.datetime.fromisoformat(p['last_heartbeat']) >= cutoff_time]
|
|
||||||
inactive_participants = [p for p in all_participants if not p['last_heartbeat'] or timezone.datetime.fromisoformat(p['last_heartbeat']) < cutoff_time]
|
|
||||||
|
|
||||||
# Remove inactive participants
|
|
||||||
if inactive_participants:
|
|
||||||
for p in inactive_participants:
|
|
||||||
# Benachrichtige andere über den gekickten Spieler
|
|
||||||
await channel_layer.group_send(
|
|
||||||
game_group_name,
|
|
||||||
{
|
|
||||||
'type': 'player_left',
|
|
||||||
'player_name': p['display_name'],
|
|
||||||
'was_kicked': True
|
|
||||||
}
|
|
||||||
)
|
|
||||||
# Lösche den inaktiven Teilnehmer
|
|
||||||
await database_sync_to_async(QuizGameParticipant.objects.filter(
|
|
||||||
participant_id=p['participant_id']
|
|
||||||
).delete)()
|
|
||||||
|
|
||||||
# Broadcast update to all clients
|
|
||||||
if active_participants or inactive_participants:
|
|
||||||
await channel_layer.group_send(
|
|
||||||
game_group_name,
|
|
||||||
{
|
|
||||||
'type': 'participant_list_update',
|
|
||||||
'participants': active_participants
|
|
||||||
}
|
|
||||||
)
|
|
||||||
except QuizGame.DoesNotExist:
|
|
||||||
break # Stop checking if game no longer exists
|
|
||||||
except Exception as e:
|
|
||||||
print(f'Error checking inactive players in game: {e}')
|
|
||||||
await asyncio.sleep(5) # Wait before retry
|
|
||||||
except asyncio.CancelledError:
|
|
||||||
break
|
|
||||||
except Exception as e:
|
|
||||||
print(f'Error in game inactive check loop: {e}')
|
|
||||||
await asyncio.sleep(5)
|
|
||||||
|
|
||||||
game_check_tasks[join_code] = asyncio.create_task(check_inactive_players())
|
|
||||||
|
|
||||||
async def connect(self):
|
async def connect(self):
|
||||||
self.join_code = self.scope['url_route']['kwargs']['join_code']
|
self.join_code = self.scope['url_route']['kwargs']['join_code']
|
||||||
@@ -91,9 +23,6 @@ class GameConsumer(AsyncWebsocketConsumer):
|
|||||||
|
|
||||||
await self.accept()
|
await self.accept()
|
||||||
|
|
||||||
# Ensure inactive check is running for this game
|
|
||||||
await self.start_inactive_check(self.join_code, self.channel_layer)
|
|
||||||
|
|
||||||
async def disconnect(self, close_code):
|
async def disconnect(self, close_code):
|
||||||
# Leave game group
|
# Leave game group
|
||||||
await self.channel_layer.group_discard(
|
await self.channel_layer.group_discard(
|
||||||
@@ -146,21 +75,6 @@ class GameConsumer(AsyncWebsocketConsumer):
|
|||||||
pass
|
pass
|
||||||
return
|
return
|
||||||
|
|
||||||
if message_type == 'heartbeat':
|
|
||||||
participant_id = text_data_json.get('participant_id')
|
|
||||||
if participant_id:
|
|
||||||
await self.update_participant_heartbeat(participant_id)
|
|
||||||
# Update participants list after heartbeat
|
|
||||||
participants = await self.get_participants()
|
|
||||||
await self.channel_layer.group_send(
|
|
||||||
self.game_group_name,
|
|
||||||
{
|
|
||||||
'type': 'participant_list_update',
|
|
||||||
'participants': participants
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
if message_type == 'submit_rating':
|
if message_type == 'submit_rating':
|
||||||
participant_id = text_data_json['participant_id']
|
participant_id = text_data_json['participant_id']
|
||||||
rating = text_data_json['rating']
|
rating = text_data_json['rating']
|
||||||
@@ -250,17 +164,6 @@ class GameConsumer(AsyncWebsocketConsumer):
|
|||||||
'redirect_url': event.get('redirect_url')
|
'redirect_url': event.get('redirect_url')
|
||||||
}))
|
}))
|
||||||
|
|
||||||
async def update_participant_heartbeat(self, participant_id):
|
|
||||||
"""Update the last heartbeat timestamp for a participant."""
|
|
||||||
try:
|
|
||||||
participant = await database_sync_to_async(QuizGameParticipant.objects.get)(
|
|
||||||
participant_id=participant_id
|
|
||||||
)
|
|
||||||
participant.last_heartbeat = timezone.now()
|
|
||||||
await database_sync_to_async(participant.save)()
|
|
||||||
except QuizGameParticipant.DoesNotExist:
|
|
||||||
pass
|
|
||||||
|
|
||||||
@database_sync_to_async
|
@database_sync_to_async
|
||||||
def verify_host(self, host_id):
|
def verify_host(self, host_id):
|
||||||
try:
|
try:
|
||||||
@@ -369,20 +272,16 @@ class GameConsumer(AsyncWebsocketConsumer):
|
|||||||
try:
|
try:
|
||||||
game = QuizGame.objects.get(join_code=self.join_code)
|
game = QuizGame.objects.get(join_code=self.join_code)
|
||||||
|
|
||||||
# Get all active participants (heartbeat within last minute)
|
|
||||||
from django.utils import timezone
|
|
||||||
active_participants = QuizGameParticipant.objects.filter(
|
active_participants = QuizGameParticipant.objects.filter(
|
||||||
quiz_game=game,
|
quiz_game=game
|
||||||
last_heartbeat__gte=timezone.now() - timezone.timedelta(minutes=1)
|
|
||||||
).count()
|
).count()
|
||||||
|
|
||||||
# If no active participants and game is finished for more than 5 minutes, delete it
|
if active_participants == 0:
|
||||||
if active_participants == 0 and game.current_state == 'finished':
|
|
||||||
if game.question_start_time and (timezone.now() - game.question_start_time).total_seconds() > 300:
|
|
||||||
game.delete()
|
game.delete()
|
||||||
except QuizGame.DoesNotExist:
|
except QuizGame.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@database_sync_to_async
|
@database_sync_to_async
|
||||||
def get_participants(self):
|
def get_participants(self):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -3,53 +3,15 @@ import json
|
|||||||
import asyncio
|
import asyncio
|
||||||
from ..models import QuizGame, QuizGameParticipant
|
from ..models import QuizGame, QuizGameParticipant
|
||||||
from channels.db import database_sync_to_async
|
from channels.db import database_sync_to_async
|
||||||
|
import redis
|
||||||
|
|
||||||
# Dictionary to track inactive check tasks and active connections per game
|
# Dictionary to track inactive check tasks and active connections per game
|
||||||
game_check_tasks = {}
|
game_check_tasks = {}
|
||||||
game_connections = {}
|
game_connections = {}
|
||||||
|
|
||||||
class LobbyConsumer(AsyncWebsocketConsumer):
|
class LobbyConsumer(AsyncWebsocketConsumer):
|
||||||
@classmethod
|
|
||||||
async def start_inactive_check(cls, join_code, channel_layer):
|
|
||||||
"""Start the inactive player check for a game if not already running."""
|
|
||||||
if join_code not in game_check_tasks or game_check_tasks[join_code].done():
|
|
||||||
async def check_inactive_players():
|
|
||||||
room_group_name = f'lobby_{join_code}'
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
await asyncio.sleep(10) # Check every 10 seconds to match frontend heartbeat
|
|
||||||
# Get participants list and broadcast update
|
|
||||||
try:
|
|
||||||
from django.utils import timezone
|
|
||||||
from datetime import timedelta
|
|
||||||
game = await database_sync_to_async(QuizGame.objects.get)(join_code=join_code)
|
|
||||||
cutoff_time = timezone.now() - timedelta(seconds=20) # Consider inactive after 20 seconds (2 missed heartbeats)
|
|
||||||
# Get current active participants with full info
|
|
||||||
active_participants = await database_sync_to_async(lambda: list(
|
|
||||||
game.participants.filter(last_heartbeat__gte=cutoff_time)
|
|
||||||
.values('participant_id', 'display_name')
|
|
||||||
))()
|
|
||||||
|
|
||||||
# Send update to all clients
|
r = redis.Redis(host='localhost', port=6379, db=0, decode_responses=True)
|
||||||
await channel_layer.group_send(
|
|
||||||
room_group_name,
|
|
||||||
{
|
|
||||||
'type': 'participants_list_update',
|
|
||||||
'participants': active_participants
|
|
||||||
}
|
|
||||||
)
|
|
||||||
except QuizGame.DoesNotExist:
|
|
||||||
break # Stop checking if game no longer exists
|
|
||||||
except Exception as e:
|
|
||||||
print(f'Error checking inactive players: {e}')
|
|
||||||
await asyncio.sleep(5) # Wait before retry
|
|
||||||
except asyncio.CancelledError:
|
|
||||||
break
|
|
||||||
except Exception as e:
|
|
||||||
print(f'Error in inactive check loop: {e}')
|
|
||||||
await asyncio.sleep(5)
|
|
||||||
|
|
||||||
game_check_tasks[join_code] = asyncio.create_task(check_inactive_players())
|
|
||||||
|
|
||||||
async def connect(self):
|
async def connect(self):
|
||||||
self.join_code = self.scope['url_route']['kwargs']['join_code']
|
self.join_code = self.scope['url_route']['kwargs']['join_code']
|
||||||
@@ -63,9 +25,6 @@ class LobbyConsumer(AsyncWebsocketConsumer):
|
|||||||
game_connections[self.join_code] = set()
|
game_connections[self.join_code] = set()
|
||||||
game_connections[self.join_code].add(self.channel_name)
|
game_connections[self.join_code].add(self.channel_name)
|
||||||
|
|
||||||
# Start inactive check task if not already running
|
|
||||||
await self.start_inactive_check(self.join_code, self.channel_layer)
|
|
||||||
|
|
||||||
# Join room group
|
# Join room group
|
||||||
await self.channel_layer.group_add(
|
await self.channel_layer.group_add(
|
||||||
self.room_group_name,
|
self.room_group_name,
|
||||||
@@ -107,11 +66,6 @@ class LobbyConsumer(AsyncWebsocketConsumer):
|
|||||||
}))
|
}))
|
||||||
return
|
return
|
||||||
|
|
||||||
if message_type == 'heartbeat':
|
|
||||||
participant_id = data.get('participant_id')
|
|
||||||
if participant_id:
|
|
||||||
await self.update_participant_heartbeat(participant_id)
|
|
||||||
# Don't update participants list after heartbeat - let the background task handle it
|
|
||||||
elif message_type in ['leave_game', 'kick_player']:
|
elif message_type in ['leave_game', 'kick_player']:
|
||||||
participant_id = data.get('participant_id')
|
participant_id = data.get('participant_id')
|
||||||
if participant_id:
|
if participant_id:
|
||||||
@@ -180,36 +134,32 @@ class LobbyConsumer(AsyncWebsocketConsumer):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@database_sync_to_async
|
|
||||||
def update_participant_heartbeat(self, participant_id):
|
|
||||||
try:
|
|
||||||
participant = QuizGameParticipant.objects.get(participant_id=participant_id)
|
|
||||||
from django.utils import timezone
|
|
||||||
participant.last_heartbeat = timezone.now()
|
|
||||||
participant.save()
|
|
||||||
return True
|
|
||||||
except QuizGameParticipant.DoesNotExist:
|
|
||||||
return False
|
|
||||||
|
|
||||||
async def get_participants_list(self):
|
async def get_participants_list(self):
|
||||||
try:
|
try:
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
game = await database_sync_to_async(QuizGame.objects.get)(join_code=self.join_code)
|
game = await database_sync_to_async(QuizGame.objects.get)(join_code=self.join_code)
|
||||||
# Only return participants that have been seen in the last minute
|
|
||||||
cutoff_time = timezone.now() - timedelta(seconds=20) # Consider inactive after 20 seconds (2 missed heartbeats)
|
|
||||||
participants = await database_sync_to_async(lambda: list(
|
participants = await database_sync_to_async(lambda: list(
|
||||||
game.participants.filter(last_heartbeat__gte=cutoff_time)
|
game.participants
|
||||||
.values('participant_id', 'display_name')
|
.values('participant_id', 'display_name')
|
||||||
))()
|
))()
|
||||||
|
|
||||||
|
|
||||||
# Send join notification for new participants
|
# Zustand laden
|
||||||
try:
|
try:
|
||||||
prev_names = set(p['display_name'] for p in self.last_participants) if hasattr(self, 'last_participants') else set()
|
r = redis.Redis(host='localhost', port=6379, db=0, decode_responses=True)
|
||||||
|
|
||||||
|
# Alte Teilnehmer aus Redis holen
|
||||||
|
data = r.get(f"last_participants_{self.room_group_name}")
|
||||||
|
prev_names = set(json.loads(data)) if data else set()
|
||||||
|
|
||||||
|
# Aktuelle Teilnehmer aus dem Argument extrahieren
|
||||||
current_names = set(p['display_name'] for p in participants)
|
current_names = set(p['display_name'] for p in participants)
|
||||||
|
|
||||||
|
# Neue Teilnehmer bestimmen
|
||||||
new_participants = current_names - prev_names
|
new_participants = current_names - prev_names
|
||||||
|
|
||||||
|
# Benachrichtigung für neue Teilnehmer versenden
|
||||||
for name in new_participants:
|
for name in new_participants:
|
||||||
await self.channel_layer.group_send(
|
await self.channel_layer.group_send(
|
||||||
self.room_group_name,
|
self.room_group_name,
|
||||||
@@ -218,9 +168,12 @@ class LobbyConsumer(AsyncWebsocketConsumer):
|
|||||||
'player_name': name
|
'player_name': name
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
except Exception as e:
|
|
||||||
print(f'Error sending join notifications: {e}')
|
|
||||||
|
|
||||||
|
# Teilnehmerliste in Redis aktualisieren
|
||||||
|
r.set(f"last_participants_{self.room_group_name}", json.dumps(list(current_names)))
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error in send_join_notifications: {e}")
|
||||||
self.last_participants = participants
|
self.last_participants = participants
|
||||||
return participants
|
return participants
|
||||||
except QuizGame.DoesNotExist:
|
except QuizGame.DoesNotExist:
|
||||||
|
|||||||
18
django/play/migrations/0011_quizgame_updated_at.py
Normal file
18
django/play/migrations/0011_quizgame_updated_at.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-04-21 11:27
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('play', '0010_alter_quizgameparticipant_last_heartbeat'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='quizgame',
|
||||||
|
name='updated_at',
|
||||||
|
field=models.DateTimeField(auto_now=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -19,6 +19,7 @@ class QuizGame(models.Model):
|
|||||||
current_state = models.CharField(max_length=20, choices=GAME_STATES, default='lobby')
|
current_state = models.CharField(max_length=20, choices=GAME_STATES, default='lobby')
|
||||||
current_question_index = models.IntegerField(default=0)
|
current_question_index = models.IntegerField(default=0)
|
||||||
question_start_time = models.DateTimeField(null=True, blank=True)
|
question_start_time = models.DateTimeField(null=True, blank=True)
|
||||||
|
updated_at = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
if not self.join_code:
|
if not self.join_code:
|
||||||
|
|||||||
@@ -12,4 +12,6 @@ urlpatterns = [
|
|||||||
path('game/<str:join_code>/waiting', views.waiting_room, name='waiting'),
|
path('game/<str:join_code>/waiting', views.waiting_room, name='waiting'),
|
||||||
path('game/<str:join_code>/scores', views.scores, name='scores'),
|
path('game/<str:join_code>/scores', views.scores, name='scores'),
|
||||||
path('game/<str:join_code>/finished', views.finished, name='finished'),
|
path('game/<str:join_code>/finished', views.finished, name='finished'),
|
||||||
|
path('select_mode/<str:join_code>', views.select_mode, name='select_mode'),
|
||||||
|
path('selected_mode/<str:join_code>', views.selected_mode, name='selected_mode'),
|
||||||
]
|
]
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
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
|
||||||
@@ -7,8 +8,12 @@ from django.contrib import messages
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
def lobby(request, join_code):
|
def lobby(request, join_code):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
quiz_game = get_object_or_404(QuizGame, join_code=join_code)
|
quiz_game = get_object_or_404(QuizGame, join_code=join_code)
|
||||||
quiz = get_object_or_404(QivipQuiz, pk=quiz_game.quiz_id.id)
|
quiz = get_object_or_404(QivipQuiz, pk=quiz_game.quiz_id.id)
|
||||||
context = {
|
context = {
|
||||||
@@ -16,11 +21,19 @@ def lobby(request, join_code):
|
|||||||
'quiz_game': quiz_game,
|
'quiz_game': quiz_game,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
mode = request.GET.get('mode','default')
|
||||||
|
request.session['mode'] = mode
|
||||||
if "host_id" in request.COOKIES:
|
if "host_id" in request.COOKIES:
|
||||||
host_id = request.COOKIES['host_id']
|
host_id = request.COOKIES['host_id']
|
||||||
if host_id == quiz_game.host_id:
|
if host_id == quiz_game.host_id:
|
||||||
context['host_id'] = host_id
|
context['host_id'] = host_id
|
||||||
return render(request, 'play/lobby.html', context=context)
|
return render(request, 'play/lobby.html', context=context)
|
||||||
|
elif mode=="learn":
|
||||||
|
return redirect('play:create_participant', join_code=join_code)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if not "participant_id" in request.COOKIES:
|
if not "participant_id" in request.COOKIES:
|
||||||
return redirect('play:create_participant', join_code=join_code)
|
return redirect('play:create_participant', join_code=join_code)
|
||||||
@@ -38,9 +51,16 @@ def lobby(request, join_code):
|
|||||||
context['participant'] = participant
|
context['participant'] = participant
|
||||||
return render(request, 'play/lobby.html', context=context)
|
return render(request, 'play/lobby.html', context=context)
|
||||||
|
|
||||||
def create_participant(request, join_code):
|
def select_mode(request,join_code):
|
||||||
quiz_game = get_object_or_404(QuizGame, join_code=join_code)
|
return render(request, 'play/select_mode.html', {'join_code': join_code})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def create_participant(request, join_code):
|
||||||
|
mode = request.GET.get('mode','default')
|
||||||
|
request.session['mode'] = mode
|
||||||
|
quiz_game = get_object_or_404(QuizGame, join_code=join_code)
|
||||||
|
if mode!="learn":
|
||||||
if "participant_id" in request.COOKIES:
|
if "participant_id" in request.COOKIES:
|
||||||
# Prüfe ob der Teilnehmer noch existiert
|
# Prüfe ob der Teilnehmer noch existiert
|
||||||
participant_id = request.COOKIES['participant_id']
|
participant_id = request.COOKIES['participant_id']
|
||||||
@@ -76,8 +96,11 @@ def create_participant(request, join_code):
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
return render(request, 'play/initialize_participant.html', {'join_code': join_code})
|
return render(request, 'play/initialize_participant.html', {'join_code': join_code})
|
||||||
|
else:
|
||||||
|
messages.error(request, "Beitritt nicht möglich.")
|
||||||
|
return render(request, 'play/join_game.html')
|
||||||
def create_game(request, quiz_id):
|
def create_game(request, quiz_id):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
quiz = QivipQuiz.objects.get(id=quiz_id)
|
quiz = QivipQuiz.objects.get(id=quiz_id)
|
||||||
game = QuizGame()
|
game = QuizGame()
|
||||||
@@ -85,7 +108,8 @@ def create_game(request, quiz_id):
|
|||||||
game.host_id = game.generate_unique_id()
|
game.host_id = game.generate_unique_id()
|
||||||
game.save()
|
game.save()
|
||||||
|
|
||||||
response = HttpResponseRedirect(reverse('play:lobby', kwargs={'join_code': game.join_code}))
|
|
||||||
|
response = HttpResponseRedirect(reverse('play:select_mode', kwargs={'join_code': game.join_code}))
|
||||||
response.set_cookie('host_id', game.host_id, max_age=3600)
|
response.set_cookie('host_id', game.host_id, max_age=3600)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
@@ -146,9 +170,18 @@ def scores(request, join_code):
|
|||||||
current_question = questions[quiz_game.current_question_index]
|
current_question = questions[quiz_game.current_question_index]
|
||||||
question_data = json.loads(current_question.data)
|
question_data = json.loads(current_question.data)
|
||||||
|
|
||||||
|
try:
|
||||||
|
my_participant = request.session.get('my_participant-participant_id')
|
||||||
|
participant = QuizGameParticipant.objects.get(participant_id=my_participant)
|
||||||
|
my_participant=participant
|
||||||
|
except:
|
||||||
|
participant = QuizGameParticipant.objects.none()
|
||||||
|
|
||||||
return render(request, 'play/game/score_overview.html', {
|
return render(request, 'play/game/score_overview.html', {
|
||||||
'quiz_game': quiz_game,
|
'quiz_game': quiz_game,
|
||||||
'participants': participants,
|
'participants': participants,
|
||||||
|
'participant': participant,
|
||||||
|
'my_participant':my_participant,
|
||||||
'is_host': is_host,
|
'is_host': is_host,
|
||||||
'host_id': quiz_game.host_id if is_host else None,
|
'host_id': quiz_game.host_id if is_host else None,
|
||||||
'is_last_question': quiz_game.current_question_index + 1 >= len(questions),
|
'is_last_question': quiz_game.current_question_index + 1 >= len(questions),
|
||||||
@@ -210,10 +243,12 @@ def question(request, join_code):
|
|||||||
return render(request, 'play/game/question_host.html', {
|
return render(request, 'play/game/question_host.html', {
|
||||||
'quiz_game': quiz_game,
|
'quiz_game': quiz_game,
|
||||||
'question_data': question_data,
|
'question_data': question_data,
|
||||||
|
'current_question':current_question,
|
||||||
'host_id': quiz_game.host_id,
|
'host_id': quiz_game.host_id,
|
||||||
'start_time': int(quiz_game.question_start_time.timestamp() * 1000),
|
'start_time': int(quiz_game.question_start_time.timestamp() * 1000),
|
||||||
'question_index': quiz_game.current_question_index,
|
'question_index': quiz_game.current_question_index,
|
||||||
'total_questions': len(questions)
|
'total_questions': len(questions),
|
||||||
|
'question_image': current_question.image
|
||||||
})
|
})
|
||||||
|
|
||||||
# Handle participant view
|
# Handle participant view
|
||||||
@@ -223,16 +258,20 @@ def question(request, join_code):
|
|||||||
participant_id = request.COOKIES['participant_id']
|
participant_id = request.COOKIES['participant_id']
|
||||||
try:
|
try:
|
||||||
participant = QuizGameParticipant.objects.get(participant_id=participant_id)
|
participant = QuizGameParticipant.objects.get(participant_id=participant_id)
|
||||||
|
|
||||||
|
|
||||||
except QuizGameParticipant.DoesNotExist:
|
except QuizGameParticipant.DoesNotExist:
|
||||||
return redirect('play:create_participant', join_code=join_code)
|
return redirect('play:create_participant', join_code=join_code)
|
||||||
|
request.session['my_participant-participant_id'] = participant.participant_id
|
||||||
|
|
||||||
return render(request, 'play/game/question_participant.html', {
|
return render(request, 'play/game/question_participant.html', {
|
||||||
'quiz_game': quiz_game,
|
'quiz_game': quiz_game,
|
||||||
'question_data': question_data,
|
'question_data': question_data,
|
||||||
|
'current_question':current_question,
|
||||||
'participant': participant,
|
'participant': participant,
|
||||||
'start_time': int(quiz_game.question_start_time.timestamp() * 1000),
|
'start_time': int(quiz_game.question_start_time.timestamp() * 1000),
|
||||||
'question_index': quiz_game.current_question_index,
|
'question_index': quiz_game.current_question_index,
|
||||||
'total_questions': len(questions)
|
'total_questions': len(questions),
|
||||||
})
|
})
|
||||||
|
|
||||||
def waiting_room(request, join_code):
|
def waiting_room(request, join_code):
|
||||||
@@ -256,3 +295,42 @@ def waiting_room(request, join_code):
|
|||||||
'quiz_game': quiz_game,
|
'quiz_game': quiz_game,
|
||||||
'participant': participant
|
'participant': participant
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def selected_mode(request, join_code):
|
||||||
|
|
||||||
|
|
||||||
|
mode = request.GET.get('mode','default')
|
||||||
|
request.session['mode'] = mode
|
||||||
|
quiz_game = get_object_or_404(QuizGame, join_code=join_code)
|
||||||
|
quiz = get_object_or_404(QivipQuiz, pk=quiz_game.quiz_id.id)
|
||||||
|
QuizGameParticipant.objects.filter(quiz_game=quiz_game).delete()
|
||||||
|
|
||||||
|
context = {
|
||||||
|
'quiz': quiz,
|
||||||
|
'quiz_game': quiz_game,
|
||||||
|
}
|
||||||
|
if "host_id" in request.COOKIES:
|
||||||
|
host_id = request.COOKIES['host_id']
|
||||||
|
if host_id == quiz_game.host_id:
|
||||||
|
context['host_id'] = host_id
|
||||||
|
|
||||||
|
if mode=="learn":
|
||||||
|
participant = QuizGameParticipant()
|
||||||
|
if request.user.is_authenticated:
|
||||||
|
participant.display_name = request.user.username
|
||||||
|
else:
|
||||||
|
participant.display_name = "SIE"
|
||||||
|
|
||||||
|
participant.participant_id=host_id
|
||||||
|
participant.quiz_game = quiz_game
|
||||||
|
participant.score = 0 # Initialize score
|
||||||
|
participant.save()
|
||||||
|
quiz_game.current_state = "question"
|
||||||
|
quiz_game.question_start_time = timezone.now()
|
||||||
|
quiz_game.save()
|
||||||
|
|
||||||
|
return redirect('play:question',join_code)
|
||||||
|
|
||||||
|
|
||||||
|
return render(request, 'play/lobby.html', context=context)
|
||||||
|
|||||||
@@ -66,6 +66,8 @@
|
|||||||
}, duration);
|
}, duration);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
if (window.location.pathname !== "/library/") {
|
||||||
|
localStorage.setItem("meine_seite_scroll", 0);}
|
||||||
</script>
|
</script>
|
||||||
{% block extra_js %}{% endblock %}
|
{% block extra_js %}{% endblock %}
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -22,8 +22,9 @@
|
|||||||
<path stroke-linecap="round" stroke-linejoin="round" d="m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0" />
|
<path stroke-linecap="round" stroke-linejoin="round" d="m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0" />
|
||||||
</svg>
|
</svg>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="flex flex-wrap gap-2">
|
<div class="flex flex-wrap gap-2">
|
||||||
<a href="{% url 'library:copy_quiz' quiz.id %}"
|
<a href="{% url 'library:copy_quiz' quiz.id %}"
|
||||||
class="inline-flex items-center gap-2 px-4 py-2 bg-blue-600 text-white text-sm font-medium rounded-lg hover:bg-blue-700 transition-colors duration-200">
|
class="inline-flex items-center gap-2 px-4 py-2 bg-blue-600 text-white text-sm font-medium rounded-lg hover:bg-blue-700 transition-colors duration-200">
|
||||||
@@ -34,6 +35,7 @@
|
|||||||
Quiz kopieren
|
Quiz kopieren
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
{% if quiz.questions.count != 0 %}
|
||||||
<a href="{% url 'play:create_game' quiz.id %}"
|
<a href="{% url 'play:create_game' quiz.id %}"
|
||||||
class="inline-flex items-center gap-2 px-4 py-2 bg-blue-600 text-white text-sm font-medium rounded-lg hover:bg-blue-700 transition-colors duration-200">
|
class="inline-flex items-center gap-2 px-4 py-2 bg-blue-600 text-white text-sm font-medium rounded-lg hover:bg-blue-700 transition-colors duration-200">
|
||||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
@@ -44,6 +46,7 @@
|
|||||||
</svg>
|
</svg>
|
||||||
Spielen
|
Spielen
|
||||||
</a>
|
</a>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -51,23 +51,24 @@
|
|||||||
|
|
||||||
<div id="filterPanel" class="container mx-auto px-4">
|
<div id="filterPanel" class="container mx-auto px-4">
|
||||||
<div class="bg-white rounded-xl shadow-lg p-6 border border-gray-200">
|
<div class="bg-white rounded-xl shadow-lg p-6 border border-gray-200">
|
||||||
<form method="get" class="grid grid-cols-1 md:grid-cols-3 gap-6">
|
<form action="{% url 'library:overview_quiz' %}" method="get" class="grid grid-cols-1 md:grid-cols-3 gap-6">
|
||||||
|
<input type="hidden" name="filter" value="1">
|
||||||
<div class="space-y-2">
|
<div class="space-y-2">
|
||||||
<label class="block text-sm font-medium text-gray-700">Minimale Fragen</label>
|
<label class="block text-sm font-medium text-gray-700">minimale Anzahl an Fragen</label>
|
||||||
{{ form.min_amout_questions }}
|
<input type="number" name="min_amout_questions" class="border-2 border-gray-300 rounded-lg p-2 w-full" min="1" id="id_min_amout_questions">
|
||||||
</div>
|
</div>
|
||||||
<div class="space-y-2">
|
<div class="space-y-2">
|
||||||
<label class="block text-sm font-medium text-gray-700">Maximale Fragen</label>
|
<label class="block text-sm font-medium text-gray-700">maximale Anzahl an Fragen</label>
|
||||||
{{ form.max_amout_questions }}
|
<input type="number" name="max_amout_questions" class="border-2 border-gray-300 rounded-lg p-2 w-full" min="1" id="id_max_amout_questions">
|
||||||
</div>
|
</div>
|
||||||
<div class="space-y-2">
|
<div class="space-y-2">
|
||||||
<label class="block text-sm font-medium text-gray-700">Von User</label>
|
<label class="block text-sm font-medium text-gray-700">veröffentlicht von User</label>
|
||||||
{{ form.user }}
|
<input type="text" name="user" class="border-2 border-gray-300 rounded-lg p-2 w-full" id="id_user">
|
||||||
</div>
|
</div>
|
||||||
<div class="md:col-span-3 flex justify-end">
|
<div class="md:col-span-3 flex justify-end">
|
||||||
<button type="submit" class="inline-flex items-center px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors duration-200">
|
<button type="submit" class="inline-flex items-center px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors duration-200">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z" />
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"></path>
|
||||||
</svg>
|
</svg>
|
||||||
Filtern
|
Filtern
|
||||||
</button>
|
</button>
|
||||||
@@ -77,6 +78,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<div class="container mx-auto px-4 sm:px-6 lg:px-8 mt-8 mb-6">
|
<div class="container mx-auto px-4 sm:px-6 lg:px-8 mt-8 mb-6">
|
||||||
<div class="flex items-center gap-3">
|
<div class="flex items-center gap-3">
|
||||||
@@ -92,13 +94,42 @@
|
|||||||
<!-- Image Section (Top) -->
|
<!-- Image Section (Top) -->
|
||||||
<div class="h-48 w-full relative flex-shrink-0">
|
<div class="h-48 w-full relative flex-shrink-0">
|
||||||
{% if quiz.image %}
|
{% if quiz.image %}
|
||||||
<div class="absolute inset-0 bg-cover bg-center" style="background-image: url({{ quiz.image.url }});"></div>
|
<div class="relative w-full h-full inset-0 bg-cover bg-center">
|
||||||
|
<!-- Hintergrundbild -->
|
||||||
|
<div class="absolute inset-0 bg-cover bg-center"
|
||||||
|
style="background-image: url({{ quiz.image.url }});">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="h-full bg-gradient-to-r from-blue-500 to-blue-600"></div>
|
<div class="h-full bg-gradient-to-r from-blue-500 to-blue-600"></div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if user.is_authenticated %}
|
||||||
|
{% if quiz.id not in favorite_quiz_ids %}
|
||||||
|
<div class="absolute top-4 right-4 bg-white bg-opacity-60 text-white px-4 py-2 rounded-lg shadow-lg">
|
||||||
|
|
||||||
|
<a href="{% url 'library:favorite_quiz' quiz.pk %}">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="text-black size-6">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="M11.48 3.499a.562.562 0 0 1 1.04 0l2.125 5.111a.563.563 0 0 0 .475.345l5.518.442c.499.04.701.663.321.988l-4.204 3.602a.563.563 0 0 0-.182.557l1.285 5.385a.562.562 0 0 1-.84.61l-4.725-2.885a.562.562 0 0 0-.586 0L6.982 20.54a.562.562 0 0 1-.84-.61l1.285-5.386a.562.562 0 0 0-.182-.557l-4.204-3.602a.562.562 0 0 1 .321-.988l5.518-.442a.563.563 0 0 0 .475-.345L11.48 3.5Z" />
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% else %}
|
||||||
|
<div class="absolute top-4 right-4 bg-white bg-opacity-60 text-white px-4 py-2 rounded-lg shadow-lg">
|
||||||
|
<a href="{% url 'library:favorite_quiz' quiz.pk %}">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="text-yellow-400 size-6">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="M11.48 3.499a.562.562 0 0 1 1.04 0l2.125 5.111a.563.563 0 0 0 .475.345l5.518.442c.499.04.701.663.321.988l-4.204 3.602a.563.563 0 0 0-.182.557l1.285 5.385a.562.562 0 0 1-.84.61l-4.725-2.885a.562.562 0 0 0-.586 0L6.982 20.54a.562.562 0 0 1-.84-.61l1.285-5.386a.562.562 0 0 0-.182-.557l-4.204-3.602a.562.562 0 0 1 .321-.988l5.518-.442a.563.563 0 0 0 .475-.345L11.48 3.5Z" />
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Content Section (Bottom) -->
|
<!-- Content Section (Bottom) -->
|
||||||
<div class="flex-grow bg-white p-4 flex flex-col gap-3">
|
<div class="flex-grow bg-white p-4 flex flex-col gap-3">
|
||||||
<!-- Title -->
|
<!-- Title -->
|
||||||
@@ -163,6 +194,7 @@
|
|||||||
|
|
||||||
<!-- Action Buttons -->
|
<!-- Action Buttons -->
|
||||||
<div class="flex justify-between items-center gap-2 mt-3 border-t pt-3">
|
<div class="flex justify-between items-center gap-2 mt-3 border-t pt-3">
|
||||||
|
{% if quiz.questions.count != 0 %}
|
||||||
<a href="{% url 'play:create_game' quiz.id %}"
|
<a href="{% url 'play:create_game' quiz.id %}"
|
||||||
class="px-3 py-1.5 bg-blue-600 hover:bg-blue-700 text-white text-sm font-medium rounded-lg transition-colors duration-200 flex items-center gap-2">
|
class="px-3 py-1.5 bg-blue-600 hover:bg-blue-700 text-white text-sm font-medium rounded-lg transition-colors duration-200 flex items-center gap-2">
|
||||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
@@ -171,6 +203,9 @@
|
|||||||
</svg>
|
</svg>
|
||||||
Spielen
|
Spielen
|
||||||
</a>
|
</a>
|
||||||
|
{% else %}
|
||||||
|
Fürs Spielen ist min. 1 Frage nötig!
|
||||||
|
{% endif %}
|
||||||
<div class="flex gap-1">
|
<div class="flex gap-1">
|
||||||
<a href="{% url 'library:detail_quiz' quiz.id %}"
|
<a href="{% url 'library:detail_quiz' quiz.id %}"
|
||||||
class="p-1.5 bg-gray-100 hover:bg-gray-200 text-gray-700 rounded-lg transition-colors duration-200">
|
class="p-1.5 bg-gray-100 hover:bg-gray-200 text-gray-700 rounded-lg transition-colors duration-200">
|
||||||
@@ -179,7 +214,7 @@
|
|||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" />
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" />
|
||||||
</svg>
|
</svg>
|
||||||
</a>
|
</a>
|
||||||
{% if quiz.user == request.user %}
|
{% if quiz.user_id == request.user %}
|
||||||
<a href="{% url 'library:edit_quiz' quiz.id %}"
|
<a href="{% url 'library:edit_quiz' quiz.id %}"
|
||||||
class="p-1.5 bg-gray-100 hover:bg-gray-200 text-gray-700 rounded-lg transition-colors duration-200">
|
class="p-1.5 bg-gray-100 hover:bg-gray-200 text-gray-700 rounded-lg transition-colors duration-200">
|
||||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
@@ -228,6 +263,203 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{% if user.is_authenticated %}
|
||||||
|
<div class="container mx-auto px-4 sm:px-6 lg:px-8 mt-8 mb-6">
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<h2 id="my-quizzes" class="text-2xl font-bold text-gray-900">Meine Favoriten</h2>
|
||||||
|
<div class="h-0.5 flex-grow bg-gradient-to-r from-blue-600 to-transparent rounded-full"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container mx-auto px-4 sm:px-6 lg:px-8">
|
||||||
|
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6 auto-rows-fr">
|
||||||
|
{% for quiz in favorite_quizzes %}
|
||||||
|
<article class="relative min-h-[20rem] rounded-xl shadow-lg overflow-hidden bg-white flex flex-col">
|
||||||
|
<!-- Image Section (Top) -->
|
||||||
|
<div class="h-48 w-full relative flex-shrink-0">
|
||||||
|
{% if quiz.image %}
|
||||||
|
<div class="relative w-full h-full inset-0 bg-cover bg-center">
|
||||||
|
<!-- Hintergrundbild -->
|
||||||
|
<div class="absolute inset-0 bg-cover bg-center"
|
||||||
|
style="background-image: url({{ quiz.image.url }});">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
{% else %}
|
||||||
|
<div class="h-full bg-gradient-to-r from-blue-500 to-blue-600"></div>
|
||||||
|
{% endif %}
|
||||||
|
{% if user.is_authenticated %}
|
||||||
|
{% if quiz.favorite == False %}
|
||||||
|
|
||||||
|
<div class="absolute top-4 right-4 bg-white bg-opacity-60 text-white px-4 py-2 rounded-lg shadow-lg">
|
||||||
|
|
||||||
|
<a href="{% url 'library:favorite_quiz' quiz.pk %}">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="text-black size-6">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="M11.48 3.499a.562.562 0 0 1 1.04 0l2.125 5.111a.563.563 0 0 0 .475.345l5.518.442c.499.04.701.663.321.988l-4.204 3.602a.563.563 0 0 0-.182.557l1.285 5.385a.562.562 0 0 1-.84.61l-4.725-2.885a.562.562 0 0 0-.586 0L6.982 20.54a.562.562 0 0 1-.84-.61l1.285-5.386a.562.562 0 0 0-.182-.557l-4.204-3.602a.562.562 0 0 1 .321-.988l5.518-.442a.563.563 0 0 0 .475-.345L11.48 3.5Z" />
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% else %}
|
||||||
|
<div class="absolute top-4 right-4 bg-white bg-opacity-60 text-white px-4 py-2 rounded-lg shadow-lg">
|
||||||
|
<a href="{% url 'library:favorite_quiz' quiz.pk %}">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="text-yellow-400 size-6">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="M11.48 3.499a.562.562 0 0 1 1.04 0l2.125 5.111a.563.563 0 0 0 .475.345l5.518.442c.499.04.701.663.321.988l-4.204 3.602a.563.563 0 0 0-.182.557l1.285 5.385a.562.562 0 0 1-.84.61l-4.725-2.885a.562.562 0 0 0-.586 0L6.982 20.54a.562.562 0 0 1-.84-.61l1.285-5.386a.562.562 0 0 0-.182-.557l-4.204-3.602a.562.562 0 0 1 .321-.988l5.518-.442a.563.563 0 0 0 .475-.345L11.48 3.5Z" />
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Content Section (Bottom) -->
|
||||||
|
<div class="flex-grow bg-white p-4 flex flex-col gap-3">
|
||||||
|
<!-- Title -->
|
||||||
|
<h2 class="text-xl font-bold text-gray-900 break-words mb-2">
|
||||||
|
<a href="{% url 'library:detail_quiz' quiz.id %}" class="hover:text-blue-600 transition-colors">{{ quiz.name }}</a>
|
||||||
|
</h2>
|
||||||
|
<!-- Description -->
|
||||||
|
<p class="text-sm text-gray-700 break-words mb-3">{{ quiz.description }}</p>
|
||||||
|
|
||||||
|
<!-- Quiz Info Grid -->
|
||||||
|
<div class="grid grid-cols-2 gap-x-4 gap-y-3 text-sm">
|
||||||
|
<!-- Difficulty -->
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<svg class="w-4 h-4 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z" />
|
||||||
|
</svg>
|
||||||
|
<span class="text-gray-800">{{ quiz.difficulty }}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Questions Count -->
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<svg class="w-4 h-4 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||||
|
</svg>
|
||||||
|
<span class="text-gray-800">{{ quiz.questions.count }} Fragen</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Status -->
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<svg class="w-4 h-4 text-purple-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||||
|
</svg>
|
||||||
|
<span class="text-gray-800">{{ quiz.status }}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Rating -->
|
||||||
|
<div class="flex items-center gap-1">
|
||||||
|
{% for i in '12345'|make_list %}
|
||||||
|
{% if forloop.counter <= quiz.average_rating|floatformat:0|add:0 %}
|
||||||
|
<span class="text-yellow-500 text-base">★</span>
|
||||||
|
{% else %}
|
||||||
|
<span class="text-gray-300 text-base">★</span>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
<span class="text-gray-600 text-sm">({{ quiz.rating_count }})</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Authors -->
|
||||||
|
{% if quiz.authors.all %}
|
||||||
|
<div class="flex items-center gap-2 text-sm mt-2">
|
||||||
|
<svg class="w-4 h-4 text-gray-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />
|
||||||
|
</svg>
|
||||||
|
<span class="text-gray-600">
|
||||||
|
{% for author in quiz.authors.all %}
|
||||||
|
{{ author.username }}{% if not forloop.last %}, {% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<!-- Action Buttons -->
|
||||||
|
<div class="flex justify-between items-center gap-2 mt-3 border-t pt-3">
|
||||||
|
{% if quiz.questions.count != 0 %}
|
||||||
|
<a href="{% url 'play:create_game' quiz.id %}"
|
||||||
|
class="px-3 py-1.5 bg-blue-600 hover:bg-blue-700 text-white text-sm font-medium rounded-lg transition-colors duration-200 flex items-center gap-2">
|
||||||
|
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z" />
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||||
|
</svg>
|
||||||
|
Spielen
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
Fürs Spielen ist min. 1 Frage nötig!
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<div class="flex gap-1">
|
||||||
|
<a href="{% url 'library:detail_quiz' quiz.id %}"
|
||||||
|
class="p-1.5 bg-gray-100 hover:bg-gray-200 text-gray-700 rounded-lg transition-colors duration-200">
|
||||||
|
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" />
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
{% if quiz.user_id == request.user %}
|
||||||
|
<a href="{% url 'library:edit_quiz' quiz.id %}"
|
||||||
|
class="p-1.5 bg-gray-100 hover:bg-gray-200 text-gray-700 rounded-lg transition-colors duration-200">
|
||||||
|
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
<a href="{% url 'library:delete_quiz' quiz.id %}"
|
||||||
|
class="p-1.5 bg-red-100 hover:bg-red-200 text-red-700 rounded-lg transition-colors duration-200">
|
||||||
|
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Pagination für eigene Quiz -->
|
||||||
|
{% if favorite_quizzes.paginator.num_pages > 1 %}
|
||||||
|
<div class="flex justify-center space-x-2 mt-6 mb-8">
|
||||||
|
{% if favorite_quizzes.has_previous %}
|
||||||
|
<a href="?my_page={{ my_quizzes.previous_page_number }}{% if request.GET.other_page %}&other_page={{ request.GET.other_page }}{% endif %}{% if request.GET.search %}&search={{ request.GET.search }}{% endif %}"
|
||||||
|
class="px-3 py-1 bg-gray-100 text-gray-700 hover:bg-gray-200 rounded-lg transition-colors">
|
||||||
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" />
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<span class="px-3 py-1 text-gray-600">Seite {{ favorite_quizzes.number }} von {{ favorite_quizzes.paginator.num_pages }}</span>
|
||||||
|
|
||||||
|
{% if my_quizzes.has_next %}
|
||||||
|
<a href="?my_page={{ my_quizzes.next_page_number }}{% if request.GET.other_page %}&other_page={{ request.GET.other_page }}{% endif %}{% if request.GET.search %}&search={{ request.GET.search }}{% endif %}"
|
||||||
|
class="px-3 py-1 bg-gray-100 text-gray-700 hover:bg-gray-200 rounded-lg transition-colors">
|
||||||
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" />
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Quiz von anderen Nutzern -->
|
<!-- Quiz von anderen Nutzern -->
|
||||||
<div class="container mx-auto px-4 sm:px-6 lg:px-8 mt-8 mb-6">
|
<div class="container mx-auto px-4 sm:px-6 lg:px-8 mt-8 mb-6">
|
||||||
<div class="flex items-center gap-3">
|
<div class="flex items-center gap-3">
|
||||||
@@ -244,11 +476,39 @@
|
|||||||
<!-- Image Section (Top) -->
|
<!-- Image Section (Top) -->
|
||||||
<div class="h-48 w-full relative flex-shrink-0">
|
<div class="h-48 w-full relative flex-shrink-0">
|
||||||
{% if quiz.image %}
|
{% if quiz.image %}
|
||||||
<div class="absolute inset-0 bg-cover bg-center" style="background-image: url({{ quiz.image.url }});"></div>
|
<div class="relative w-full h-full inset-0 bg-cover bg-center">
|
||||||
|
<!-- Hintergrundbild -->
|
||||||
|
<div class="absolute inset-0 bg-cover bg-center"
|
||||||
|
style="background-image: url({{ quiz.image.url }});">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="h-full bg-gradient-to-r from-blue-500 to-blue-600"></div>
|
<div class="h-full bg-gradient-to-r from-blue-500 to-blue-600"></div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if user.is_authenticated %}
|
||||||
|
{% if quiz.id not in favorite_quiz_ids %}
|
||||||
|
<div class="absolute top-4 right-4 bg-white bg-opacity-60 text-white px-4 py-2 rounded-lg shadow-lg">
|
||||||
|
|
||||||
|
<a href="{% url 'library:favorite_quiz' quiz.pk %}">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="text-black size-6">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="M11.48 3.499a.562.562 0 0 1 1.04 0l2.125 5.111a.563.563 0 0 0 .475.345l5.518.442c.499.04.701.663.321.988l-4.204 3.602a.563.563 0 0 0-.182.557l1.285 5.385a.562.562 0 0 1-.84.61l-4.725-2.885a.562.562 0 0 0-.586 0L6.982 20.54a.562.562 0 0 1-.84-.61l1.285-5.386a.562.562 0 0 0-.182-.557l-4.204-3.602a.562.562 0 0 1 .321-.988l5.518-.442a.563.563 0 0 0 .475-.345L11.48 3.5Z" />
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% else %}
|
||||||
|
<div class="absolute top-4 right-4 bg-white bg-opacity-60 text-white px-4 py-2 rounded-lg shadow-lg">
|
||||||
|
<a href="{% url 'library:favorite_quiz' quiz.pk %}">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="text-yellow-400 size-6">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="M11.48 3.499a.562.562 0 0 1 1.04 0l2.125 5.111a.563.563 0 0 0 .475.345l5.518.442c.499.04.701.663.321.988l-4.204 3.602a.563.563 0 0 0-.182.557l1.285 5.385a.562.562 0 0 1-.84.61l-4.725-2.885a.562.562 0 0 0-.586 0L6.982 20.54a.562.562 0 0 1-.84-.61l1.285-5.386a.562.562 0 0 0-.182-.557l-4.204-3.602a.562.562 0 0 1 .321-.988l5.518-.442a.563.563 0 0 0 .475-.345L11.48 3.5Z" />
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Content Section (Bottom) -->
|
<!-- Content Section (Bottom) -->
|
||||||
@@ -315,6 +575,7 @@
|
|||||||
|
|
||||||
<!-- Action Buttons -->
|
<!-- Action Buttons -->
|
||||||
<div class="flex justify-between items-center gap-2 mt-3 border-t pt-3">
|
<div class="flex justify-between items-center gap-2 mt-3 border-t pt-3">
|
||||||
|
{% if quiz.questions.count != 0 %}
|
||||||
<a href="{% url 'play:create_game' quiz.id %}"
|
<a href="{% url 'play:create_game' quiz.id %}"
|
||||||
class="px-3 py-1.5 bg-blue-600 hover:bg-blue-700 text-white text-sm font-medium rounded-lg transition-colors duration-200 flex items-center gap-2">
|
class="px-3 py-1.5 bg-blue-600 hover:bg-blue-700 text-white text-sm font-medium rounded-lg transition-colors duration-200 flex items-center gap-2">
|
||||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
@@ -323,6 +584,9 @@
|
|||||||
</svg>
|
</svg>
|
||||||
Spielen
|
Spielen
|
||||||
</a>
|
</a>
|
||||||
|
{% else %}
|
||||||
|
Fürs Spielen ist min. 1 Frage nötig!
|
||||||
|
{% endif %}
|
||||||
<div class="flex gap-1">
|
<div class="flex gap-1">
|
||||||
<a href="{% url 'library:detail_quiz' quiz.id %}"
|
<a href="{% url 'library:detail_quiz' quiz.id %}"
|
||||||
class="p-1.5 bg-gray-100 hover:bg-gray-200 text-gray-700 rounded-lg transition-colors duration-200">
|
class="p-1.5 bg-gray-100 hover:bg-gray-200 text-gray-700 rounded-lg transition-colors duration-200">
|
||||||
@@ -370,9 +634,39 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
if (urlParams.get('filter') === '1') {
|
||||||
|
document.getElementById('filterPanel').classList.add('show');
|
||||||
|
}
|
||||||
|
|
||||||
document.getElementById('filterButton').addEventListener('click', function() {
|
document.getElementById('filterButton').addEventListener('click', function() {
|
||||||
document.getElementById('filterPanel').classList.toggle('show');
|
document.getElementById('filterPanel').classList.toggle('show');
|
||||||
|
|
||||||
|
// URL beim Öffnen aktualisieren
|
||||||
|
const params = new URLSearchParams(window.location.search);
|
||||||
|
if (document.getElementById('filterPanel').classList.contains('show')) {
|
||||||
|
params.set('filter', '1');
|
||||||
|
} else {
|
||||||
|
params.delete('filter');
|
||||||
|
}
|
||||||
|
history.replaceState(null, '', `${location.pathname}?${params}`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
if (window.location.pathname === "/library/") {
|
||||||
|
window.addEventListener("beforeunload", function () {
|
||||||
|
localStorage.setItem("meine_seite_scroll", window.scrollY);
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener("load", function () {
|
||||||
|
const scrollPos = localStorage.getItem("meine_seite_scroll");
|
||||||
|
if (scrollPos !== null) {
|
||||||
|
window.scrollTo(0, parseInt(scrollPos));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|||||||
@@ -9,9 +9,8 @@
|
|||||||
Zurück zum Quiz
|
Zurück zum Quiz
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="bg-white rounded-lg shadow-md p-6 border-blue-600 border-2 rounded-xl shadow-md">
|
<div class="bg-white rounded-lg shadow-md p-6 border-blue-600 border-2 rounded-xl shadow-md">
|
||||||
<form method="post" class="space-y-6">
|
<form method="post" class="space-y-6" enctype="multipart/form-data">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
||||||
<!-- Question Text -->
|
<!-- Question Text -->
|
||||||
@@ -24,6 +23,15 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
{% if image %}
|
||||||
|
<img src="{{ image.url }}" style="max-width: 500px;" alt="Bild der Frage">
|
||||||
|
{% endif %}
|
||||||
|
<div>
|
||||||
|
<label class="font-bold" for="question_image">Bild:</label>
|
||||||
|
<input value="image.url" class="bg-blue-200 p-2 m-2 rounded-lg border-2 border-blue-400" type="file" name="question_image" id="question_image">
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Options -->
|
<!-- Options -->
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-sm font-medium text-gray-700 mb-2">Antwortmöglichkeiten</label>
|
<label class="block text-sm font-medium text-gray-700 mb-2">Antwortmöglichkeiten</label>
|
||||||
@@ -92,6 +100,19 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="p-4">
|
||||||
|
<label class="font-bold" for="time_per_question">Zeit pro Frage:</label>
|
||||||
|
<select name="time_per_question" id="time_per_question">
|
||||||
|
<option value="10" {% if standard_time_per_question == "10" or time_per_question == "10" %}selected{% endif %}>10 Sekunden</option>
|
||||||
|
<option value="20" {% if standard_time_per_question == "20" or time_per_question == "20" %}selected{% endif %}>20 Sekunden</option>
|
||||||
|
<option value="30" {% if standard_time_per_question == "30" or time_per_question == "30" %}selected{% endif %}>30 Sekunden</option>
|
||||||
|
<option value="45" {% if standard_time_per_question == "45" or time_per_question == "45" %}selected{% endif %}>45 Sekunden</option>
|
||||||
|
<option value="60" {% if standard_time_per_question == "60" or time_per_question == "60" %}selected{% endif %}>1 Minute</option>
|
||||||
|
<option value="120" {% if standard_time_per_question == "120" or time_per_question == "120" %}selected{% endif %}>2 Minuten</option>
|
||||||
|
<option value="300" {% if standard_time_per_question == "300" or time_per_question == "300" %}selected{% endif %}>5 Minuten</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="flex justify-end space-x-3">
|
<div class="flex justify-end space-x-3">
|
||||||
<a href="{% url 'library:detail_quiz' quiz.id %}"
|
<a href="{% url 'library:detail_quiz' quiz.id %}"
|
||||||
class="inline-flex items-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
|
class="inline-flex items-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="bg-white rounded-lg shadow-md p-6 border-blue-600 border-2 rounded-xl shadow-md">
|
<div class="bg-white rounded-lg shadow-md p-6 border-blue-600 border-2 rounded-xl shadow-md">
|
||||||
<form method="post" class="space-y-6">
|
<form method="post" class="space-y-6" enctype="multipart/form-data">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
||||||
<!-- Question Text -->
|
<!-- Question Text -->
|
||||||
@@ -24,6 +24,14 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% if image %}
|
||||||
|
<img src="{{ image.url }}" style="max-width: 500px;" alt="Bild der Frage">
|
||||||
|
{% endif %}
|
||||||
|
<div>
|
||||||
|
<label class="font-bold" for="question_image">Bild:</label>
|
||||||
|
<input class="bg-blue-200 p-2 m-2 rounded-lg border-2 border-blue-400" type="file" name="question_image" id="question_image">
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- True/False Selection -->
|
<!-- True/False Selection -->
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-sm font-medium text-gray-700 mb-2">Richtige Antwort</label>
|
<label class="block text-sm font-medium text-gray-700 mb-2">Richtige Antwort</label>
|
||||||
@@ -43,6 +51,19 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="p-4">
|
||||||
|
<label class="font-bold" for="time_per_question">Zeit pro Frage:</label>
|
||||||
|
<select name="time_per_question" id="time_per_question">
|
||||||
|
<option value="10" {% if standard_time_per_question == "10" or time_per_question == "10" %}selected{% endif %}>10 Sekunden</option>
|
||||||
|
<option value="20" {% if standard_time_per_question == "20" or time_per_question == "20" %}selected{% endif %}>20 Sekunden</option>
|
||||||
|
<option value="30" {% if standard_time_per_question == "30" or time_per_question == "30" %}selected{% endif %}>30 Sekunden</option>
|
||||||
|
<option value="45" {% if standard_time_per_question == "45" or time_per_question == "45" %}selected{% endif %}>45 Sekunden</option>
|
||||||
|
<option value="60" {% if standard_time_per_question == "60" or time_per_question == "60" %}selected{% endif %}>1 Minute</option>
|
||||||
|
<option value="120" {% if standard_time_per_question == "120" or time_per_question == "120" %}selected{% endif %}>2 Minuten</option>
|
||||||
|
<option value="300" {% if standard_time_per_question == "300" or time_per_question == "300" %}selected{% endif %}>5 Minuten</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="flex justify-end space-x-3">
|
<div class="flex justify-end space-x-3">
|
||||||
<a href="{% url 'library:detail_quiz' quiz.id %}"
|
<a href="{% url 'library:detail_quiz' quiz.id %}"
|
||||||
class="inline-flex items-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
|
class="inline-flex items-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
<nav class="flex justify-between items-center bg-blue-600 h-12 px-4 sm:px-6 lg:px-8 rounded-lg m-2 shadow-md overflow-x-auto whitespace-nowrap">
|
<nav class="flex justify-between items-center bg-blue-600 h-12 px-4 sm:px-6 rounded-lg mt-1 m-2 shadow-md overflow-x-auto whitespace-nowrap">
|
||||||
<div class="flex items-center flex-shrink-0">
|
<div class="flex items-center flex-shrink-0 md:w-32">
|
||||||
<h2 class="text-xl font-bold text-white hover:scale-110 transition duration-200 ">
|
<h2 class="text-xl font-bold text-white hover:scale-110 transition duration-200 ">
|
||||||
<a href="{% url 'homepage:home' %}">qivip</a>
|
<a href="{% url 'homepage:home' %}">qivip</a>
|
||||||
</h2>
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if show_search %}
|
<div class="flex justify-center items-center min-w-40">
|
||||||
<form method="get" class="mr-2 ml-2 flex items-center w-full max-w-sm bg-white rounded-full px-4 py-1 shadow-md">
|
<form method="get" action="{% url 'library:overview_quiz' %}" class="mr-2 ml-2 flex items-center justify-center w-screen max-w-sm bg-white rounded-full px-4 py-1 shadow-md">
|
||||||
<input type="text" name="search" placeholder="Suche ..." value="{{ request.GET.search }}"
|
<input type="text" name="search" placeholder="Suche ..." value="{{ request.GET.search }}"
|
||||||
class="w-full px-3 py-1 text-black bg-transparent focus:outline-none">
|
class=" text-sm w-full px-3 py-1 text-black bg-transparent focus:outline-none lg:text-base">
|
||||||
<button type="submit" class=" py-1 text-blue-600">
|
<button class="py-1 text-blue-600">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-5 md:size-6 ">
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" d="m21 21-5.197-5.197m0 0A7.5 7.5 0 1 0 5.196 5.196a7.5 7.5 0 0 0 10.607 10.607Z" />
|
<path stroke-linecap="round" stroke-linejoin="round" d="m21 21-5.197-5.197m0 0A7.5 7.5 0 1 0 5.196 5.196a7.5 7.5 0 0 0 10.607 10.607Z" />
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form></div>
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<div class="flex items-center space-x-4">
|
|
||||||
|
<div class="flex items-center space-x-4 md:w-40 ">
|
||||||
<ul class="flex space-x-4 qp-nav-list">
|
<ul class="flex space-x-4 qp-nav-list">
|
||||||
{% if show_search %}
|
{% if show_search %}
|
||||||
<li class="hidden md:flex"><a href="{% url 'library:overview_quiz' %}">Bibliothek</a></li>
|
<li class="hidden md:flex"><a href="{% url 'library:overview_quiz' %}">Bibliothek</a></li>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<div class="bg-white rounded-lg shadow-md p-8 mb-6">
|
<div class="bg-white rounded-lg shadow-md p-8 mb-6">
|
||||||
<div class="text-center mb-8">
|
<div class="text-center mb-8">
|
||||||
<h1 class="text-4xl font-bold text-blue-600 mb-4">Quiz beendet!</h1>
|
<h1 class="text-4xl font-bold text-blue-600 mb-4">Quiz beendet!</h1>
|
||||||
<p class="text-xl text-gray-600">Vielen Dank fürs Mitspielen!</p>
|
<p class="text-xl text-gray-600">Vielen Dank fürs Spielen!</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if not is_host %}
|
{% if not is_host %}
|
||||||
|
|||||||
@@ -1,41 +1,69 @@
|
|||||||
{% extends 'base.html' %}
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
|
{% if request.session.mode == "learn" %}
|
||||||
|
|
||||||
<div class="container mx-auto px-4">
|
<div class="container mx-auto px-4">
|
||||||
|
<div class="flex justify-end mb-4">
|
||||||
|
<button onclick="leaveGame()" class="bg-red-500 hover:bg-red-600 text-white font-bold py-2 px-4 rounded">
|
||||||
|
Spiel verlassen
|
||||||
|
</button>
|
||||||
|
</div>{% endif %}
|
||||||
<div class="bg-white rounded-lg shadow-md p-6 mb-6">
|
<div class="bg-white rounded-lg shadow-md p-6 mb-6">
|
||||||
<p class="text-gray-700 font-bold text-xl mb-4">Frage {{ question_index|add:1 }} von {{ total_questions }}</p>
|
<p class="text-gray-700 font-bold text-xl mb-4">Frage {{ question_index|add:1 }} von {{ total_questions }}</p>
|
||||||
<h1 class="text-3xl font-bold mb-6">{{ question_data.question }}</h1>
|
<h1 class="text-3xl font-bold mb-6">{{ question_data.question }}</h1>
|
||||||
|
|
||||||
|
{% if question_image %}
|
||||||
|
<div class="flex justify-center">
|
||||||
|
<img class="m-4" src="{{ question_image.url }}" style="max-width: 500px;" alt="Bild der Frage">
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if request.session.mode == "learn" %}
|
||||||
|
<div class="grid grid-cols-1 gap-4 mb-6">
|
||||||
|
{% else %}
|
||||||
<div class="grid grid-cols-2 gap-4 mb-6">
|
<div class="grid grid-cols-2 gap-4 mb-6">
|
||||||
|
{% endif %}
|
||||||
|
{% if request.session.mode != "learn" %}
|
||||||
<div class="p-4 bg-blue-50 rounded-lg">
|
<div class="p-4 bg-blue-50 rounded-lg">
|
||||||
<p class="text-blue-600 text-xl mb-2">Verbleibende Zeit </p>
|
<p class="text-blue-600 text-xl mb-2">Verbleibende Zeit </p>
|
||||||
<p id="remaining-time" class="text-6xl font-bold text-blue-700">30</p>
|
<p id="remaining-time" class="text-6xl font-bold text-blue-700">30</p>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<div class="p-4 bg-blue-50 rounded-lg">
|
<div class="p-4 bg-blue-50 rounded-lg">
|
||||||
<p class="text-blue-600 text-xl mb-2">Antworten</p>
|
<p class="text-blue-600 text-xl mb-2">Antworten</p>
|
||||||
<p id="answer-count" class="text-6xl font-bold text-blue-700">0/0</p>
|
<p id="answer-count" class="text-6xl font-bold text-blue-700">0/0</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="grid grid-cols-2 gap-4">
|
<div class="grid grid-cols-2 gap-4" id="options-container">
|
||||||
{% for option in question_data.options %}
|
{% for option in question_data.options %}
|
||||||
<div class="p-4 bg-gray-100 rounded-lg" data-correct="{{ option.is_correct }}">
|
<button
|
||||||
|
class="p-4 bg-gray-100 hover:bg-blue-100 rounded-lg transition-colors duration-200 answer-option"
|
||||||
|
data-index="{{ forloop.counter0 }}"
|
||||||
|
{% if request.session.mode == "learn" %}
|
||||||
|
onclick="submitAnswer({{ forloop.counter0 }});" {% endif %}>
|
||||||
<p class="text-lg">{{ option.value }}</p>
|
<p class="text-lg">{{ option.value }}</p>
|
||||||
<p id="option-count-{{ forloop.counter0 }}" class="text-gray-600 hidden">0 Antworten</p>
|
</button>
|
||||||
</div>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{% block extra_js %}
|
{% block extra_js %}
|
||||||
{% include 'play/game/common_scripts.html' %}
|
{% include 'play/game/common_scripts.html' %}
|
||||||
<script>
|
<script>
|
||||||
const joinCode = '{{ quiz_game.join_code }}';
|
const joinCode = '{{ quiz_game.join_code }}';
|
||||||
const hostId = '{{ host_id }}';
|
const hostId = '{{ host_id }}';
|
||||||
const questionStartTime = {{ start_time }};
|
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);
|
const gameSocket = initializeGameSocket(joinCode);
|
||||||
let answeredParticipants = 0;
|
let answeredParticipants = 0;
|
||||||
let totalParticipants = 0;
|
let totalParticipants = 0;
|
||||||
@@ -85,7 +113,7 @@
|
|||||||
// Show correct answers and answer counts
|
// Show correct answers and answer counts
|
||||||
var correctOptions = document.querySelectorAll('[data-correct="True"]');
|
var correctOptions = document.querySelectorAll('[data-correct="True"]');
|
||||||
for (var i = 0; i < correctOptions.length; i++) {
|
for (var i = 0; i < correctOptions.length; i++) {
|
||||||
correctOptions[i].classList.add('border-2', 'border-green-500');
|
correctOptions[i].classList.add('border-2', 'border-blue-500');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show answer counts
|
// Show answer counts
|
||||||
@@ -104,6 +132,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Timer
|
// Timer
|
||||||
|
{% if request.session.mode != "learn" %}
|
||||||
function updateTimer() {
|
function updateTimer() {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const elapsed = now - questionStartTime;
|
const elapsed = now - questionStartTime;
|
||||||
@@ -118,6 +147,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
// Request initial participants list
|
// Request initial participants list
|
||||||
gameSocket.onopen = function(e) {
|
gameSocket.onopen = function(e) {
|
||||||
gameSocket.send(JSON.stringify({
|
gameSocket.send(JSON.stringify({
|
||||||
@@ -125,5 +157,51 @@
|
|||||||
}));
|
}));
|
||||||
updateTimer();
|
updateTimer();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
let hasAnswered = false;
|
||||||
|
const participantId = '{{ host_id }}'; // HIER IST DER HOST DER SPIELER
|
||||||
|
|
||||||
|
function leaveGame() {
|
||||||
|
if (confirm('Möchtest du das Spiel wirklich verlassen?')) {
|
||||||
|
gameSocket.send(JSON.stringify({
|
||||||
|
type: 'leave_game',
|
||||||
|
participant_id: participantId
|
||||||
|
}));
|
||||||
|
window.location.href = '/';
|
||||||
|
gameSocket.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function submitAnswer(optionIndex) {
|
||||||
|
if (hasAnswered) return;
|
||||||
|
|
||||||
|
hasAnswered = true;
|
||||||
|
const now = Date.now();
|
||||||
|
const timeRemaining = Math.max(0, questionDuration - (now - questionStartTime));
|
||||||
|
|
||||||
|
// Disable all options and highlight selected
|
||||||
|
const options = document.getElementsByClassName('answer-option');
|
||||||
|
for (let option of options) {
|
||||||
|
option.disabled = true;
|
||||||
|
option.classList.remove('hover:bg-blue-100');
|
||||||
|
if (parseInt(option.dataset.index) === optionIndex) {
|
||||||
|
option.classList.remove('bg-gray-100');
|
||||||
|
option.classList.add('bg-blue-600', 'text-white');
|
||||||
|
} else {
|
||||||
|
option.classList.add('opacity-50');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send answer to server
|
||||||
|
gameSocket.send(JSON.stringify({
|
||||||
|
type: 'submit_answer',
|
||||||
|
participant_id: participantId,
|
||||||
|
answer: optionIndex,
|
||||||
|
time_remaining: timeRemaining
|
||||||
|
}));
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
const joinCode = '{{ quiz_game.join_code }}';
|
const joinCode = '{{ quiz_game.join_code }}';
|
||||||
const participantId = '{{ participant.participant_id }}';
|
const participantId = '{{ participant.participant_id }}';
|
||||||
const questionStartTime = {{ start_time }};
|
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);
|
const gameSocket = initializeGameSocket(joinCode);
|
||||||
|
|
||||||
gameSocket.onmessage = function(e) {
|
gameSocket.onmessage = function(e) {
|
||||||
|
|||||||
@@ -17,11 +17,14 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% if request.session.mode != "learn" %}
|
||||||
|
|
||||||
<div class="mb-6">
|
<div class="mb-6">
|
||||||
<h2 class="text-xl font-bold mb-4">Punktestand</h2>
|
<h2 class="text-xl font-bold mb-4">Punktestand</h2>
|
||||||
<div class="space-y-2">
|
<div class="space-y-2">
|
||||||
{% for participant in participants %}
|
{% for participant in participants %}
|
||||||
|
{% if participant == my_participant or is_host %}
|
||||||
|
|
||||||
<div class="p-4 {% if forloop.first %}bg-yellow-100 border-2 border-yellow-500{% else %}bg-gray-100{% endif %} rounded-lg flex justify-between items-center">
|
<div class="p-4 {% if forloop.first %}bg-yellow-100 border-2 border-yellow-500{% else %}bg-gray-100{% endif %} rounded-lg flex justify-between items-center">
|
||||||
<div>
|
<div>
|
||||||
<p class="text-lg font-bold">{{ participant.display_name }}</p>
|
<p class="text-lg font-bold">{{ participant.display_name }}</p>
|
||||||
@@ -33,10 +36,17 @@
|
|||||||
<span class="text-red-500">✗</span>
|
<span class="text-red-500">✗</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
{% else %}
|
||||||
|
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
{% if is_host %}
|
{% if is_host %}
|
||||||
{% if is_last_question %}
|
{% if is_last_question %}
|
||||||
<button id="finish-button" class="w-full p-3 rounded-full bg-blue-600 text-white font-bold hover:bg-blue-700 transition-colors duration-200">
|
<button id="finish-button" class="w-full p-3 rounded-full bg-blue-600 text-white font-bold hover:bg-blue-700 transition-colors duration-200">
|
||||||
@@ -112,7 +122,8 @@
|
|||||||
if (stats.hasOwnProperty(optionIndex)) {
|
if (stats.hasOwnProperty(optionIndex)) {
|
||||||
var element = document.getElementById('option-count-' + optionIndex);
|
var element = document.getElementById('option-count-' + optionIndex);
|
||||||
if (element) {
|
if (element) {
|
||||||
element.textContent = stats[optionIndex] + ' Antworten';
|
|
||||||
|
element.textContent = stats[optionIndex] + ' Antwort(en)';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,13 @@
|
|||||||
<!-- Quiz Info -->
|
<!-- Quiz Info -->
|
||||||
<div class="text-center mb-8">
|
<div class="text-center mb-8">
|
||||||
<h3 class="text-xl text-gray-600 mb-2">{{ quiz.name }}</h3>
|
<h3 class="text-xl text-gray-600 mb-2">{{ quiz.name }}</h3>
|
||||||
|
{% if request.session.mode != "learn" %}
|
||||||
<div class="bg-blue-100 rounded-lg p-4 mb-4">
|
<div class="bg-blue-100 rounded-lg p-4 mb-4">
|
||||||
<h1 class="text-4xl font-bold text-blue-800">{{ quiz_game.join_code }}</h1>
|
<h1 class="text-4xl font-bold text-blue-800">{{ quiz_game.join_code }}</h1>
|
||||||
<p class="text-sm text-blue-600 mt-1">Spiel-Code</p>
|
<p class="text-sm text-blue-600 mt-1">Spiel-Code</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<!-- Participant Info -->
|
<!-- Participant Info -->
|
||||||
{% if participant %}
|
{% if participant %}
|
||||||
@@ -31,7 +33,7 @@
|
|||||||
</svg>
|
</svg>
|
||||||
Teilnehmer
|
Teilnehmer
|
||||||
</h3>
|
</h3>
|
||||||
<ul id="participants-list" class="space-y-2 max-h-60 overflow-y-auto">
|
<ul id="participants-list" class="space-y-2 max-h-60">
|
||||||
<li class="text-gray-500 p-3 bg-gray-50 rounded-lg text-center">Warte auf Teilnehmer...</li>
|
<li class="text-gray-500 p-3 bg-gray-50 rounded-lg text-center">Warte auf Teilnehmer...</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
41
django/templates/play/select_mode.html
Normal file
41
django/templates/play/select_mode.html
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<div class="grid place-content-center md:h-screen h-150 w-full -z-50 top-0 p-8 ">
|
||||||
|
<div class="rounded-md rounded-xl shadow-lg border-3 border-blue-100 p-10">
|
||||||
|
<span class="flex justify-center font-bold p-4 text-center text-1xl lg:text-2xl">Bitte wählen Sie einen Spielmodus aus:</span>
|
||||||
|
|
||||||
|
<div class="grid sm:grid-cols-2 place-items-stretch text-center gap-4 p-4">
|
||||||
|
|
||||||
|
<!-- Moderieren -->
|
||||||
|
<a class="qp-a-button bg-green-500 text-white flex justify-center items-center relative group h-20 gap-2" href="{% url 'play:selected_mode' join_code %}?mode=classic">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="size-6">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="M18 18.72a9.094 9.094 0 0 0 3.741-.479 3 3 0 0 0-4.682-2.72m.94 3.198.001.031c0 .225-.012.447-.037.666A11.944 11.944 0 0 1 12 21c-2.17 0-4.207-.576-5.963-1.584A6.062 6.062 0 0 1 6 18.719m12 0a5.971 5.971 0 0 0-.941-3.197m0 0A5.995 5.995 0 0 0 12 12.75a5.995 5.995 0 0 0-5.058 2.772m0 0a3 3 0 0 0-4.681 2.72 8.986 8.986 0 0 0 3.74.477m.94-3.197a5.971 5.971 0 0 0-.94 3.197M15 6.75a3 3 0 1 1-6 0 3 3 0 0 1 6 0Zm6 3a2.25 2.25 0 1 1-4.5 0 2.25 2.25 0 0 1 4.5 0Zm-13.5 0a2.25 2.25 0 1 1-4.5 0 2.25 2.25 0 0 1 4.5 0Z" />
|
||||||
|
</svg>
|
||||||
|
|
||||||
|
Moderiermodus
|
||||||
|
<!-- Tooltip -->
|
||||||
|
<span class="absolute w-full h-1/2 top-1/4 left-0 hidden group-hover:flex items-center justify-center text-white bg-black bg-opacity-90 text-xs rounded px-2 z-10 pointer-events-none">
|
||||||
|
Klassischer Spielmodus zum Moderieren
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<!-- Lernmodus -->
|
||||||
|
<a class="qp-a-button bg-indigo-500 text-white flex justify-center items-center relative group h-20 gap-2" href="{% url 'play:selected_mode' join_code %}?mode=learn">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="size-6">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="M15.75 6a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0ZM4.501 20.118a7.5 7.5 0 0 1 14.998 0A17.933 17.933 0 0 1 12 21.75c-2.676 0-5.216-.584-7.499-1.632Z" />
|
||||||
|
</svg>
|
||||||
|
|
||||||
|
Lernmodus
|
||||||
|
<!-- Tooltip -->
|
||||||
|
<span class="absolute w-full h-1/2 top-1/4 left-0 hidden group-hover:flex items-center justify-center text-white bg-black bg-opacity-90 text-xs rounded px-2 z-10 pointer-events-none">
|
||||||
|
Modus zum selbständigen Üben und Lernen
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
@@ -4,3 +4,4 @@ channels~=4.2.0 # WebSocket support
|
|||||||
daphne~=4.1.2 # ASGI server
|
daphne~=4.1.2 # ASGI server
|
||||||
pillow~=11.1.0 # Image handling
|
pillow~=11.1.0 # Image handling
|
||||||
whitenoise~=6.6.0 # Static file serving
|
whitenoise~=6.6.0 # Static file serving
|
||||||
|
django-cleanup
|
||||||
Reference in New Issue
Block a user