From 2019c5c434a250928e6c6d1ad7483a0adfd33e9d Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Sat, 30 Mar 2024 17:07:53 +0100 Subject: [PATCH] Validate note bounds and that they are integers Signed-off-by: Emmy D'Anello --- participation/models.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/participation/models.py b/participation/models.py index c31e7c7..a26df3b 100644 --- a/participation/models.py +++ b/participation/models.py @@ -902,6 +902,28 @@ class Pool(models.Model): } }) + # Add range conditions + for i in range(pool_size): + for j in range(passage_width): + column = getcol(min_column + i * passage_width + j) + min_note = 0 if j < 6 else -4 + max_note = 20 if j < 2 else 10 if j < 6 else 4 + format_requests.append({ + "setDataValidation": { + "range": a1_range_to_grid_range(f"{column}{min_row - 1}:{column}{max_row}", worksheet.id), + "rule": { + "condition": { + "type": "CUSTOM_FORMULA", + "values": [{"userEnteredValue": f'=ET(REGEXMATCH(TO_TEXT({column}4); "^-?[0-9]+$"); ' + f'{column}4>={min_note}; {column}4<={max_note})'},], + }, + "inputMessage": f"La saisie doit ĂȘtre un entier valide " + f"compris entre {min_note} et {max_note}.", + "strict": True, + }, + } + }) + # Remove old protected ranges for protected_range in spreadsheet.list_protected_ranges(worksheet.id): format_requests.append({