mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2024-12-25 17:42:24 +00:00
Fix GSheet column width
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
parent
5c3b3d26c8
commit
9721898731
@ -575,7 +575,7 @@ class Tournament(models.Model):
|
|||||||
format_requests = []
|
format_requests = []
|
||||||
|
|
||||||
# Set the width of the columns
|
# Set the width of the columns
|
||||||
column_widths = [("A", 300), ("B", 150), ("C", 150), ("D", 150), ("E", 150), ("F", 150), ("G", 150),
|
column_widths = [("A", 350), ("B", 150), ("C", 150), ("D", 150), ("E", 150), ("F", 150), ("G", 150),
|
||||||
("H", 150), ("I", 150), ("J", 150)]
|
("H", 150), ("I", 150), ("J", 150)]
|
||||||
for column, width in column_widths:
|
for column, width in column_widths:
|
||||||
grid_range = a1_range_to_grid_range(column, worksheet.id)
|
grid_range = a1_range_to_grid_range(column, worksheet.id)
|
||||||
@ -640,7 +640,7 @@ class Tournament(models.Model):
|
|||||||
(f"A{participations.count() + 5}:C{2 * participations.count() + 4}", (0.9, 0.9, 0.9)),]
|
(f"A{participations.count() + 5}:C{2 * participations.count() + 4}", (0.9, 0.9, 0.9)),]
|
||||||
if settings.NB_ROUNDS >= 3:
|
if settings.NB_ROUNDS >= 3:
|
||||||
bg_colors.append((f"F2:G{participations.count() + 1}", (0.9, 0.9, 0.9)))
|
bg_colors.append((f"F2:G{participations.count() + 1}", (0.9, 0.9, 0.9)))
|
||||||
bg_colors.append((f"H2:I{participations.count() + 1}", (0.9, 0.9, 0.9)))
|
bg_colors.append((f"I2:J{participations.count() + 1}", (0.9, 0.9, 0.9)))
|
||||||
else:
|
else:
|
||||||
bg_colors.append((f"F2:G{participations.count() + 1}", (0.9, 0.9, 0.9)))
|
bg_colors.append((f"F2:G{participations.count() + 1}", (0.9, 0.9, 0.9)))
|
||||||
for bg_range, bg_color in bg_colors:
|
for bg_range, bg_color in bg_colors:
|
||||||
@ -1214,6 +1214,11 @@ class Pool(models.Model):
|
|||||||
def update_spreadsheet(self): # noqa: C901
|
def update_spreadsheet(self): # noqa: C901
|
||||||
translation.activate(settings.PREFERRED_LANGUAGE_CODE)
|
translation.activate(settings.PREFERRED_LANGUAGE_CODE)
|
||||||
|
|
||||||
|
pool_size = self.participations.count()
|
||||||
|
has_observer = settings.TFJM_APP == "ETEAM" and pool_size >= 4
|
||||||
|
passage_width = 6 + (2 if has_observer else 0)
|
||||||
|
passages = self.passages.all()
|
||||||
|
|
||||||
# Create tournament sheet if it does not exist
|
# Create tournament sheet if it does not exist
|
||||||
self.tournament.create_spreadsheet()
|
self.tournament.create_spreadsheet()
|
||||||
|
|
||||||
@ -1221,17 +1226,13 @@ class Pool(models.Model):
|
|||||||
spreadsheet = gc.open_by_key(self.tournament.notes_sheet_id)
|
spreadsheet = gc.open_by_key(self.tournament.notes_sheet_id)
|
||||||
worksheets = spreadsheet.worksheets()
|
worksheets = spreadsheet.worksheets()
|
||||||
if f"{_('Pool')} {self.short_name}" not in [ws.title for ws in worksheets]:
|
if f"{_('Pool')} {self.short_name}" not in [ws.title for ws in worksheets]:
|
||||||
worksheet = spreadsheet.add_worksheet(f"{_('Pool')} {self.short_name}", 100, 34)
|
worksheet = spreadsheet.add_worksheet(f"{_('Pool')} {self.short_name}",
|
||||||
|
30, 2 + pool_size * passage_width)
|
||||||
else:
|
else:
|
||||||
worksheet = spreadsheet.worksheet(f"{_('Pool')} {self.short_name}")
|
worksheet = spreadsheet.worksheet(f"{_('Pool')} {self.short_name}")
|
||||||
if any(ws.title == "Sheet1" for ws in worksheets):
|
if any(ws.title == "Sheet1" for ws in worksheets):
|
||||||
spreadsheet.del_worksheet(spreadsheet.worksheet("Sheet1"))
|
spreadsheet.del_worksheet(spreadsheet.worksheet("Sheet1"))
|
||||||
|
|
||||||
pool_size = self.participations.count()
|
|
||||||
has_observer = settings.TFJM_APP == "ETEAM" and pool_size >= 4
|
|
||||||
passage_width = 6 + (2 if has_observer else 0)
|
|
||||||
passages = self.passages.all()
|
|
||||||
|
|
||||||
header = [
|
header = [
|
||||||
sum(([str(_("Problem #{problem}").format(problem=passage.solution_number))] + (passage_width - 1) * [""]
|
sum(([str(_("Problem #{problem}").format(problem=passage.solution_number))] + (passage_width - 1) * [""]
|
||||||
for passage in passages), start=[str(_("Problem")), ""]),
|
for passage in passages), start=[str(_("Problem")), ""]),
|
||||||
@ -1275,7 +1276,7 @@ class Pool(models.Model):
|
|||||||
for passage in passages),
|
for passage in passages),
|
||||||
start=[str(_("Coefficient")), ""])
|
start=[str(_("Coefficient")), ""])
|
||||||
subtotal = [str(_("Subtotal")), ""]
|
subtotal = [str(_("Subtotal")), ""]
|
||||||
footer = [average, coeffs, subtotal, 34 * [""]]
|
footer = [average, coeffs, subtotal, (2 + pool_size * passage_width) * [""]]
|
||||||
|
|
||||||
min_row = 5
|
min_row = 5
|
||||||
max_row = min_row + self.juries.count()
|
max_row = min_row + self.juries.count()
|
||||||
@ -1354,8 +1355,9 @@ class Pool(models.Model):
|
|||||||
|
|
||||||
all_values = header + notes + footer + ranking
|
all_values = header + notes + footer + ranking
|
||||||
|
|
||||||
worksheet.batch_clear([f"A1:AH{max_row + 5 + pool_size}"])
|
max_col = getcol(2 + pool_size * passage_width)
|
||||||
worksheet.update(all_values, "A1:AH", raw=False)
|
worksheet.batch_clear([f"A1:{max_col}{max_row + 5 + pool_size}"])
|
||||||
|
worksheet.update(all_values, f"A1:{max_col}", raw=False)
|
||||||
|
|
||||||
format_requests = []
|
format_requests = []
|
||||||
|
|
||||||
@ -1386,13 +1388,13 @@ class Pool(models.Model):
|
|||||||
for i in range(pool_size + 1):
|
for i in range(pool_size + 1):
|
||||||
merge_cells.append(f"A{max_row + 5 + i}:B{max_row + 5 + i}")
|
merge_cells.append(f"A{max_row + 5 + i}:B{max_row + 5 + i}")
|
||||||
|
|
||||||
format_requests.append({"unmergeCells": {"range": a1_range_to_grid_range("A1:AH", worksheet.id)}})
|
format_requests.append({"unmergeCells": {"range": a1_range_to_grid_range(f"A1:{max_col}", worksheet.id)}})
|
||||||
for name in merge_cells:
|
for name in merge_cells:
|
||||||
grid_range = a1_range_to_grid_range(name, worksheet.id)
|
grid_range = a1_range_to_grid_range(name, worksheet.id)
|
||||||
format_requests.append({"mergeCells": {"mergeType": MergeType.merge_all, "range": grid_range}})
|
format_requests.append({"mergeCells": {"mergeType": MergeType.merge_all, "range": grid_range}})
|
||||||
|
|
||||||
# Make titles bold
|
# Make titles bold
|
||||||
bold_ranges = [("A1:AH", False), ("A1:AH3", True),
|
bold_ranges = [(f"A1:{max_col}", False), (f"A1:{max_col}3", True),
|
||||||
(f"A{max_row + 1}:B{max_row + 3}", True), (f"A{max_row + 5}:E{max_row + 5}", True)]
|
(f"A{max_row + 1}:B{max_row + 3}", True), (f"A{max_row + 5}:E{max_row + 5}", True)]
|
||||||
for bold_range, bold in bold_ranges:
|
for bold_range, bold in bold_ranges:
|
||||||
format_requests.append({
|
format_requests.append({
|
||||||
@ -1404,7 +1406,7 @@ class Pool(models.Model):
|
|||||||
})
|
})
|
||||||
|
|
||||||
# Set background color for headers and footers
|
# Set background color for headers and footers
|
||||||
bg_colors = [("A1:AH", (1, 1, 1)),
|
bg_colors = [(f"A1:{max_col}", (1, 1, 1)),
|
||||||
(f"A1:{getcol(2 + passages.count() * passage_width)}3", (0.8, 0.8, 0.8)),
|
(f"A1:{getcol(2 + passages.count() * passage_width)}3", (0.8, 0.8, 0.8)),
|
||||||
(f"A{min_row - 1}:B{max_row}", (0.95, 0.95, 0.95)),
|
(f"A{min_row - 1}:B{max_row}", (0.95, 0.95, 0.95)),
|
||||||
(f"A{max_row + 1}:B{max_row + 3}", (0.8, 0.8, 0.8)),
|
(f"A{max_row + 1}:B{max_row + 3}", (0.8, 0.8, 0.8)),
|
||||||
@ -1439,10 +1441,10 @@ class Pool(models.Model):
|
|||||||
})
|
})
|
||||||
|
|
||||||
# Set the width of the columns
|
# Set the width of the columns
|
||||||
column_widths = [("A", 300), ("B", 30)]
|
column_widths = [("A", 350), ("B", 30)]
|
||||||
for passage in passages:
|
for passage in passages:
|
||||||
column_widths.append((f"{getcol(3 + passage_width * (passage.position - 1))}"
|
column_widths.append((f"{getcol(3 + passage_width * (passage.position - 1))}"
|
||||||
f":{getcol(8 + passage_width * (passage.position - 1))}", 75))
|
f":{getcol(2 + passage_width * passage.position)}", 80))
|
||||||
for column, width in column_widths:
|
for column, width in column_widths:
|
||||||
grid_range = a1_range_to_grid_range(column, worksheet.id)
|
grid_range = a1_range_to_grid_range(column, worksheet.id)
|
||||||
format_requests.append({
|
format_requests.append({
|
||||||
@ -1493,7 +1495,7 @@ class Pool(models.Model):
|
|||||||
})
|
})
|
||||||
|
|
||||||
# Define borders
|
# Define borders
|
||||||
border_ranges = [("A1:AH", "0000"),
|
border_ranges = [(f"A1:{max_col}", "0000"),
|
||||||
(f"A1:{getcol(2 + passages.count() * passage_width)}{max_row + 3}", "1111"),
|
(f"A1:{getcol(2 + passages.count() * passage_width)}{max_row + 3}", "1111"),
|
||||||
(f"A{max_row + 5}:E{max_row + pool_size + 5}", "1111"),
|
(f"A{max_row + 5}:E{max_row + pool_size + 5}", "1111"),
|
||||||
(f"A1:B{max_row + 3}", "1113"),
|
(f"A1:B{max_row + 3}", "1113"),
|
||||||
@ -1568,9 +1570,9 @@ class Pool(models.Model):
|
|||||||
})
|
})
|
||||||
|
|
||||||
# Protect the header, the juries list, the footer and the ranking
|
# Protect the header, the juries list, the footer and the ranking
|
||||||
protected_ranges = ["A1:AH4",
|
protected_ranges = [f"A1:{max_col}4",
|
||||||
f"A{min_row}:B{max_row}",
|
f"A{min_row}:B{max_row}",
|
||||||
f"A{max_row}:AH{max_row + 5 + pool_size}"]
|
f"A{max_row}:{max_col}{max_row + 5 + pool_size}"]
|
||||||
for protected_range in protected_ranges:
|
for protected_range in protected_ranges:
|
||||||
format_requests.append({
|
format_requests.append({
|
||||||
"addProtectedRange": {
|
"addProtectedRange": {
|
||||||
|
Loading…
Reference in New Issue
Block a user