Merge pull request 'feature/tourunament-classification' (#41) from feature/tourunament-classification into master
Reviewed-on: #41
This commit is contained in:
commit
55791f521b
@ -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 %}
|
||||
|
26
trials/migrations/0029_tournamentclassification.py
Normal file
26
trials/migrations/0029_tournamentclassification.py
Normal file
@ -0,0 +1,26 @@
|
||||
# Generated by Django 3.2.9 on 2022-06-04 15:02
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('trials', '0028_ratetest_ratetournament'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='TournamentClassification',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('score', models.IntegerField()),
|
||||
('date', models.DateField()),
|
||||
('tournament', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='tournament_classification', to='trials.tournament')),
|
||||
('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='tournament_classification', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.2.9 on 2022-06-04 15:06
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('trials', '0029_tournamentclassification'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='tournamentclassification',
|
||||
name='date',
|
||||
field=models.DateField(auto_now_add=True),
|
||||
),
|
||||
]
|
@ -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,30 @@ 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")
|
||||
return render(request, 'tournament_classification.html', context)
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user