add tournament ranking
This commit is contained in:
parent
26ffc43918
commit
d7e9b8fb3a
@ -23,6 +23,7 @@
|
||||
<a href="{% url 'CreateTournament' %}"><i class="fa-solid fa-trophy"></i> Stwórz turniej </a>
|
||||
{% endif %}
|
||||
<a href="{% url 'tournaments' %}"><i class="fa-solid fa-trophy"></i> Turnieje </a>
|
||||
<a href="{% url 'TournamentClassification' %}"><i class="fa-solid fa-trophy"></i> Ranking turniejowy </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>
|
||||
|
@ -6,8 +6,8 @@
|
||||
{% block content %}
|
||||
<h1>Stwórz turniej</h1>
|
||||
<form method="post" novalidate>
|
||||
<span>name:<input id="name" type="text" name="name" value="{{ tournament.name }}"></span><br>
|
||||
<span>passing score:<input id="passing_score" type="text" name="passing_score" value="{{ tournament.passing_score }}"></span>
|
||||
<span>Nazwa turnieju:<input id="name" type="text" name="name" value="{{ tournament.name }}"></span><br>
|
||||
<span>Próg zdawalności:<input id="passing_score" type="text" name="passing_score" value="{{ tournament.passing_score }}"></span>
|
||||
{% for question in questions %}
|
||||
<div class="tournamentQuestionContainer">
|
||||
<div class="mainTestName">
|
||||
|
34
templates/tournament_classification.html
Normal file
34
templates/tournament_classification.html
Normal file
@ -0,0 +1,34 @@
|
||||
{% extends "base.html" %}
|
||||
{% load social_share %}
|
||||
|
||||
{% block title %}Tournament classification{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<form method="post">
|
||||
<label for="name">Turniej: </label>
|
||||
<select name="name" id="name">
|
||||
{% for tournament_name in tournament_names %}
|
||||
<option value="{{tournament_name}}">{{tournament_name}}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
|
||||
<div class="testContent">
|
||||
<input type="submit" value="Wyszukaj">
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{% if final_tournaments%}
|
||||
{% for tournament in final_tournaments%}
|
||||
{{forloop.counter}}
|
||||
tuniej: {{tournament.tournament__name}}
|
||||
wynik: {{tournament.score}}
|
||||
gracz: {{tournament.user__email}}
|
||||
data: {{tournament.date|date:"d M Y"}}
|
||||
<br>
|
||||
|
||||
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
@ -210,4 +210,24 @@ class RateTournament(models.Model):
|
||||
null=True,
|
||||
related_name="rate_tournaments",
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class TournamentClassification(models.Model):
|
||||
|
||||
user = models.ForeignKey(
|
||||
"users.User",
|
||||
null=True,
|
||||
related_name="tournament_classification",
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
|
||||
tournament = models.ForeignKey(
|
||||
"Tournament",
|
||||
null=True,
|
||||
related_name="tournament_classification",
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
|
||||
score = models.IntegerField()
|
||||
date = models.DateField(auto_now_add=True)
|
||||
|
@ -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, TournamentView, CreateTournamentView, TournamentTemplateView, TournamentResultView
|
||||
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, TournamentTemplateView, TournamentResultView, TournamentClassificationView
|
||||
|
||||
router = DefaultRouter(trailing_slash=False)
|
||||
router.register("items", TestModelViewSet)
|
||||
@ -28,7 +28,8 @@ urlpatterns = [
|
||||
path('tournamets', TournamentView, name="tournaments"),
|
||||
path('add/tournament', CreateTournamentView, name="CreateTournament"),
|
||||
path('<int:tournament_id>/tournament/show', TournamentTemplateView.as_view()),
|
||||
path('<int:tournament_id>/tournament/result', TournamentResultView.as_view())
|
||||
path('<int:tournament_id>/tournament/result', TournamentResultView.as_view()),
|
||||
path('tournament/classification', TournamentClassificationView.as_view(), name="TournamentClassification")
|
||||
]
|
||||
|
||||
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, Tournament, RateTournament, RateTest
|
||||
from trials.models import Test, SolvedTest, Tournament, RateTournament, RateTest, TournamentClassification
|
||||
from trials.serializers import TestSerializer
|
||||
from django.conf import settings
|
||||
from django.shortcuts import render, redirect
|
||||
@ -448,7 +448,7 @@ class TestTemplateView(TemplateView):
|
||||
test.save()
|
||||
return HttpResponseRedirect(f'result')
|
||||
|
||||
|
||||
# here
|
||||
class TournamentTemplateView(TemplateView):
|
||||
PASSED = "Zaliczony"
|
||||
FAILED = "Niezaliczony"
|
||||
@ -516,6 +516,11 @@ class TournamentTemplateView(TemplateView):
|
||||
# user=request.user,
|
||||
# test=test
|
||||
# )
|
||||
TournamentClassification.objects.create(
|
||||
user=request.user,
|
||||
tournament=tournament,
|
||||
score=score,
|
||||
)
|
||||
tournament.completions += 1
|
||||
tournament.total_percentage_scored_by_users += int(score / max * 100)
|
||||
if tournament.completions >= 5:
|
||||
@ -595,6 +600,38 @@ class TestResultView(TemplateView):
|
||||
permission_classes = []
|
||||
template_name = settings.BASE_DIR + f"/templates/result.html"
|
||||
|
||||
|
||||
class TournamentResultView(TemplateView):
|
||||
permission_classes = []
|
||||
template_name = settings.BASE_DIR + f"/templates/tournament_result.html"
|
||||
|
||||
|
||||
class TournamentClassificationView(TemplateView):
|
||||
permission_classes = []
|
||||
template_name = settings.BASE_DIR + f"/templates/tournament_classification.html"
|
||||
|
||||
def get_queryset(self):
|
||||
return TournamentClassification.objects.all()
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["tournament_names"] = self.get_queryset().values_list("tournament__name", flat=True).order_by("tournament__name").distinct()
|
||||
return context
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
name = request.POST["name"]
|
||||
context["tournament_names"] = self.get_queryset().values_list("tournament__name", flat=True).order_by("tournament__name").distinct()
|
||||
context["final_tournaments"] = TournamentClassification.objects.filter(tournament__name=name).values("tournament__name","score", "date", "user__email").order_by("-score", "date")
|
||||
# for tc in tournament_classification:
|
||||
# final_tournaments.append({
|
||||
# "name": tc.tournament.name,
|
||||
# "user": tc.user,
|
||||
# "date": tc.date
|
||||
# })
|
||||
# import pdb;
|
||||
# pdb.set_trace()
|
||||
return render(request, 'tournament_classification.html', context)
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user