1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-06-24 12:28:49 +02:00

Add archive with all notation sheets

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello
2024-03-29 18:59:37 +01:00
parent a44439671e
commit 6b16ed3cc8
7 changed files with 222 additions and 99 deletions

View File

@ -650,7 +650,7 @@ class TournamentExportCSVView(VolunteerMixin, DetailView):
if 'all' not in request.GET:
participations = participations.filter(valid=True)
for participation in participations.order_by('-valid', 'team__trigram').all():
for registration in participation.team.participants\
for registration in participation.team.participants \
.order_by('coachregistration', 'user__last_name').all():
writer.writerow({
'Tournoi': tournament.name,
@ -939,8 +939,8 @@ class PoolJuryView(VolunteerMixin, FormView, DetailView):
if request.user.is_authenticated and \
(request.user.registration.is_admin or request.user.registration.is_volunteer
and (self.object.tournament in request.user.registration.organized_tournaments.all()
or request.user.registration == self.object.jury_president)):
and (self.object.tournament in request.user.registration.organized_tournaments.all()
or request.user.registration == self.object.jury_president)):
return super().dispatch(request, *args, **kwargs)
return self.handle_no_permission()
@ -1022,8 +1022,8 @@ class PoolRemoveJuryView(VolunteerMixin, DetailView):
if request.user.is_authenticated and \
(request.user.registration.is_admin or request.user.registration.is_volunteer
and (self.object.tournament in request.user.registration.organized_tournaments.all()
or request.user.registration == self.object.jury_president)):
and (self.object.tournament in request.user.registration.organized_tournaments.all()
or request.user.registration == self.object.jury_president)):
return super().dispatch(request, *args, **kwargs)
return self.handle_no_permission()
@ -1048,8 +1048,8 @@ class PoolPresideJuryView(VolunteerMixin, DetailView):
if request.user.is_authenticated and \
(request.user.registration.is_admin or request.user.registration.is_volunteer
and (self.object.tournament in request.user.registration.organized_tournaments.all()
or request.user.registration == self.object.jury_president)):
and (self.object.tournament in request.user.registration.organized_tournaments.all()
or request.user.registration == self.object.jury_president)):
return super().dispatch(request, *args, **kwargs)
return self.handle_no_permission()
@ -1076,8 +1076,8 @@ class PoolUploadNotesView(VolunteerMixin, FormView, DetailView):
if request.user.is_authenticated and \
(request.user.registration.is_admin or request.user.registration.is_volunteer
and (self.object.tournament in request.user.registration.organized_tournaments.all()
or request.user.registration == self.object.jury_president)):
and (self.object.tournament in request.user.registration.organized_tournaments.all()
or request.user.registration == self.object.jury_president)):
return super().dispatch(request, *args, **kwargs)
return self.handle_no_permission()
@ -1121,8 +1121,8 @@ class PoolNotesTemplateView(VolunteerMixin, DetailView):
if request.user.is_authenticated and \
(request.user.registration.is_admin or request.user.registration.is_volunteer
and (self.object.tournament in request.user.registration.organized_tournaments.all()
or request.user.registration == self.object.jury_president)):
and (self.object.tournament in request.user.registration.organized_tournaments.all()
or request.user.registration == self.object.jury_president)):
return super().dispatch(request, *args, **kwargs)
return self.handle_no_permission()
@ -1313,7 +1313,7 @@ class PoolNotesTemplateView(VolunteerMixin, DetailView):
for i in range(line_length):
table.addElement(TableColumn(stylename=obs_col_style if pool_size == 4
and i % passage_width == passage_width - 1 else col_style))
and i % passage_width == passage_width - 1 else col_style))
# Add line for the problems for different passages
header_pb = TableRow()
@ -1652,6 +1652,17 @@ class NotationSheetTemplateView(VolunteerMixin, DetailView):
"""
model = Pool
def dispatch(self, request, *args, **kwargs):
self.object = self.get_object()
if request.user.is_authenticated and \
(request.user.registration.is_admin or request.user.registration.is_volunteer
and (self.object.tournament in request.user.registration.organized_tournaments.all()
or request.user.registration == self.object.jury_president)):
return super().dispatch(request, *args, **kwargs)
return self.handle_no_permission()
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
@ -1661,13 +1672,13 @@ class NotationSheetTemplateView(VolunteerMixin, DetailView):
if not page.isnumeric() or page not in ['1', '2']:
page = '1'
passages = passages.filter(id__in=[passages[0].id, passages[2].id, passages[4].id]
if page == '1' else [passages[1].id, passages[3].id])
if page == '1' else [passages[1].id, passages[3].id])
context['page'] = page
context['passages'] = passages
context['esp'] = passages.count() * '&'
context['is_jury'] = self.request.user.registration in self.object.juries.all() \
and 'blank' not in self.request.GET
if self.request.user.registration in self.object.juries.all() and 'blank' not in self.request.GET:
context['jury'] = self.request.user.registration
context['tfjm_number'] = timezone.now().year - 2010
return context
@ -1692,6 +1703,95 @@ class FinalNotationSheetTemplateView(NotationSheetTemplateView):
template_name = 'participation/tex/finale.tex'
class NotationSheetsArchiveView(VolunteerMixin, DetailView):
@property
def model(self):
return Pool if 'pool_id' in self.kwargs else Tournament
@property
def pk_url_kwarg(self):
return 'pool_id' if 'pool_id' in self.kwargs else 'tournament_id'
def dispatch(self, request, *args, **kwargs):
if not request.user.is_authenticated:
return self.handle_no_permission()
reg = request.user.registration
if 'pool_id' in kwargs:
pool = self.get_object()
tournament = pool.tournament
if reg.is_admin or reg.is_volunteer \
and (tournament in reg.organized_tournaments.all() or reg in pool.juries.all()):
return super().dispatch(request, *args, **kwargs)
else:
tournament = self.get_object()
if reg.is_admin or reg.is_volunteer and tournament in reg.organized_tournaments.all():
return super().dispatch(request, *args, **kwargs)
return self.handle_no_permission()
def get(self, request, *args, **kwargs):
if 'pool_id' in kwargs:
pool = self.get_object()
tournament = pool.tournament
pools = [pool]
filename = _("Notation sheets of pool {pool} of {tournament}.zip") \
.format(pool=pool.short_name, tournament=tournament.name)
else:
tournament = self.get_object()
pools = tournament.pools.all()
filename = _("Notation sheets of {tournament}.zip").format(tournament=tournament.name)
output = BytesIO()
with ZipFile(output, "w") as zf:
for pool in pools:
prefix = f"{pool.short_name}/" if len(pools) > 1 else ""
for template_name in ['bareme', 'finale']:
pages = [1] if pool.participations.count() < 5 else [1, 2]
for page in pages:
juries = list(pool.juries.all()) + [None]
for jury in juries:
if jury is not None and template_name == "bareme":
continue
context = {'jury': jury, 'page': page, 'pool': pool,
'tfjm_number': timezone.now().year - 2010}
passages = pool.passages.all()
if passages.count() == 5:
passages = passages.filter(id__in=[passages[0].id, passages[2].id, passages[4].id]
if page == '1' else [passages[1].id, passages[3].id])
context['passages'] = passages
context['esp'] = passages.count() * '&'
tex = render_to_string(f"participation/tex/{template_name}.tex",
context=context, request=self.request)
temp_dir = mkdtemp()
with open(os.path.join(temp_dir, "texput.tex"), "w") as f:
f.write(tex)
process = subprocess.Popen(
["pdflatex", "-interaction=nonstopmode", f"-output-directory={temp_dir}",
os.path.join(temp_dir, "texput.tex"), ])
process.wait()
sheet_name = f"Barème pour la poule {pool.short_name}" if template_name == "bareme" \
else (f"Feuille de notation pour la poule {pool.short_name}"
f" - {str(jury) if jury else 'Vierge'}")
sheet_name += " - page 2" if page == 2 else ""
zf.write(os.path.join(temp_dir, "texput.pdf"),
f"{prefix}{sheet_name}.pdf")
response = HttpResponse(content_type="application/zip")
response["Content-Disposition"] = f"attachment; filename=\"{filename}\""
response.write(output.getvalue())
return response
class PassageCreateView(VolunteerMixin, CreateView):
model = Passage
form_class = PassageForm