From f08f52c12966edd6354b2bd6d049746d4d838712 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 30 Apr 2020 01:20:50 +0200 Subject: [PATCH] Display team solutions --- apps/member/management/commands/import_olddb.py | 6 +++++- apps/member/models.py | 9 +++++++++ apps/member/urls.py | 4 ++-- apps/member/views.py | 16 +++++++++++++++- templates/tournament/team_detail.html | 16 +++++++++++++--- 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/apps/member/management/commands/import_olddb.py b/apps/member/management/commands/import_olddb.py index 7df074a..3188455 100644 --- a/apps/member/management/commands/import_olddb.py +++ b/apps/member/management/commands/import_olddb.py @@ -210,7 +210,11 @@ class Command(BaseCommand): obj_dict["user"] = TFJMUser.objects.get(args[1]), obj_dict["type"] = args[4].lower() else: - obj_dict["team"] = Team.objects.get(pk=args[2]) + try: + obj_dict["team"] = Team.objects.get(pk=args[2]) + except Team.DoesNotExist: + print("Team with pk {} does not exist, ignoring".format(args[2])) + continue with transaction.atomic(): if args[4] != "MOTIVATION_LETTER": Authorization.objects.create(**obj_dict) diff --git a/apps/member/models.py b/apps/member/models.py index cb83b8a..7d96bdc 100644 --- a/apps/member/models.py +++ b/apps/member/models.py @@ -241,6 +241,7 @@ class Solution(Document): class Meta: verbose_name = _("solution") verbose_name_plural = _("solutions") + unique_together = ('team', 'problem',) def __str__(self): return _("Solution of team {trigram} for problem {problem}")\ @@ -265,6 +266,14 @@ class Synthesis(Document): verbose_name=_("dest"), ) + round = models.PositiveSmallIntegerField( + choices=[ + (1, _("Round 1")), + (2, _("Round 2")), + ], + verbose_name=_("round"), + ) + def save(self, **kwargs): self.type = "synthesis" super().save(**kwargs) diff --git a/apps/member/urls.py b/apps/member/urls.py index ac94b3b..87ee918 100644 --- a/apps/member/urls.py +++ b/apps/member/urls.py @@ -1,10 +1,10 @@ from django.urls import path -from .views import CreateUserView - +from .views import CreateUserView, DocumentView app_name = "member" urlpatterns = [ path('signup/', CreateUserView.as_view(), name="signup"), + path("file//", DocumentView.as_view(), name="document"), ] diff --git a/apps/member/views.py b/apps/member/views.py index 240250c..3398b6e 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -1,10 +1,24 @@ +from django.contrib.auth.mixins import LoginRequiredMixin +from django.core.exceptions import PermissionDenied +from django.http import FileResponse +from django.views import View from django.views.generic import CreateView from .forms import SignUpForm -from .models import TFJMUser +from .models import TFJMUser, Document class CreateUserView(CreateView): model = TFJMUser form_class = SignUpForm template_name = "registration/signup.html" + + +class DocumentView(LoginRequiredMixin, View): + def get(self, request, *args, **kwargs): + doc = Document.objects.get(file=self.kwargs["file"]) + + if not request.user.admin: + raise PermissionDenied + + return FileResponse(doc.file, content_type="application/pdf") diff --git a/templates/tournament/team_detail.html b/templates/tournament/team_detail.html index 2fd0bb2..224480d 100644 --- a/templates/tournament/team_detail.html +++ b/templates/tournament/team_detail.html @@ -40,10 +40,20 @@

{% trans "Documents" %}

- {% if team.motivation_letters %} + {% if team.motivation_letters.count %}
- {% blocktrans with version=team.motivation_letters.count %}Motivation letter (version {{ version }}):{% endblocktrans %} - {% trans "Download" %} + {% blocktrans with version=team.motivation_letters.count %}Motivation letter (version {{ version }}):{% endblocktrans %} + {% trans "Download" %} +
+ {% endif %} + + {% if team.solutions.count %} +
+
{% endif %} {% endblock %}