diff --git a/templates/tournament_classification.html b/templates/tournament_classification.html
new file mode 100644
index 0000000..0ea5c64
--- /dev/null
+++ b/templates/tournament_classification.html
@@ -0,0 +1,34 @@
+{% extends "base.html" %}
+{% load social_share %}
+
+{% block title %}Tournament classification{% endblock %}
+
+{% block content %}
+
+
+{% 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"}}
+
+
+
+{% endfor %}
+{% endif %}
+
+{% endblock %}
+
diff --git a/trials/migrations/0029_tournamentclassification.py b/trials/migrations/0029_tournamentclassification.py
new file mode 100644
index 0000000..765fee9
--- /dev/null
+++ b/trials/migrations/0029_tournamentclassification.py
@@ -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)),
+ ],
+ ),
+ ]
diff --git a/trials/migrations/0030_alter_tournamentclassification_date.py b/trials/migrations/0030_alter_tournamentclassification_date.py
new file mode 100644
index 0000000..ab0d912
--- /dev/null
+++ b/trials/migrations/0030_alter_tournamentclassification_date.py
@@ -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),
+ ),
+ ]
diff --git a/trials/models.py b/trials/models.py
index e5b213e..7027711 100644
--- a/trials/models.py
+++ b/trials/models.py
@@ -210,4 +210,24 @@ class RateTournament(models.Model):
null=True,
related_name="rate_tournaments",
on_delete=models.CASCADE
- )
\ No newline at end of file
+ )
+
+
+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)
diff --git a/trials/urls.py b/trials/urls.py
index fe2b64c..dafe5cc 100644
--- a/trials/urls.py
+++ b/trials/urls.py
@@ -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('
/tournament/show', TournamentTemplateView.as_view()),
- path('/tournament/result', TournamentResultView.as_view())
+ path('/tournament/result', TournamentResultView.as_view()),
+ path('tournament/classification', TournamentClassificationView.as_view(), name="TournamentClassification")
]
urlpatterns += router.urls
diff --git a/trials/views.py b/trials/views.py
index 8719421..6ca956a 100644
--- a/trials/views.py
+++ b/trials/views.py
@@ -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)
+
+
+