Skip to content

Commit 0f49467

Browse files
authored
feat: team list PDF generation without personal data (#986)
1 parent 2f6f992 commit 0f49467

File tree

5 files changed

+54
-65
lines changed

5 files changed

+54
-65
lines changed

bullet/bullet_admin/forms/documents.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from competitions.models import Competition, Venue
1+
from competitions.models import Competition
22
from django import forms
33
from django.conf import settings
44
from django.core.exceptions import ValidationError
55
from documents.models import CertificateTemplate, TexTemplate
6-
from users.models import User
76

87

98
class CertificateForm(forms.Form):
@@ -50,14 +49,6 @@ def clean(self):
5049
return self.cleaned_data
5150

5251

53-
class TeamListForm(forms.Form):
54-
venue = forms.ModelChoiceField(queryset=Venue.objects.none())
55-
56-
def __init__(self, competition: Competition, user: User, **kwargs):
57-
super().__init__(**kwargs)
58-
self.fields["venue"].queryset = Venue.objects.for_user(competition, user)
59-
60-
6152
class TearoffForm(forms.Form):
6253
first_problem = forms.IntegerField(
6354
label="First problem",

bullet/bullet_admin/forms/venues.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,14 @@ def clean_shortcode(self):
7676
if not prefix_re.match(data):
7777
raise ValidationError("Barcode prefix must contain only capital letters.")
7878
return data
79+
80+
81+
class TeamListForm(forms.Form):
82+
include_contact = forms.BooleanField(
83+
required=False, label="Include contact information", initial=True
84+
)
85+
include_contestants = forms.BooleanField(
86+
required=False,
87+
label="Include contestants",
88+
initial=True,
89+
)

bullet/bullet_admin/templates/bullet_admin/documents/team_list.html

Lines changed: 0 additions & 29 deletions
This file was deleted.

bullet/bullet_admin/views/venues.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
from bullet_admin.access import AdminAccess, CountryAdminAccess, VenueAccess
2828
from bullet_admin.forms.documents import CertificateForm, TearoffForm
29-
from bullet_admin.forms.venues import VenueForm
29+
from bullet_admin.forms.venues import TeamListForm, VenueForm
3030
from bullet_admin.mixins import AdminRequiredMixin, RedirectBackMixin
3131
from bullet_admin.utils import get_active_competition
3232
from bullet_admin.views import GenericForm, GenericList
@@ -160,13 +160,14 @@ def form_valid(self, form):
160160

161161
class TeamListView(VenueMixin, GenericForm, FormView):
162162
require_unlocked_competition = False
163-
form_class = Form
163+
form_class = TeamListForm
164164

165165
def form_valid(self, form):
166166
venue = self.venue
167167
data = team_list(
168168
Team.objects.competing().filter(venue=venue, number__isnull=False),
169169
f"Team list: {venue.name}",
170+
**form.cleaned_data,
170171
)
171172
return FileResponse(data, as_attachment=True, filename="team_list.pdf")
172173

bullet/documents/generators/team_list.py

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
from documents.generators.reportlab_utils import prepare_pdf, render_table
1010

1111

12-
def team_list(teams: QuerySet, title: str) -> io.BytesIO:
12+
def team_list(
13+
teams: QuerySet, title: str, include_contact=True, include_contestants=True
14+
) -> io.BytesIO:
1315
teams = (
1416
teams.order_by("number")
1517
.prefetch_related("contestants")
@@ -46,43 +48,56 @@ def team_list(teams: QuerySet, title: str) -> io.BytesIO:
4648
)
4749

4850
data = []
49-
data.append(
50-
[
51-
Paragraph("Number", style_bold),
52-
Paragraph("School", style_bold),
53-
Paragraph("Contact information", style_bold),
54-
Paragraph("Contestants", style_bold),
55-
]
56-
)
51+
header = [
52+
Paragraph("Number", style_bold),
53+
Paragraph("School", style_bold),
54+
]
55+
if include_contact:
56+
header.append(Paragraph("Contact information", style_bold))
57+
if include_contestants:
58+
header.append(Paragraph("Contestants", style_bold))
59+
data.append(header)
5760

5861
for team in teams:
5962
contact = []
6063
if team.contact_email:
6164
contact.append(team.contact_email)
6265
if team.contact_phone:
6366
contact.append(team.contact_phone_pretty)
64-
data.append(
67+
68+
row: list = [
6569
[
66-
[
67-
Paragraph(
68-
f"{team.venue.shortcode}<b>{team.number:03d}</b>", style_code
69-
),
70-
Paragraph(team.id_display, style_code_small),
71-
],
72-
[
73-
Paragraph(team.school.name, style_base),
74-
Paragraph(team.school.address, style_small),
75-
],
70+
Paragraph(
71+
f"{team.venue.shortcode}<b>{team.number:03d}</b>", style_code
72+
),
73+
Paragraph(team.id_display, style_code_small),
74+
],
75+
[
76+
Paragraph(
77+
f"{team.school.name}<b> {team.in_school_symbol or ''}</b>",
78+
style_base,
79+
),
80+
Paragraph(team.school.address, style_small),
81+
],
82+
]
83+
84+
if include_contact:
85+
row.append(
7686
[
7787
Paragraph(team.contact_name, style_base),
7888
Paragraph("<br/>".join(contact), style_small),
79-
],
89+
]
90+
)
91+
92+
if include_contestants:
93+
row.append(
8094
Paragraph(
8195
"<br/>".join([c.full_name for c in team.contestants.all()]),
8296
style_small,
83-
),
84-
]
85-
)
97+
)
98+
)
99+
100+
data.append(row)
86101

87102
story = []
88103
story.append(Paragraph(title, style_title))

0 commit comments

Comments
 (0)