develop/soita-2.0 #36
@ -19,4 +19,9 @@ class Question(models.Model):
|
||||
for answer in self.answers.all()
|
||||
]
|
||||
|
||||
tournament = models.ManyToManyField(
|
||||
"trials.Tournament",
|
||||
null=True
|
||||
)
|
||||
|
||||
objects = QuestionManager()
|
@ -20,9 +20,9 @@
|
||||
<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>
|
||||
{% 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 %}
|
||||
<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>
|
||||
<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>
|
||||
|
28
templates/createTournament.html
Normal file
28
templates/createTournament.html
Normal 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 %}
|
23
templates/tournaments.html
Normal file
23
templates/tournaments.html
Normal 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 %}
|
||||
|
@ -103,4 +103,15 @@ class SolvedTest(models.Model):
|
||||
null=True,
|
||||
related_name="answers",
|
||||
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)
|
||||
|
@ -1,7 +1,7 @@
|
||||
from django.urls import path
|
||||
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.register("items", TestModelViewSet)
|
||||
@ -24,7 +24,9 @@ urlpatterns = [
|
||||
path('add/questions', addQuestions, name="addQuestions"),
|
||||
path('my', myTests, name="myTests"),
|
||||
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
|
||||
|
@ -8,7 +8,7 @@ from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from questions.models import Question
|
||||
from trials.models import Test, SolvedTest
|
||||
from trials.models import Test, SolvedTest, Tournament
|
||||
from trials.serializers import TestSerializer
|
||||
from django.conf import settings
|
||||
from django.shortcuts import render, redirect
|
||||
@ -83,6 +83,15 @@ def addQuestions(request, **kwargs):
|
||||
return redirect('home')
|
||||
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):
|
||||
template_name = settings.BASE_DIR + f"/templates/addQuestionToExistingTest.html"
|
||||
|
@ -90,7 +90,8 @@ def register(request):
|
||||
email=form.cleaned_data["email"],
|
||||
first_name=form.cleaned_data["first_name"],
|
||||
last_name=form.cleaned_data["last_name"],
|
||||
password=form.cleaned_data["password1"]
|
||||
password=form.cleaned_data["password1"],
|
||||
type="standard"
|
||||
)
|
||||
return redirect('register_success')
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user