Compare commits
95 Commits
20-t-style
...
testbranhc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e135ff945f | ||
|
|
fbb0787aa9 | ||
|
|
16fcaf6346 | ||
|
|
8a6d337392 | ||
|
|
5f4fd4345e | ||
|
|
7e93165c58 | ||
|
|
419160d144 | ||
|
|
0c6580e732 | ||
|
|
8f4b5d581d | ||
|
|
809d857e94 | ||
|
|
98142c91f3 | ||
|
|
93b2675b9e | ||
|
|
157daae740 | ||
|
|
f6459965e0 | ||
|
|
a3331543f2 | ||
|
|
9d71f2bbf3 | ||
|
|
8cceecf1bd | ||
|
|
c330c4bc70 | ||
|
|
26bf2a2c55 | ||
|
|
86958c6d16 | ||
|
|
83a3d1584a | ||
|
|
a07c66ad1a | ||
|
|
956e69b56f | ||
|
|
526e486fd3 | ||
|
|
b149cbcfee | ||
|
|
12c5cec7a1 | ||
|
|
e0bfda0dee | ||
|
|
23675bc69e | ||
|
|
94659791e6 | ||
|
|
17cc0af02d | ||
|
|
f28878e1b0 | ||
|
|
2a8b0b813c | ||
|
|
f18ed83f9d | ||
|
|
d1cca38595 | ||
|
|
1f1344522f | ||
|
|
7cad46063e | ||
|
|
55750bcf1f | ||
|
|
230944cbcd | ||
|
|
2f47ff8523 | ||
|
|
3ef7d61da6 | ||
|
|
7fe29c5bd4 | ||
|
|
5775e53bb8 | ||
|
|
57682d4607 | ||
|
|
915552ac4a | ||
| 861e89ae4d | |||
| 97fd326561 | |||
|
|
34a9ab6a43 | ||
|
|
4c597473b7 | ||
|
|
8119f202d3 | ||
| 6beccc772a | |||
|
|
4797a74111 | ||
|
|
30b5cd9731 | ||
|
|
6b83f26fc0 | ||
|
|
346ac69046 | ||
|
|
838eaab9be | ||
|
|
eba34fa2d4 | ||
|
|
9f51def959 | ||
| c8bf38dd36 | |||
|
|
7120dcd317 | ||
|
|
da419533e9 | ||
|
|
bd0aa651af | ||
|
|
d1b11a0c51 | ||
|
|
5dc849f551 | ||
| 35617470c4 | |||
|
|
b6991c2cbd | ||
|
|
a0e31d77f2 | ||
|
|
434d1f63e3 | ||
|
|
e3bd3c8579 | ||
|
|
7e66868a7d | ||
|
|
b306321565 | ||
|
|
3a099945b5 | ||
|
|
9f6c1cc33c | ||
|
|
13cbaaa6dc | ||
|
|
46634b1e1c | ||
|
|
3508b8e341 | ||
|
|
039e3ea0cb | ||
| 90d7a3ea94 | |||
| c348734ff4 | |||
| 35da688b1e | |||
|
|
089abfc598 | ||
| f732d8305e | |||
|
|
7a4caf7191 | ||
| 213b4cfd77 | |||
|
|
1f55ad8247 | ||
|
|
53ffe3822a | ||
|
|
71d8deab5b | ||
|
|
2173d7f928 | ||
|
|
eddab4a298 | ||
|
|
2ea2c03c67 | ||
|
|
0775710102 | ||
|
|
ba77d72091 | ||
|
|
b09eb2c7d6 | ||
|
|
47beb3a8e7 | ||
|
|
0eaac8c2f0 | ||
|
|
adb208a56a |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -3,3 +3,6 @@ __pycache__
|
|||||||
db.sqlite3
|
db.sqlite3
|
||||||
tailwindcss.exe
|
tailwindcss.exe
|
||||||
t-style.css
|
t-style.css
|
||||||
|
dump.rdb
|
||||||
|
media
|
||||||
|
node_modules
|
||||||
21
README.md
21
README.md
@@ -6,6 +6,7 @@
|
|||||||
2. [Starten des Servers](#starten-des-servers)
|
2. [Starten des Servers](#starten-des-servers)
|
||||||
3. [Superuser erstellen](#superuser-erstellen)
|
3. [Superuser erstellen](#superuser-erstellen)
|
||||||
4. [Tailwind-Nutzung](#tailwind-nutzung)
|
4. [Tailwind-Nutzung](#tailwind-nutzung)
|
||||||
|
5. [Issue - Merge Request - Merge](#issue-mergerequest-merge)
|
||||||
|
|
||||||
## Initialisierung des Projekts
|
## Initialisierung des Projekts
|
||||||
|
|
||||||
@@ -83,7 +84,11 @@ npm install tailwindcss @tailwindcss/cli
|
|||||||
### Datei generieren
|
### Datei generieren
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
# Bei Verwendung der Binärdatei:
|
||||||
tailwindcss -i <INPUT-DATEI> -o <OUTPUT-DATEI> --watch --minify
|
tailwindcss -i <INPUT-DATEI> -o <OUTPUT-DATEI> --watch --minify
|
||||||
|
|
||||||
|
# Bei Verwendung von NPM:
|
||||||
|
npx @tailwindcss/cli -i <INPUT-DATEI> -o <OUTPUT-DATEI> --watch --minify
|
||||||
```
|
```
|
||||||
|
|
||||||
- INPUT-DATEI: CSS Datei, welche die Einbindung und Konfiguration von Tailwind enthält
|
- INPUT-DATEI: CSS Datei, welche die Einbindung und Konfiguration von Tailwind enthält
|
||||||
@@ -94,5 +99,19 @@ tailwindcss -i <INPUT-DATEI> -o <OUTPUT-DATEI> --watch --minify
|
|||||||
**Beispiel:**
|
**Beispiel:**
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
tailwindcss -i core/homepage/static/homepage/t-input.css -o core/homepage/static/homepage/t-style.css --watch --minify
|
# unter Linux mit Tailwind Binärdatei:
|
||||||
|
tailwindcss -i static/css/t-input.css -o static/css/t-style.css --watch --minify
|
||||||
|
|
||||||
|
# unter Windows mit NPM (in bash mit '/' statt '\'):
|
||||||
|
npx @tailwindcss/cli -i .\static\css\t-input.css -o .\static\css\t-style.css --watch --minify
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Issue - Merge Request - Merge
|
||||||
|
|
||||||
|
Hier der vereinbarte Arbeitsablauf:
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
3. Nach dem Hochladen kann der Merge in den Master durchgeführt werden.
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
{% load static %}
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="de">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>{% block title %}{% endblock %}</title>
|
|
||||||
<link rel="stylesheet" href="{% static 'homepage/t-style.css' %}">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
{% include 'homepage/partials/_nav.html' %}
|
|
||||||
{% block content %}
|
|
||||||
{% endblock %}
|
|
||||||
{% include 'homepage/partials/_footer.html' %}
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<nav class="flex justify-between bg-blue-600 h-12 px-4 sm:px-6 lg:px-8 rounded-lg m-2 shadow-md">
|
|
||||||
<div class="flex items-center">
|
|
||||||
<h2 class="text-xl font-bold text-white hover:scale-110 transition duration-200"><a href="#">qivip</a></h2>
|
|
||||||
</div>
|
|
||||||
<div class="flex items-center">
|
|
||||||
<ul class="flex space-x-4 qp-nav-list">
|
|
||||||
<li><a href="#">Start</a></li>
|
|
||||||
<li><a href="#">Bibliothek</a></li>
|
|
||||||
<li><a href="{% url 'login' %}">Konto</a></li> <!--Hier ist der Link erstmal auf das alte Login-Formular gesetzt! Zum Testen!-->
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,15 +0,0 @@
|
|||||||
{% extends 'homepage/base.html' %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<div class="grid place-content-center md:h-screen h-150 w-full -z-50 top-0 p-4">
|
|
||||||
<div class="text-center">
|
|
||||||
<h2 class="font-bold md:text-8xl text-6xl md:mb-8 text-blue-600">qivip</h2>
|
|
||||||
<h3 class="italic font-extralight sm:text-2xl text-md">Interaktives Lernen neu definiert.</h3>
|
|
||||||
</div>
|
|
||||||
<div class="grid sm:grid-cols-3 place-items-stretch text-center mt-8 gap-4 p-4 border-3 bg-blue-100 border-blue-100 rounded-md">
|
|
||||||
<a class="qp-a-button bg-green-500 text-white" href="#">Teilnehmen</a>
|
|
||||||
<a class="qp-a-button bg-indigo-500 text-white" href="#">Moderieren</a>
|
|
||||||
<a class="qp-a-button bg-purple-500 text-white" href="#">Verwalten</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
{% load static %}
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="de">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>Impressum</title>
|
|
||||||
<link rel="icon" type="image/png" href="{% static 'icons/favicon.png' %}">
|
|
||||||
<link rel="stylesheet" href="{% static 'homepage/t-style.css' %}">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
{% include 'homepage/partials/_nav.html' %}
|
|
||||||
<div class="max-w-screen-lg mx-auto">
|
|
||||||
{% block content%}{% endblock %}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div>
|
|
||||||
<h1>Impressum</h1>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<dvi>
|
|
||||||
<p>
|
|
||||||
Katharineum zu Lübeck
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
Königsstraße 27-31
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
23552 Lübeck
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
{% include 'homepage/partials/_footer.html' %}
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
<nav class="flex justify-between bg-blue-600 h-12 px-4 sm:px-6 lg:px-8 rounded-lg m-2 shadow-md">
|
|
||||||
<div class="flex items-center">
|
|
||||||
<h2 class="text-xl font-bold text-white hover:scale-110 transition duration-200"><a href="{% url 'homepage:home' %}">qivip</a></h2>
|
|
||||||
</div>
|
|
||||||
<div class="flex items-center">
|
|
||||||
<ul class="flex space-x-4 qp-nav-list">
|
|
||||||
<li><a href="{% url 'library:overview_quiz' %}">Bibliothek</a></li>
|
|
||||||
{% if user.is_authenticated %}
|
|
||||||
<li><a href="{% url 'accounts:home' %}">Konto</a></li>
|
|
||||||
{% else %}
|
|
||||||
<li><a href="{% url 'accounts:login' %}">Anmelden</a></li>
|
|
||||||
{% endif %}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
{% load static %}
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="de">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>Impressum</title>
|
|
||||||
<link rel="icon" type="image/png" href="{% static 'icons/favicon.png' %}">
|
|
||||||
<link rel="stylesheet" href="{% static 'homepage/t-style.css' %}">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
{% include 'homepage/partials/_nav.html' %}
|
|
||||||
<div class="max-w-screen-lg mx-auto">
|
|
||||||
{% block content%}{% endblock %}
|
|
||||||
<div>
|
|
||||||
<p>
|
|
||||||
Hallo, ich bin die Datenschutzerklärung!
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% include 'homepage/partials/_footer.html' %}
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
from django import forms
|
|
||||||
from .models import QivipQuiz, QivipQuestion
|
|
||||||
|
|
||||||
class QuizForm(forms.ModelForm):
|
|
||||||
class Meta:
|
|
||||||
model = QivipQuiz
|
|
||||||
fields = ['name', 'description', 'status', 'category', 'tags',"difficulty"]
|
|
||||||
|
|
||||||
class QuestionForm(forms.ModelForm):
|
|
||||||
class Meta:
|
|
||||||
model = QivipQuestion
|
|
||||||
fields = ['quiz_id', 'data']
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
{% load static %}
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="de">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<link rel="stylesheet" href="{% static 'homepage/t-style.css' %}">
|
|
||||||
<title>qivip</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
{% include 'homepage/partials/_nav.html' %}
|
|
||||||
<div class="max-w-screen-lg mx-auto">
|
|
||||||
{% block content%}{% endblock %}
|
|
||||||
</div>
|
|
||||||
{% include 'homepage/partials/_footer.html' %}
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
{% extends 'library/base.html' %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<h1>Löschen</h1>
|
|
||||||
<p>Soll das Quiz "{{ object.name }}" wirklich gelöscht werden?</p>
|
|
||||||
<form method="post">
|
|
||||||
{% csrf_token %}
|
|
||||||
<button type="submit">Löschen</button>
|
|
||||||
<a href="{% url 'library:overview_quiz' %}">Abbrechen</a>
|
|
||||||
</form>
|
|
||||||
{% endblock %}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
{% extends 'library/base.html' %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<h1>{{ quiz.name }}</h1>
|
|
||||||
<p>{{ quiz.description }}</p>
|
|
||||||
<a href="{% url 'library:edit_quiz' quiz.id %}">Bearbeiten</a>
|
|
||||||
<a href="{% url 'library:delete_quiz' quiz.id %}">Löschen</a>
|
|
||||||
|
|
||||||
<h2>Fragen</h2>
|
|
||||||
<ul>
|
|
||||||
<a href="{% url 'library:new_question' %}">Neue Frage erstellen</a>
|
|
||||||
{% for question in questions %}
|
|
||||||
<li>{{ question.data }}</li>
|
|
||||||
<a href="{% url 'library:edit_question' question.id %}">Bearbeiten</a>
|
|
||||||
<a href="{% url 'library:delete_question' question.id %}">Löschen</a>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
{% endblock %}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
{% extends 'library/base.html' %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<h1>Formular</h1>
|
|
||||||
<h2>{{ form.name.value }}</h2>
|
|
||||||
<div class="input-group">
|
|
||||||
<form method="post">
|
|
||||||
{% csrf_token %}
|
|
||||||
{{ form.as_p }}
|
|
||||||
<button type="submit">Speichern</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
{% extends 'library/base.html' %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<h1>Übersicht</h1>
|
|
||||||
<div class="flex justify-end">
|
|
||||||
<a href="{% url 'library:new_quiz' %}" class="bg-blue-500 text-white px-4 py-2 rounded-md">Neues Quiz erstellen</a>
|
|
||||||
</div>
|
|
||||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
|
||||||
{% for quiz in quizzes %}
|
|
||||||
<div class="bg-white rounded-lg p-4 shadow-md">
|
|
||||||
<h2 class="text-lg font-bold"><a href="{% url 'library:detail_quiz' quiz.id %}">{{ quiz.name }}</a></h2>
|
|
||||||
<p class="text-sm text-gray-600 my-8">{{ quiz.description }}</p>
|
|
||||||
<a href="#"class="qp-a-button-small bg-green-500">Spiel starten</a>
|
|
||||||
<button><a href="{% url 'library:edit_quiz' quiz.id %}"class="qp-a-button-small bg-indigo-500">Bearbeiten</a></button>
|
|
||||||
<a href="{% url 'library:delete_quiz' quiz.id %}" class="qp-a-button-small bg-purple-500">Löschen</a>
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
from django.shortcuts import render, redirect, get_object_or_404
|
|
||||||
from django.contrib.auth.decorators import login_required
|
|
||||||
from django.contrib.auth.models import User
|
|
||||||
from .models import QivipQuiz, QivipQuestion
|
|
||||||
from .forms import QuizForm, QuestionForm
|
|
||||||
|
|
||||||
# Übersicht aller Quizze
|
|
||||||
@login_required
|
|
||||||
def overview_quiz(request):
|
|
||||||
quizzes = QivipQuiz.objects.filter(user_id=request.user)
|
|
||||||
return render(request, 'library/overview_quiz.html', {'quizzes': quizzes})
|
|
||||||
|
|
||||||
# Neues Quiz erstellen
|
|
||||||
@login_required
|
|
||||||
def new_quiz(request):
|
|
||||||
if request.method == 'POST':
|
|
||||||
form = QuizForm(request.POST)
|
|
||||||
if form.is_valid():
|
|
||||||
quiz = form.save(commit=False)
|
|
||||||
quiz.user_id = request.user
|
|
||||||
quiz.save()
|
|
||||||
form.save_m2m() # Speichert die Many-to-Many Beziehungen (Tags)
|
|
||||||
return redirect('library:edit_quiz', pk=quiz.pk)
|
|
||||||
else:
|
|
||||||
form = QuizForm()
|
|
||||||
return render(request, 'library/form.html', {'form': form})
|
|
||||||
|
|
||||||
# Quiz bearbeiten
|
|
||||||
@login_required
|
|
||||||
def edit_quiz(request, pk):
|
|
||||||
quiz = get_object_or_404(QivipQuiz, pk=pk, user_id=request.user)
|
|
||||||
if request.method == 'POST':
|
|
||||||
form = QuizForm(request.POST, instance=quiz)
|
|
||||||
if form.is_valid():
|
|
||||||
form.save()
|
|
||||||
return redirect('library:overview_quiz')
|
|
||||||
else:
|
|
||||||
form = QuizForm(instance=quiz)
|
|
||||||
return render(request, 'library/form.html', {'form': form})
|
|
||||||
|
|
||||||
# Quiz löschen
|
|
||||||
@login_required
|
|
||||||
def delete_quiz(request, pk):
|
|
||||||
quiz = get_object_or_404(QivipQuiz, pk=pk, user_id=request.user)
|
|
||||||
if request.method == 'POST':
|
|
||||||
quiz.delete()
|
|
||||||
return redirect('library:overview_quiz')
|
|
||||||
return render(request, 'library/delete_confirmation.html', {'object': quiz})
|
|
||||||
|
|
||||||
# Quiz anzeigen
|
|
||||||
@login_required
|
|
||||||
def detail_quiz(request, pk):
|
|
||||||
quiz = get_object_or_404(QivipQuiz, pk=pk, user_id=request.user)
|
|
||||||
questions = QivipQuestion.objects.filter(quiz_id=quiz)
|
|
||||||
return render(request, 'library/detail_quiz.html', {'quiz': quiz, 'questions': questions})
|
|
||||||
|
|
||||||
# Übersicht aller Fragen
|
|
||||||
@login_required
|
|
||||||
def question_list(request):
|
|
||||||
questions = QivipQuestion.objects.filter(quiz_id__user_id=request.user)
|
|
||||||
return render(request, 'library/question_list.html', {'questions': questions})
|
|
||||||
|
|
||||||
# Neue Frage erstellen
|
|
||||||
@login_required
|
|
||||||
def new_question(request):
|
|
||||||
if request.method == 'POST':
|
|
||||||
form = QuestionForm(request.POST)
|
|
||||||
if form.is_valid():
|
|
||||||
question = form.save(commit=False)
|
|
||||||
# Prüfe ob der User Zugriff auf das Quiz hat
|
|
||||||
if question.quiz_id.user_id != request.user:
|
|
||||||
return redirect('library:question_list')
|
|
||||||
question.save()
|
|
||||||
return redirect('library:edit_question', pk=question.pk)
|
|
||||||
else:
|
|
||||||
form = QuestionForm()
|
|
||||||
return render(request, 'library/form.html', {'form': form})
|
|
||||||
|
|
||||||
# Frage bearbeiten
|
|
||||||
@login_required
|
|
||||||
def edit_question(request, pk):
|
|
||||||
question = get_object_or_404(QivipQuestion, pk=pk, quiz_id__user_id=request.user)
|
|
||||||
if request.method == 'POST':
|
|
||||||
form = QuestionForm(request.POST, instance=question)
|
|
||||||
if form.is_valid():
|
|
||||||
form.save()
|
|
||||||
return redirect('library:edit_question', pk=pk)
|
|
||||||
else:
|
|
||||||
form = QuestionForm(instance=question)
|
|
||||||
return render(request, 'library/form.html', {'form': form})
|
|
||||||
|
|
||||||
# Frage löschen
|
|
||||||
@login_required
|
|
||||||
def delete_question(request, pk):
|
|
||||||
question = get_object_or_404(QivipQuestion, pk=pk, quiz_id__user_id=request.user)
|
|
||||||
if request.method == 'POST':
|
|
||||||
question.delete()
|
|
||||||
return redirect('library:detail_quiz', pk=question.quiz_id.pk)
|
|
||||||
return render(request, 'library/delete_confirmation.html', {'object': question})
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.contrib.auth import login, authenticate
|
||||||
from .forms import RegisterForm
|
from .forms import RegisterForm
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
@@ -11,8 +12,9 @@ def register(response):
|
|||||||
if response.method == "POST":
|
if response.method == "POST":
|
||||||
form = RegisterForm(response.POST)
|
form = RegisterForm(response.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
form.save()
|
user=form.save()
|
||||||
return redirect("home")
|
login(response, user) #automatischer Login nach Registrierung
|
||||||
|
return redirect("accounts:home")
|
||||||
else:
|
else:
|
||||||
form = RegisterForm()
|
form = RegisterForm()
|
||||||
|
|
||||||
@@ -35,6 +35,7 @@ INSTALLED_APPS = [
|
|||||||
'homepage.apps.HomepageConfig',
|
'homepage.apps.HomepageConfig',
|
||||||
'components.apps.ComponentsConfig',
|
'components.apps.ComponentsConfig',
|
||||||
'accounts.apps.AccountsConfig',
|
'accounts.apps.AccountsConfig',
|
||||||
|
'play',
|
||||||
'django.contrib.admin',
|
'django.contrib.admin',
|
||||||
'django.contrib.auth',
|
'django.contrib.auth',
|
||||||
'django.contrib.contenttypes',
|
'django.contrib.contenttypes',
|
||||||
@@ -58,7 +59,7 @@ ROOT_URLCONF = 'core.urls'
|
|||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
'DIRS': [],
|
'DIRS': [BASE_DIR / 'templates'],
|
||||||
'APP_DIRS': True,
|
'APP_DIRS': True,
|
||||||
'OPTIONS': {
|
'OPTIONS': {
|
||||||
'context_processors': [
|
'context_processors': [
|
||||||
@@ -120,7 +121,7 @@ USE_TZ = True
|
|||||||
# https://docs.djangoproject.com/en/5.1/howto/static-files/
|
# https://docs.djangoproject.com/en/5.1/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = '/static/'
|
||||||
BASE_DIR='static' #von ben8 hinzugefügt
|
STATICFILES_DIRS = [BASE_DIR / 'static']
|
||||||
|
|
||||||
# Default primary key field type
|
# Default primary key field type
|
||||||
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
|
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
|
||||||
@@ -128,3 +129,7 @@ BASE_DIR='static' #von ben8 hinzugefügt
|
|||||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||||
|
|
||||||
LOGIN_URL = '/account/login/'
|
LOGIN_URL = '/account/login/'
|
||||||
|
import os
|
||||||
|
|
||||||
|
MEDIA_URL = '/media/' # URL, um auf Medien-Dateien zuzugreifen
|
||||||
|
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') # Speicherort für hochgeladene Dateien
|
||||||
@@ -21,6 +21,7 @@ urlpatterns = [
|
|||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path('account/', include('accounts.urls')),
|
path('account/', include('accounts.urls')),
|
||||||
path('', include('homepage.urls')),
|
path('', include('homepage.urls')),
|
||||||
path('play/', include('components.urls')),
|
path('play/', include('play.urls')),
|
||||||
path('library/', include('library.urls')),
|
path('library/', include('library.urls')),
|
||||||
|
path('components/', include('components.urls'))
|
||||||
]
|
]
|
||||||
@@ -6,7 +6,6 @@ class QivipQuizAdmin(admin.ModelAdmin):
|
|||||||
list_display = ('name', 'user_id', 'status', 'category', 'creation_date', 'update_date') # Welche Felder sollen in der Übersicht angezeigt werden
|
list_display = ('name', 'user_id', 'status', 'category', 'creation_date', 'update_date') # Welche Felder sollen in der Übersicht angezeigt werden
|
||||||
search_fields = ('name', 'user_id__username', 'category__name') # Suchfelder
|
search_fields = ('name', 'user_id__username', 'category__name') # Suchfelder
|
||||||
list_filter = ('status', 'category') # Filteroptionen
|
list_filter = ('status', 'category') # Filteroptionen
|
||||||
|
|
||||||
# Für das QivipQuestion Modell
|
# Für das QivipQuestion Modell
|
||||||
class QivipQuestionAdmin(admin.ModelAdmin):
|
class QivipQuestionAdmin(admin.ModelAdmin):
|
||||||
list_display = ('quiz_id', 'data', 'creation_date', 'update_date')
|
list_display = ('quiz_id', 'data', 'creation_date', 'update_date')
|
||||||
31
django/library/forms.py
Normal file
31
django/library/forms.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
from django import forms
|
||||||
|
from .models import QivipQuiz, QivipQuestion
|
||||||
|
|
||||||
|
class QuizForm(forms.ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = QivipQuiz
|
||||||
|
fields = ['name', 'description','image', 'status', 'category', 'tags',"difficulty","credits"]
|
||||||
|
|
||||||
|
class QuestionForm(forms.ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = QivipQuestion
|
||||||
|
fields = ['quiz_id', 'data']
|
||||||
|
|
||||||
|
from django import forms
|
||||||
|
|
||||||
|
class QuizFilterForm(forms.Form):
|
||||||
|
search = forms.CharField(required=False, label="Suche", widget=forms.TextInput(attrs={
|
||||||
|
'class': 'flex flex-grow rounded-lg p-2' ,'placeholder': 'Suche ...',
|
||||||
|
}))
|
||||||
|
|
||||||
|
|
||||||
|
min_amout_questions = forms.IntegerField(required=False, min_value=1, label="Minimale Anzahl an Fragen", widget=forms.NumberInput(attrs={
|
||||||
|
'class': 'border-2 border-gray-300 rounded-lg p-2 w-full'
|
||||||
|
}))
|
||||||
|
|
||||||
|
max_amout_questions = forms.IntegerField(required=False, min_value=1, label="Maximale Anzahl an Fragen", widget=forms.NumberInput(attrs={
|
||||||
|
'class': 'border-2 border-gray-300 rounded-lg p-2 w-full'
|
||||||
|
}))
|
||||||
|
user = forms.CharField(required=False, label="von User", widget=forms.TextInput(attrs={
|
||||||
|
'class': 'border-2 border-gray-300 rounded-lg p-2 w-full'
|
||||||
|
}))
|
||||||
18
django/library/migrations/0016_alter_qivipquiz_status.py
Normal file
18
django/library/migrations/0016_alter_qivipquiz_status.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-03-16 12:53
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0015_alter_qivipquiz_difficulty'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='status',
|
||||||
|
field=models.CharField(choices=[('öffentlich', 'Öffentlich'), ('versteckt', 'Versteckt'), ('privat', 'Privat')], default='öffentlich', max_length=10),
|
||||||
|
),
|
||||||
|
]
|
||||||
18
django/library/migrations/0017_alter_qivipquiz_difficulty.py
Normal file
18
django/library/migrations/0017_alter_qivipquiz_difficulty.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-03-16 12:54
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0016_alter_qivipquiz_status'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
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),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-03-16 13:03
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0017_alter_qivipquiz_difficulty'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='description',
|
||||||
|
field=models.TextField(blank=True, default='In dem Quiz geht es um ...', max_length=150, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-03-16 13:05
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0018_alter_qivipquiz_description'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='description',
|
||||||
|
field=models.TextField(default='In dem Quiz geht es um ...', max_length=255, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-03-16 13:08
|
||||||
|
|
||||||
|
import library.models
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0019_alter_qivipquiz_description'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='description',
|
||||||
|
field=models.TextField(default='In dem Quiz geht es um ...', max_length=255, validators=[library.models.QivipQuiz.validate_description]),
|
||||||
|
),
|
||||||
|
]
|
||||||
18
django/library/migrations/0021_alter_qivipquiz_name.py
Normal file
18
django/library/migrations/0021_alter_qivipquiz_name.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-03-16 14:34
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0020_alter_qivipquiz_description'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='name',
|
||||||
|
field=models.CharField(max_length=100),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-03-16 14:35
|
||||||
|
|
||||||
|
import library.models
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0021_alter_qivipquiz_name'),
|
||||||
|
]
|
||||||
|
|
||||||
|
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]),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='name',
|
||||||
|
field=models.CharField(max_length=75),
|
||||||
|
),
|
||||||
|
]
|
||||||
18
django/library/migrations/0023_qivipquiz_image.py
Normal file
18
django/library/migrations/0023_qivipquiz_image.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-03-21 17:24
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0022_alter_qivipquiz_description_alter_qivipquiz_name'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='image',
|
||||||
|
field=models.ImageField(blank=True, null=True, upload_to='quiz_images/'),
|
||||||
|
),
|
||||||
|
]
|
||||||
18
django/library/migrations/0024_alter_qivipquiz_image.py
Normal file
18
django/library/migrations/0024_alter_qivipquiz_image.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-03-22 10:22
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0023_qivipquiz_image'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='image',
|
||||||
|
field=models.ImageField(blank=True, max_length=256, null=True, upload_to='quiz_images/'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-04-03 16:46
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0024_alter_qivipquiz_image'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='modified_description',
|
||||||
|
field=models.TextField(blank=True, default='Das Quiz wurde modifiziert von:', editable=False),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-04-04 13:28
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0025_qivipquiz_modified_description'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='modified_description',
|
||||||
|
field=models.TextField(blank=True, editable=False),
|
||||||
|
),
|
||||||
|
]
|
||||||
21
django/library/migrations/0027_qivipquiz_creator.py
Normal file
21
django/library/migrations/0027_qivipquiz_creator.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-04-04 13:37
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0026_alter_qivipquiz_modified_description'),
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='creator',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='creator_quiz', to=settings.AUTH_USER_MODEL),
|
||||||
|
),
|
||||||
|
]
|
||||||
21
django/library/migrations/0028_alter_qivipquiz_creator.py
Normal file
21
django/library/migrations/0028_alter_qivipquiz_creator.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-04-04 13:57
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0027_qivipquiz_creator'),
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='creator',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='creator_quiz', to=settings.AUTH_USER_MODEL),
|
||||||
|
),
|
||||||
|
]
|
||||||
18
django/library/migrations/0029_qivipquiz_credits.py
Normal file
18
django/library/migrations/0029_qivipquiz_credits.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-04-04 16:02
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0028_alter_qivipquiz_creator'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='credits',
|
||||||
|
field=models.TextField(blank=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-04-05 09:39
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0029_qivipquiz_credits'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='creator',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='modified_description',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='qivipquiz',
|
||||||
|
name='base_quiz',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='child_quizzes', to='library.qivipquiz'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -2,12 +2,13 @@ from django.db import models
|
|||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.utils.text import slugify
|
from django.utils.text import slugify
|
||||||
import uuid
|
import uuid
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
class QivipQuiz(models.Model):
|
class QivipQuiz(models.Model):
|
||||||
STATUS_VALUES = {
|
STATUS_VALUES = {
|
||||||
"public": "Öffentlich",
|
"öffentlich": "Öffentlich",
|
||||||
"hidden": "Versteckt",
|
"versteckt": "Versteckt",
|
||||||
"private": "Privat",
|
"privat": "Privat",
|
||||||
}
|
}
|
||||||
DIFFICULTY_VALUES = {
|
DIFFICULTY_VALUES = {
|
||||||
"1": "1",
|
"1": "1",
|
||||||
@@ -15,25 +16,34 @@ class QivipQuiz(models.Model):
|
|||||||
"3": "3",
|
"3": "3",
|
||||||
"4": "4",
|
"4": "4",
|
||||||
"5": "5",
|
"5": "5",
|
||||||
"not defined":"nicht gesetzt",
|
"nicht gesetzt":"nicht gesetzt",
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def validate_description(value):
|
||||||
|
if value.strip() == "In dem Quiz geht es um ...":
|
||||||
|
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/
|
||||||
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')
|
||||||
|
base_quiz = models.ForeignKey('self', on_delete=models.SET_NULL,blank=True, null=True, related_name='child_quizzes')
|
||||||
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="public")
|
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', related_name='quiz', on_delete=models.CASCADE)
|
||||||
tags = models.ManyToManyField('Tag', blank=True)
|
tags = models.ManyToManyField('Tag', blank=True)
|
||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=75)
|
||||||
description = models.TextField(blank=True, null=True, 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 ...")
|
||||||
difficulty= models.CharField(max_length=11, choices=list(DIFFICULTY_VALUES.items()), default="not defined", help_text="1: niedrigste Schwierigkeit und 5: höchste Schwierigkeit")
|
difficulty= models.CharField(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)
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
class QivipQuestion(models.Model):
|
class QivipQuestion(models.Model):
|
||||||
uuid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
|
uuid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
from . import views
|
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from . import views
|
||||||
|
from django.conf.urls.static import static
|
||||||
app_name = 'library'
|
app_name = 'library'
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
@@ -12,4 +14,8 @@ urlpatterns = [
|
|||||||
path('question/new/', views.new_question, name='new_question'),
|
path('question/new/', views.new_question, name='new_question'),
|
||||||
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'),
|
||||||
|
|
||||||
|
]# Nur für die Entwicklungsumgebung
|
||||||
|
if settings.DEBUG:
|
||||||
|
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
432
django/library/views.py
Normal file
432
django/library/views.py
Normal file
@@ -0,0 +1,432 @@
|
|||||||
|
import uuid
|
||||||
|
from django.shortcuts import render, redirect, get_object_or_404
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
from django.urls import reverse
|
||||||
|
from django.contrib import messages
|
||||||
|
from .models import QivipQuiz, QivipQuestion
|
||||||
|
from .forms import QuizForm, QuestionForm
|
||||||
|
import json
|
||||||
|
from django.core.paginator import Paginator
|
||||||
|
from .models import QivipQuiz
|
||||||
|
from .forms import QuizFilterForm
|
||||||
|
from django.db.models import Count
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
# Übersicht aller Quizze
|
||||||
|
|
||||||
|
def overview_quiz(request):
|
||||||
|
|
||||||
|
#Filter
|
||||||
|
form = QuizFilterForm(request.GET)
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
filter_my_quizzes = QivipQuiz.objects.filter(user_id=request.user).annotate(max_amout_questions=Count('question'))
|
||||||
|
except:
|
||||||
|
filter_my_quizzes = QivipQuiz.objects.none()
|
||||||
|
|
||||||
|
filter_other_quizzes = QivipQuiz.objects.annotate(max_amout_questions=Count('question'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if form.is_valid():
|
||||||
|
search = form.cleaned_data.get('search')
|
||||||
|
username= form.cleaned_data.get('user')
|
||||||
|
max_amout_questions= form.cleaned_data.get('max_amout_questions')
|
||||||
|
min_amout_questions= form.cleaned_data.get('min_amout_questions')
|
||||||
|
if search: # Suche nach Namen
|
||||||
|
filter_other_quizzes = filter_other_quizzes.filter(name__icontains=search)
|
||||||
|
filter_my_quizzes = filter_my_quizzes.filter(name__icontains=search)
|
||||||
|
|
||||||
|
if min_amout_questions:
|
||||||
|
filter_other_quizzes = filter_other_quizzes.filter(max_amout_questions__gte=min_amout_questions)
|
||||||
|
try:
|
||||||
|
filter_my_quizzes =filter_my_quizzes.filter(max_amout_questions__gte=min_amout_questions)
|
||||||
|
except:
|
||||||
|
filter_my_quizzes = QivipQuiz.objects.none()
|
||||||
|
|
||||||
|
if max_amout_questions:
|
||||||
|
filter_other_quizzes = filter_other_quizzes.filter(max_amout_questions__lte=max_amout_questions)
|
||||||
|
try:
|
||||||
|
filter_my_quizzes =filter_my_quizzes.filter(max_amout_questions__lte=max_amout_questions)
|
||||||
|
except:
|
||||||
|
filter_my_quizzes = QivipQuiz.objects.none()
|
||||||
|
|
||||||
|
if username:
|
||||||
|
try:
|
||||||
|
user = User.objects.get(username=username) # Benutzer anhand des Namens holen
|
||||||
|
filter_other_quizzes = filter_other_quizzes.filter(user_id=user.id)
|
||||||
|
filter_my_quizzes = filter_my_quizzes.filter(user_id=user.id) # Nach der user_id filtern
|
||||||
|
except User.DoesNotExist:
|
||||||
|
filter_other_quizzes = QivipQuiz.objects.none() # Falls User nicht existiert, leere Query zurückgeben
|
||||||
|
filter_my_quizzes = QivipQuiz.objects.none()
|
||||||
|
|
||||||
|
try:
|
||||||
|
filter_other_quizzes=filter_other_quizzes.exclude(user_id=request.user)
|
||||||
|
except:
|
||||||
|
filter_other_quizzes=filter_other_quizzes
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
filter_other_quizzes = filter_other_quizzes.filter(max_amout_questions__gte=1).filter(status='öffentlich')
|
||||||
|
|
||||||
|
context = {
|
||||||
|
'show_search': True,
|
||||||
|
'filter_my_quizzes': filter_my_quizzes.order_by('-creation_date'),
|
||||||
|
'filter_other_quizzes': filter_other_quizzes.order_by('-creation_date'),
|
||||||
|
'form': form,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return render(request, 'library/overview_quiz.html', context)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Neues Quiz erstellen
|
||||||
|
@login_required
|
||||||
|
def new_quiz(request):
|
||||||
|
if request.method == 'POST':
|
||||||
|
form = QuizForm(request.POST, request.FILES)
|
||||||
|
if form.is_valid():
|
||||||
|
quiz = form.save(commit=False)
|
||||||
|
quiz.user_id = request.user
|
||||||
|
quiz.creator = request.user
|
||||||
|
quiz.save()
|
||||||
|
form.save_m2m() # Speichert die Many-to-Many Beziehungen (Tags)
|
||||||
|
return redirect('library:detail_quiz', pk=quiz.pk)
|
||||||
|
|
||||||
|
else:
|
||||||
|
form = QuizForm()
|
||||||
|
return render(request, 'library/form.html', {'form': form})
|
||||||
|
|
||||||
|
# Quiz bearbeiten
|
||||||
|
@login_required
|
||||||
|
def edit_quiz(request, pk):
|
||||||
|
quiz = get_object_or_404(QivipQuiz, pk=pk, user_id=request.user)
|
||||||
|
if request.method == 'POST':
|
||||||
|
form = QuizForm(request.POST, instance=quiz, files=request.FILES)
|
||||||
|
if form.is_valid():
|
||||||
|
|
||||||
|
form.save()
|
||||||
|
return redirect('library:detail_quiz', pk=pk)
|
||||||
|
#return modified(request, pk)
|
||||||
|
|
||||||
|
else:
|
||||||
|
form = QuizForm(instance=quiz)
|
||||||
|
return render(request, 'library/form.html', {'form': form})
|
||||||
|
|
||||||
|
# Quiz löschen
|
||||||
|
@login_required
|
||||||
|
def delete_quiz(request, pk):
|
||||||
|
quiz = get_object_or_404(QivipQuiz, pk=pk, user_id=request.user)
|
||||||
|
if request.method == 'POST':
|
||||||
|
quiz.delete()
|
||||||
|
return redirect('library:overview_quiz')
|
||||||
|
return render(request, 'library/delete_confirmation.html', {'object': quiz})
|
||||||
|
|
||||||
|
# Quiz anzeigen
|
||||||
|
def detail_quiz(request, pk):
|
||||||
|
#quiz = get_object_or_404(QivipQuiz, pk=pk, user_id=request.user)
|
||||||
|
quiz = get_object_or_404(QivipQuiz, pk=pk)
|
||||||
|
questions = QivipQuestion.objects.filter(quiz_id=quiz)
|
||||||
|
|
||||||
|
# Parse JSON data for each question
|
||||||
|
for question in questions:
|
||||||
|
if question.data:
|
||||||
|
question.data = json.loads(question.data)
|
||||||
|
|
||||||
|
context = {
|
||||||
|
'quiz': quiz,
|
||||||
|
'questions': questions
|
||||||
|
}
|
||||||
|
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
|
||||||
|
def copy_quiz(request, pk):
|
||||||
|
original_quiz = get_object_or_404(QivipQuiz, pk=pk)
|
||||||
|
|
||||||
|
|
||||||
|
# Quiz kopieren (ohne ID, damit ein neues Objekt erstellt wird)
|
||||||
|
|
||||||
|
# Quiz kopieren (ohne ID, damit ein neues Objekt erstellt wird)
|
||||||
|
|
||||||
|
new_quiz = original_quiz # Kopie erstellen (aber Achtung: Noch gleiche Referenz!)
|
||||||
|
new_quiz.pk = None # Setzt die ID auf None, damit Django es als neues Objekt erkennt
|
||||||
|
new_quiz.uuid = uuid.uuid4() # Neue UUID generieren
|
||||||
|
new_quiz.user_id = request.user # Neuer Besitzer ist der aktuelle User
|
||||||
|
new_quiz.name += " - Kopie" # Optional: Name anpassen
|
||||||
|
new_quiz.base_quiz_id = pk
|
||||||
|
#new_quiz.creator = original_quiz.creator or request.user
|
||||||
|
new_quiz.save() # Speichern als neues Objekt
|
||||||
|
# Optional: Beschreibung anpassen
|
||||||
|
# Alle zugehörigen Fragen kopieren
|
||||||
|
questions = QivipQuestion.objects.filter(quiz_id=pk)
|
||||||
|
for question in questions:
|
||||||
|
question.uuid = uuid.uuid4()
|
||||||
|
question.pk = None # Setze pk auf None, damit es als neues Objekt gespeichert wird
|
||||||
|
question.quiz_id = original_quiz # Verknüpfe mit dem neuen Quiz
|
||||||
|
question.data = question.data # `data`-Feld wird explizit übernommen # Verknüpfe mit dem neuen Quiz
|
||||||
|
question.save()
|
||||||
|
|
||||||
|
return redirect('library:detail_quiz', pk=new_quiz.pk)
|
||||||
|
|
||||||
|
|
||||||
|
# Übersicht aller Fragen
|
||||||
|
@login_required
|
||||||
|
def question_list(request):
|
||||||
|
questions = QivipQuestion.objects.filter(quiz_id__user_id=request.user)
|
||||||
|
|
||||||
|
# Parse JSON data for each question
|
||||||
|
for question in questions:
|
||||||
|
if question.data:
|
||||||
|
question.data = json.loads(question.data)
|
||||||
|
|
||||||
|
return render(request, 'library/question_list.html', {'questions': questions})
|
||||||
|
|
||||||
|
# Neue Frage erstellen
|
||||||
|
@login_required
|
||||||
|
def new_question(request):
|
||||||
|
question_type = request.GET.get('type')
|
||||||
|
quiz_id = request.GET.get('quiz_id')
|
||||||
|
|
||||||
|
if not quiz_id:
|
||||||
|
messages.error(request, 'Quiz ID muss angegeben werden.')
|
||||||
|
return redirect('library:overview_quiz')
|
||||||
|
|
||||||
|
try:
|
||||||
|
quiz = QivipQuiz.objects.get(pk=quiz_id, user_id=request.user)
|
||||||
|
except QivipQuiz.DoesNotExist:
|
||||||
|
messages.error(request, 'Quiz nicht gefunden oder keine Berechtigung.')
|
||||||
|
return redirect('library:overview_quiz')
|
||||||
|
|
||||||
|
if question_type not in ['multiple_choice', 'true_false']:
|
||||||
|
base_url = reverse('library:new_question')
|
||||||
|
return redirect(f'{base_url}?type=multiple_choice&quiz_id={quiz_id}')
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
question_text = request.POST.get('question', '')
|
||||||
|
|
||||||
|
# Handle different question types
|
||||||
|
if question_type == 'true_false':
|
||||||
|
correct_answer = request.POST.get('correct_answer') == 'true'
|
||||||
|
json_data = {
|
||||||
|
'type': question_type,
|
||||||
|
'question': question_text,
|
||||||
|
'options': [
|
||||||
|
{'value': 'Wahr', 'is_correct': correct_answer},
|
||||||
|
{'value': 'Falsch', 'is_correct': not correct_answer}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
elif question_type == 'multiple_choice':
|
||||||
|
options = []
|
||||||
|
i = 1
|
||||||
|
# Limit to maximum 6 options
|
||||||
|
while request.POST.get(f'option_{i}') and i <= 6:
|
||||||
|
is_correct = request.POST.get(f'correct_{i}') == '1'
|
||||||
|
options.append({
|
||||||
|
'order': i,
|
||||||
|
'value': request.POST.get(f'option_{i}'),
|
||||||
|
'is_correct': is_correct
|
||||||
|
})
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
# Validate minimum 2 options
|
||||||
|
if len(options) < 2:
|
||||||
|
messages.error(request, 'Mindestens zwei Optionen müssen angegeben werden.')
|
||||||
|
return redirect(request.get_full_path())
|
||||||
|
|
||||||
|
json_data = {
|
||||||
|
'type': question_type,
|
||||||
|
'question': question_text,
|
||||||
|
'options': options
|
||||||
|
}
|
||||||
|
|
||||||
|
question = QivipQuestion()
|
||||||
|
question.data = json.dumps(json_data)
|
||||||
|
question.quiz_id = quiz
|
||||||
|
question.save()
|
||||||
|
#return modified(request, pk=quiz.pk)
|
||||||
|
return redirect('library:detail_quiz', pk=quiz.pk)
|
||||||
|
else:
|
||||||
|
# Initialize empty question data for new questions
|
||||||
|
if question_type == 'true_false':
|
||||||
|
question_data = {
|
||||||
|
'type': question_type,
|
||||||
|
'question': '',
|
||||||
|
'options': [
|
||||||
|
{'value': 'Wahr', 'is_correct': True},
|
||||||
|
{'value': 'Falsch', 'is_correct': False}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
elif question_type == 'multiple_choice':
|
||||||
|
question_data = {
|
||||||
|
'type': question_type,
|
||||||
|
'question': '',
|
||||||
|
'options': [
|
||||||
|
{'value': '', 'is_correct': False},
|
||||||
|
{'value': '', 'is_correct': False}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
template_name = f'library/question/question_{question_type}.html'
|
||||||
|
context = {
|
||||||
|
'question': question_data,
|
||||||
|
'quiz_id': quiz_id,
|
||||||
|
'quiz': quiz
|
||||||
|
}
|
||||||
|
|
||||||
|
return render(request, template_name, context)
|
||||||
|
|
||||||
|
# Frage bearbeiten
|
||||||
|
@login_required
|
||||||
|
def edit_question(request, pk):
|
||||||
|
question = get_object_or_404(QivipQuestion, pk=pk, quiz_id__user_id=request.user)
|
||||||
|
if question.quiz_id.user_id != request.user:
|
||||||
|
return redirect('library:question_list')
|
||||||
|
|
||||||
|
# Parse the existing JSON data
|
||||||
|
try:
|
||||||
|
question_data = json.loads(question.data) if question.data else {}
|
||||||
|
question_type = question_data.get('type', 'multiple_choice')
|
||||||
|
|
||||||
|
# For true/false questions, get the correct answer from the options
|
||||||
|
if question_type == 'true_false':
|
||||||
|
# Default to true if no options exist
|
||||||
|
correct_answer = True
|
||||||
|
if question_data.get('options'):
|
||||||
|
correct_answer = question_data['options'][0].get('is_correct', True)
|
||||||
|
question_data = {
|
||||||
|
'type': question_type,
|
||||||
|
'question': question_data.get('question', ''),
|
||||||
|
'correct_answer': correct_answer, # Add this for template compatibility
|
||||||
|
'options': [
|
||||||
|
{'value': 'Wahr', 'is_correct': correct_answer},
|
||||||
|
{'value': 'Falsch', 'is_correct': not correct_answer}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
# For multiple choice questions
|
||||||
|
question_data.setdefault('type', question_type)
|
||||||
|
question_data.setdefault('question', '')
|
||||||
|
question_data.setdefault('options', [])
|
||||||
|
|
||||||
|
except (json.JSONDecodeError, AttributeError):
|
||||||
|
# Handle invalid JSON or None data
|
||||||
|
question_type = question_data.get('type', 'multiple_choice')
|
||||||
|
if question_type == 'true_false':
|
||||||
|
question_data = {
|
||||||
|
'type': question_type,
|
||||||
|
'question': '',
|
||||||
|
'correct_answer': True, # Default to true for new questions
|
||||||
|
'options': [
|
||||||
|
{'value': 'Wahr', 'is_correct': True},
|
||||||
|
{'value': 'Falsch', 'is_correct': False}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
question_data = {
|
||||||
|
'type': question_type,
|
||||||
|
'question': '',
|
||||||
|
'options': []
|
||||||
|
}
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
question_text = request.POST.get('question', '')
|
||||||
|
|
||||||
|
# Handle different question types
|
||||||
|
if question_type == 'true_false':
|
||||||
|
correct_answer = request.POST.get('correct_answer') == 'true'
|
||||||
|
json_data = {
|
||||||
|
'type': question_type,
|
||||||
|
'question': question_text,
|
||||||
|
'options': [
|
||||||
|
{'value': 'Wahr', 'is_correct': correct_answer},
|
||||||
|
{'value': 'Falsch', 'is_correct': not correct_answer}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
elif question_type == 'multiple_choice':
|
||||||
|
options = []
|
||||||
|
i = 1
|
||||||
|
# Limit to maximum 6 options
|
||||||
|
while request.POST.get(f'option_{i}') and i <= 6:
|
||||||
|
options.append({
|
||||||
|
'order': i,
|
||||||
|
'value': request.POST.get(f'option_{i}'),
|
||||||
|
'is_correct': request.POST.get(f'correct_{i}') == '1'
|
||||||
|
})
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
# Validate minimum 2 options
|
||||||
|
if len(options) < 2:
|
||||||
|
messages.error(request, 'Mindestens zwei Optionen müssen angegeben werden.')
|
||||||
|
return redirect(request.get_full_path())
|
||||||
|
|
||||||
|
# Validate maximum 6 options
|
||||||
|
if len(options) > 6:
|
||||||
|
messages.error(request, 'Maximal 6 Optionen sind erlaubt.')
|
||||||
|
return redirect(request.get_full_path())
|
||||||
|
|
||||||
|
json_data = {
|
||||||
|
'type': question_type,
|
||||||
|
'question': question_text,
|
||||||
|
'options': options
|
||||||
|
}
|
||||||
|
|
||||||
|
question.data = json.dumps(json_data)
|
||||||
|
question.save()
|
||||||
|
#return modified(request, question.quiz_id.pk)
|
||||||
|
return redirect('library:detail_quiz', pk=question.quiz_id.pk)
|
||||||
|
|
||||||
|
else:
|
||||||
|
template_name = f'library/question/question_{question_type}.html'
|
||||||
|
context = {
|
||||||
|
'question': {'data': question_data}, # Wrap in data structure expected by template
|
||||||
|
'quiz_id': question.quiz_id.pk,
|
||||||
|
'quiz': question.quiz_id
|
||||||
|
}
|
||||||
|
|
||||||
|
return render(request, template_name, context)
|
||||||
|
|
||||||
|
|
||||||
|
# Frage löschen
|
||||||
|
@login_required
|
||||||
|
def delete_question(request, pk):
|
||||||
|
question = get_object_or_404(QivipQuestion, pk=pk, quiz_id__user_id=request.user)
|
||||||
|
|
||||||
|
# Parse JSON data for question
|
||||||
|
if question.data:
|
||||||
|
question.data = json.loads(question.data)
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
question.delete()
|
||||||
|
return redirect('library:detail_quiz', pk=question.quiz_id.pk)
|
||||||
|
return render(request, 'library/delete_confirmation.html', {'object': question})
|
||||||
35
django/package-lock.json
generated
Normal file
35
django/package-lock.json
generated
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"name": "django",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "django",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"swiper": "^11.2.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/swiper": {
|
||||||
|
"version": "11.2.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/swiper/-/swiper-11.2.6.tgz",
|
||||||
|
"integrity": "sha512-8aXpYKtjy3DjcbzZfz+/OX/GhcU5h+looA6PbAzHMZT6ESSycSp9nAjPCenczgJyslV+rUGse64LMGpWE3PX9Q==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "patreon",
|
||||||
|
"url": "https://www.patreon.com/swiperjs"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "open_collective",
|
||||||
|
"url": "http://opencollective.com/swiper"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 4.7.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
15
django/package.json
Normal file
15
django/package.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "django",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"description": "",
|
||||||
|
"dependencies": {
|
||||||
|
"swiper": "^11.2.6"
|
||||||
|
}
|
||||||
|
}
|
||||||
0
django/play/__init__.py
Normal file
0
django/play/__init__.py
Normal file
6
django/play/admin.py
Normal file
6
django/play/admin.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
from .models import QuizGame, QuizGameParticipant
|
||||||
|
|
||||||
|
# Register your models here.
|
||||||
|
admin.site.register(QuizGame)
|
||||||
|
admin.site.register(QuizGameParticipant)
|
||||||
6
django/play/apps.py
Normal file
6
django/play/apps.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class PlayConfig(AppConfig):
|
||||||
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
|
name = 'play'
|
||||||
37
django/play/migrations/0001_initial.py
Normal file
37
django/play/migrations/0001_initial.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-03-15 13:48
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('library', '0015_alter_qivipquiz_difficulty'),
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='QuizGame',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('join_code', models.CharField(max_length=6, unique=True)),
|
||||||
|
('host_user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='host_user', to=settings.AUTH_USER_MODEL)),
|
||||||
|
('quiz_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='library.qivipquiz')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='QuizGameParticipant',
|
||||||
|
fields=[
|
||||||
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('display_name', models.CharField(max_length=15, verbose_name='Anzeigename')),
|
||||||
|
('score', models.IntegerField(max_length=10, verbose_name='Punkte')),
|
||||||
|
('avatar', models.CharField(max_length=200)),
|
||||||
|
('quiz_game', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='participant', to='play.quizgame')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
18
django/play/migrations/0002_alter_quizgame_join_code.py
Normal file
18
django/play/migrations/0002_alter_quizgame_join_code.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-03-15 13:59
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('play', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='quizgame',
|
||||||
|
name='join_code',
|
||||||
|
field=models.CharField(blank=True, max_length=6, unique=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# Generated by Django 5.1.7 on 2025-03-15 19:05
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('play', '0002_alter_quizgame_join_code'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='quizgameparticipant',
|
||||||
|
name='participant_id',
|
||||||
|
field=models.CharField(default=1, max_length=200, unique=True),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='quizgameparticipant',
|
||||||
|
name='avatar',
|
||||||
|
field=models.CharField(blank=True, default='', max_length=200),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='quizgameparticipant',
|
||||||
|
name='score',
|
||||||
|
field=models.IntegerField(default=0, verbose_name='Punkte'),
|
||||||
|
),
|
||||||
|
]
|
||||||
0
django/play/migrations/__init__.py
Normal file
0
django/play/migrations/__init__.py
Normal file
40
django/play/models.py
Normal file
40
django/play/models.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
from django.db import models
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
from library.models import QivipQuiz
|
||||||
|
from django.http import response
|
||||||
|
import random, string
|
||||||
|
|
||||||
|
# Create your models here.
|
||||||
|
class QuizGame(models.Model):
|
||||||
|
host_user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='host_user')
|
||||||
|
join_code = models.CharField(max_length=6, unique=True, blank=True)
|
||||||
|
quiz_id = models.ForeignKey(QivipQuiz, on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
if not self.join_code:
|
||||||
|
self.join_code = self.generate_unique_code()
|
||||||
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
|
def generate_unique_code(self):
|
||||||
|
for i in range(10):
|
||||||
|
new_code = ''.join(random.choices(string.digits, k=6))
|
||||||
|
if not QuizGame.objects.filter(join_code=new_code).exists():
|
||||||
|
return new_code
|
||||||
|
|
||||||
|
class QuizGameParticipant(models.Model):
|
||||||
|
participant_id = models.CharField(max_length=200, unique=True)
|
||||||
|
display_name = models.CharField(verbose_name="Anzeigename", max_length=15)
|
||||||
|
quiz_game = models.ForeignKey(QuizGame, on_delete=models.CASCADE, related_name="participant")
|
||||||
|
score = models.IntegerField(verbose_name="Punkte", default=0)
|
||||||
|
avatar = models.CharField(max_length=200, blank=True, default="")
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
if not self.participant_id:
|
||||||
|
self.participant_id = self.generate_unique_id()
|
||||||
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
|
def generate_unique_id(self):
|
||||||
|
for i in range(10):
|
||||||
|
new_id = ''.join(random.choices(string.digits + string.ascii_lowercase, k=60))
|
||||||
|
if not QuizGameParticipant.objects.filter(participant_id=new_id).exists():
|
||||||
|
return new_id
|
||||||
3
django/play/tests.py
Normal file
3
django/play/tests.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
10
django/play/urls.py
Normal file
10
django/play/urls.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
from django.urls import path
|
||||||
|
from . import views
|
||||||
|
|
||||||
|
app_name = 'play'
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('lobby/<str:join_code>', views.lobby, name='lobby'),
|
||||||
|
path('lobby/<str:join_code>/participate', views.create_participant, name='create_participant'),
|
||||||
|
path('join', views.join_game, name='join_game'),
|
||||||
|
]
|
||||||
60
django/play/views.py
Normal file
60
django/play/views.py
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
from django.shortcuts import render
|
||||||
|
from django.shortcuts import render, redirect, get_object_or_404, reverse
|
||||||
|
from play.models import QuizGame, QuizGameParticipant
|
||||||
|
from library.models import QivipQuiz
|
||||||
|
from django.http import HttpResponseRedirect
|
||||||
|
|
||||||
|
# Create your views here.
|
||||||
|
def lobby(request, join_code):
|
||||||
|
if not "participant_id" in request.COOKIES:
|
||||||
|
return redirect('play:create_participant', join_code=join_code)
|
||||||
|
participant_id = request.COOKIES['participant_id']
|
||||||
|
quiz_game = get_object_or_404(QuizGame, join_code=join_code)
|
||||||
|
quiz = get_object_or_404(QivipQuiz, pk=quiz_game.quiz_id.id)
|
||||||
|
participant = get_object_or_404(QuizGameParticipant, participant_id=participant_id)
|
||||||
|
|
||||||
|
if not participant.quiz_game.join_code == join_code:
|
||||||
|
participant.quiz_game = quiz_game
|
||||||
|
participant.save()
|
||||||
|
|
||||||
|
context = {
|
||||||
|
'debug': "test",
|
||||||
|
'participant': participant,
|
||||||
|
'quiz': quiz,
|
||||||
|
}
|
||||||
|
|
||||||
|
return render(request, 'play/lobby.html', context=context)
|
||||||
|
|
||||||
|
def create_participant(request, join_code):
|
||||||
|
if "participant_id" in request.COOKIES: # Umleiten, falls Teilnehmer bereits erstellt
|
||||||
|
return redirect('play:lobby', join_code=join_code)
|
||||||
|
if request.method == 'POST':
|
||||||
|
display_name = request.POST.get('display_name')
|
||||||
|
join_code = request.POST.get('join_code')
|
||||||
|
try:
|
||||||
|
quiz = QuizGame.objects.get(join_code=join_code)
|
||||||
|
participant = QuizGameParticipant()
|
||||||
|
participant.display_name = display_name
|
||||||
|
participant.quiz_game = quiz
|
||||||
|
participant.save()
|
||||||
|
|
||||||
|
response = HttpResponseRedirect(reverse('play:lobby', kwargs={'join_code': join_code}))
|
||||||
|
response.set_cookie('participant_id', participant.participant_id, max_age=3600)
|
||||||
|
|
||||||
|
return response
|
||||||
|
except QuizGame.DoesNotExist:
|
||||||
|
# TODO: Fehlermeldung fuer nicht-existierendes Quiz
|
||||||
|
pass
|
||||||
|
|
||||||
|
return render(request, 'play/initialize_participant.html', {'join_code': join_code})
|
||||||
|
|
||||||
|
def join_game(request):
|
||||||
|
if request.method == 'POST':
|
||||||
|
join_code = request.POST.get('game_code')
|
||||||
|
try:
|
||||||
|
quiz = QuizGame.objects.get(join_code=join_code)
|
||||||
|
return redirect('play:lobby', join_code=join_code)
|
||||||
|
except QuizGame.DoesNotExist:
|
||||||
|
# TODO: Mit message eine Fehlermeldung weitergeben (und im entsprechenden Template Designen)
|
||||||
|
pass
|
||||||
|
return render(request, 'play/join_game.html')
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
@import 'tailwindcss';
|
@import 'tailwindcss';
|
||||||
|
|
||||||
|
qp-container {
|
||||||
|
@apply max-w-xl w-full mx-auto;
|
||||||
|
}
|
||||||
|
|
||||||
nav div ul.qp-nav-list li {
|
nav div ul.qp-nav-list li {
|
||||||
@apply text-white hover:scale-110 hover:border-b-2 hover:border-white transition duration-200;
|
@apply text-white hover:scale-110 hover:border-b-2 hover:border-white transition duration-200;
|
||||||
}
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user