1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-06-21 21:58:25 +02:00

Profile list

This commit is contained in:
Yohann D'ANELLO
2020-04-30 21:07:12 +02:00
parent f70f6f16f0
commit 03f47f996b
8 changed files with 124 additions and 52 deletions

View File

@ -74,6 +74,32 @@ class TournamentDetailView(DetailView):
class TeamDetailView(LoginRequiredMixin, DetailView):
model = Team
def dispatch(self, request, *args, **kwargs):
if not request.user.admin and self.request.user not in self.get_object().tournament.organizers:
raise PermissionDenied
return super().dispatch(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
team = self.get_object()
if "zip" in request.POST:
solutions = team.solutions.all()
out = BytesIO()
zf = zipfile.ZipFile(out, "w")
for solution in solutions:
zf.write(solution.file.path, str(solution) + ".pdf")
zf.close()
resp = HttpResponse(out.getvalue(), content_type="application/x-zip-compressed")
resp['Content-Disposition'] = 'attachment; filename={}'\
.format(_("Solutions for team {team}.zip")
.format(team=str(team)).replace(" ", "%20"))
return resp
return self.get(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)