Display team solutions

This commit is contained in:
Yohann D'ANELLO 2020-04-30 01:20:50 +02:00
parent 3fdda5a030
commit f08f52c129
5 changed files with 44 additions and 7 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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/<str:file>/", DocumentView.as_view(), name="document"),
]

View File

@ -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")

View File

@ -40,10 +40,20 @@
<h4>{% trans "Documents" %}</h4>
{% if team.motivation_letters %}
{% if team.motivation_letters.count %}
<div class="alert alert-info">
{% blocktrans with version=team.motivation_letters.count %}Motivation letter (version {{ version }}):{% endblocktrans %}
<a href="{{ team.motivation_letters.last.file.url }}">{% trans "Download" %}</a>
<strong>{% blocktrans with version=team.motivation_letters.count %}Motivation letter (version {{ version }}):{% endblocktrans %}</strong>
<a data-turbolinks="false" href="{% url "member:document" file=team.motivation_letters.last.file %}">{% trans "Download" %}</a>
</div>
{% endif %}
{% if team.solutions.count %}
<div class="alert alert-info">
<ul>
{% for solution in team.solutions.all %}
<li><strong>{{ solution }} :</strong> <a data-turbolinks="false" href="{% url "member:document" file=solution.file %}">{% trans "Download" %}</a></li>
{% endfor %}
</ul>
</div>
{% endif %}
{% endblock %}