Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion bullet/documents/generators/tearoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,16 @@ def _place_stamp(
start_y = (-210 + self.stamp_width + 2) * mm
max_width = (self.statement_height - 10) * mm
max_height = (self.stamp_width - 2 - 5) * mm
school_length = max_width

if max_width > 75 * mm:
start_x += (max_width - 75 * mm) / 2
max_width = 75 * mm
school_length = max_width

if not include_qr:
start_x += max_height / 2
school_length -= max_height

canvas.setFillGray(0)
code = code128.Code128(
Expand Down Expand Up @@ -243,7 +246,10 @@ def _place_stamp(
text = canvas.beginText()
text.setTextOrigin(start_x, start_y - max_height - 8)
text.setFont("IBMPlexMono-Regular", 6)
text.textOut(tearoff.team.display_name_short)
school_chars = (
int(school_length / mm * 0.77) - 1
) # 0.77 is how many characters fit in a mm of space
text.textOut(tearoff.team.get_shortened_display_name(school_chars))
canvas.drawText(text)

canvas.restoreState()
Expand Down
9 changes: 6 additions & 3 deletions bullet/users/models/contestants.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,14 @@ def display_name(self):

@property
def display_name_short(self):
return self.get_shortened_display_name()

def get_shortened_display_name(self, chars=55):
if self.name:
return shorten(self.name, 55)
return shorten(self.name, chars)
if self.in_school_symbol:
return f"{shorten(str(self.school), 55)} {self.in_school_symbol}"
return shorten(str(self.school), 55)
return f"{shorten(str(self.school), chars)} {self.in_school_symbol}"
return shorten(str(self.school), chars)

@property
def contact_phone_pretty(self):
Expand Down