develop/soita-2.0 #36

Merged
s470631 merged 12 commits from develop/soita-2.0 into master 2022-05-24 21:02:17 +02:00
8 changed files with 86 additions and 7 deletions
Showing only changes of commit 71cd22bbbb - Show all commits

View File

@ -19,4 +19,9 @@ class Question(models.Model):
for answer in self.answers.all() for answer in self.answers.all()
] ]
tournament = models.ManyToManyField(
"trials.Tournament",
null=True
)
objects = QuestionManager() objects = QuestionManager()

View File

@ -20,9 +20,9 @@
<a href="{% url 'popular' %}"><i class="fa-solid fa-star"></i> Popularne </a> <a href="{% url 'popular' %}"><i class="fa-solid fa-star"></i> Popularne </a>
<a href="{% url 'hard' %}"><i class="fa-solid fa-fire-flame-curved"></i> Trudne </a> <a href="{% url 'hard' %}"><i class="fa-solid fa-fire-flame-curved"></i> Trudne </a>
{% if user.type == "admin" %} {% if user.type == "admin" %}
<a href="{% url 'home' %}"><i class="fa-solid fa-trophy"></i> Stwórz turniej </a> <a href="{% url 'CreateTournament' %}"><i class="fa-solid fa-trophy"></i> Stwórz turniej </a>
{% endif %} {% endif %}
<a href="{% url 'home' %}"><i class="fa-solid fa-trophy"></i> Turnieje </a> <a href="{% url 'tournaments' %}"><i class="fa-solid fa-trophy"></i> Turnieje </a>
<br> <br>
<a href="{% url 'newTest' %}"><i class="fa-solid fa-circle-plus"></i> Stwórz test</a> <a href="{% url 'newTest' %}"><i class="fa-solid fa-circle-plus"></i> Stwórz test</a>
<a href="{% url 'myTests' %}"><i class="fa-solid fa-note-sticky"></i> Twoje testy</a> <a href="{% url 'myTests' %}"><i class="fa-solid fa-note-sticky"></i> Twoje testy</a>

View File

@ -0,0 +1,28 @@
{% extends "base.html" %}
{% block title %}Stwórz turniej{% endblock %}
{% block content %}
<h1>Stwórz turniej</h1>
<form method="post" novalidate>
{% for question in questions %}
<div class="mainTestName">
<div class="question_title" style="padding-top:15px; padding-bottom:10px; padding-left:5px;">
<input class="form-check-input me-1" type="radio" value={{ question.id }}>
{{ question.description }}
</div>
<div class="list-group">
{% for answer in question.answers.all %}
<label class="list-group-item">
- {{ answer.description }}<br>
</label>
{% endfor %}
</div>
{% endfor %}
</div>
</form>
<div class="testContent">
<input type="submit" value="Wyślij odpowiedzi">
</div>
{% endblock %}

View File

@ -0,0 +1,23 @@
{% extends "base.html" %}
{% block title %}Turnieje{% endblock %}
{% block content %}
<h1>Twoje testy</h1>
{% for test in tests %}
<div class="mainTestContainer">
<div class="mainTestName">
{{tournament.name}}
<!-- {% if test.password != "" %}-->
<!-- <i class="fa-solid fa-lock locked" title="Test chroniony hasłem"></i>-->
<!-- {% endif %}-->
</div>
<!-- <div class="mainTestDesc">-->
<!-- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus volutpat scelerisque tortor, id sodales leo finibus id. Vivamus id viverra nunc, ac faucibus metus. Nulla a mauris imperdiet sapien lobortis dapibus. Quisque ornare posuere pulvinar.-->
<!-- </div>-->
<button><a href="/tests/{{tournament.id}}/show">Rozwiąż</a></button>
</div>
<br>
{% endfor %}
{% endblock %}

View File

@ -104,3 +104,14 @@ class SolvedTest(models.Model):
related_name="answers", related_name="answers",
on_delete=models.CASCADE on_delete=models.CASCADE
) )
class Tournament(models.Model):
name = models.CharField(max_length=100)
created_by = models.ForeignKey(
"users.User",
null=True,
related_name="tournaments",
on_delete=models.CASCADE
)
password = models.CharField(max_length=100)

View File

@ -1,7 +1,7 @@
from django.urls import path from django.urls import path
from rest_framework.routers import DefaultRouter from rest_framework.routers import DefaultRouter
from trials.views import TestModelViewSet, TestTemplateView, TestValidateAPIView, TestResultView, rateTest, addTest, addQuestions, myTests, solvedTests, solvedTestsDetailed, EditTestTemplateView, deleteTest, AddQuestionToExistingTest, RemoveQuestionFromExistingTest, EditQuestionTemplateView, editName, editVisible, editPassword, TestPasswordTemplateView from trials.views import TestModelViewSet, TestTemplateView, TestValidateAPIView, TestResultView, rateTest, addTest, addQuestions, myTests, solvedTests, solvedTestsDetailed, EditTestTemplateView, deleteTest, AddQuestionToExistingTest, RemoveQuestionFromExistingTest, EditQuestionTemplateView, editName, editVisible, editPassword, TestPasswordTemplateView, TournamentView, CreateTournamentView
router = DefaultRouter(trailing_slash=False) router = DefaultRouter(trailing_slash=False)
router.register("items", TestModelViewSet) router.register("items", TestModelViewSet)
@ -24,7 +24,9 @@ urlpatterns = [
path('add/questions', addQuestions, name="addQuestions"), path('add/questions', addQuestions, name="addQuestions"),
path('my', myTests, name="myTests"), path('my', myTests, name="myTests"),
path('solved', solvedTests, name="solvedTests"), path('solved', solvedTests, name="solvedTests"),
path('solved/<int:test_id>', solvedTestsDetailed, name="solvedTests") path('solved/<int:test_id>', solvedTestsDetailed, name="solvedTests"),
path('tournamets', TournamentView, name="tournaments"),
path('add/tournament', CreateTournamentView, name="CreateTournament")
] ]
urlpatterns += router.urls urlpatterns += router.urls

View File

@ -8,7 +8,7 @@ from rest_framework.response import Response
from rest_framework.views import APIView from rest_framework.views import APIView
from questions.models import Question from questions.models import Question
from trials.models import Test, SolvedTest from trials.models import Test, SolvedTest, Tournament
from trials.serializers import TestSerializer from trials.serializers import TestSerializer
from django.conf import settings from django.conf import settings
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
@ -83,6 +83,15 @@ def addQuestions(request, **kwargs):
return redirect('home') return redirect('home')
return render(request, 'addQuestions.html') return render(request, 'addQuestions.html')
def TournamentView(request):
context = {}
context['tournament'] = Tournament.objects.all()
return render(request, 'tournaments.html', context)
def CreateTournamentView(request):
context = {}
context['questions'] = Question.objects.all()
return render(request, 'createTournament.html', context)
class AddQuestionToExistingTest(TemplateView): class AddQuestionToExistingTest(TemplateView):
template_name = settings.BASE_DIR + f"/templates/addQuestionToExistingTest.html" template_name = settings.BASE_DIR + f"/templates/addQuestionToExistingTest.html"

View File

@ -90,7 +90,8 @@ def register(request):
email=form.cleaned_data["email"], email=form.cleaned_data["email"],
first_name=form.cleaned_data["first_name"], first_name=form.cleaned_data["first_name"],
last_name=form.cleaned_data["last_name"], last_name=form.cleaned_data["last_name"],
password=form.cleaned_data["password1"] password=form.cleaned_data["password1"],
type="standard"
) )
return redirect('register_success') return redirect('register_success')
else: else: