diff --git a/participation/models.py b/participation/models.py index 001e050..e388c99 100644 --- a/participation/models.py +++ b/participation/models.py @@ -1,7 +1,6 @@ # Copyright (C) 2020 by Animath # SPDX-License-Identifier: GPL-3.0-or-later -import asyncio from datetime import date import os @@ -16,7 +15,6 @@ from django.utils.crypto import get_random_string from django.utils.text import format_lazy from django.utils.translation import gettext_lazy as _ import gspread -from django.views.debug import ExceptionReporter from gspread.utils import a1_range_to_grid_range, MergeType from registration.models import Payment, VolunteerRegistration from tfjm.lists import get_sympa_client @@ -434,7 +432,7 @@ class Tournament(models.Model): gc = gspread.service_account_from_dict(settings.GOOGLE_SERVICE_CLIENT) spreadsheet = gc.open_by_key(self.notes_sheet_id) worksheets = spreadsheet.worksheets() - if f"Classement final" not in [ws.title for ws in worksheets]: + if "Classement final" not in [ws.title for ws in worksheets]: worksheet = spreadsheet.add_worksheet("Classement final", 100, 26) else: worksheet = spreadsheet.worksheet("Classement final") @@ -477,7 +475,6 @@ class Tournament(models.Model): data = header + lines + final_ranking worksheet.update(data, f"A1:G{participations.count() + 5}", raw=False) - format_requests = [] # Set the width of the columns @@ -536,7 +533,7 @@ class Tournament(models.Model): # Set background color for headers and footers bg_colors = [("A1:AF", (1, 1, 1)), - (f"A1:G1", (0.8, 0.8, 0.8)), + ("A1:G1", (0.8, 0.8, 0.8)), (f"A2:B{participations.count() + 1}", (0.9, 0.9, 0.9)), (f"C2:C{participations.count() + 1}", (1, 1, 1)), (f"D2:D{participations.count() + 1}", (0.9, 0.9, 0.9)), @@ -581,7 +578,7 @@ class Tournament(models.Model): }) # Protect the header, the juries list, the footer and the ranking - protected_ranges = [f"A1:G1", f"A2:B{participations.count() + 1}", + protected_ranges = ["A1:G1", f"A2:B{participations.count() + 1}", f"D2:D{participations.count() + 1}", f"F2:G{participations.count() + 1}", f"A{participations.count() + 4}:C{2 * participations.count() + 4}", ] for protected_range in protected_ranges: @@ -1214,7 +1211,8 @@ class Pool(models.Model): note.save() def save(self, force_insert=False, force_update=False, using=None, update_fields=None): - self.update_juries_lines_spreadsheet() + if os.getenv('GOOGLE_PRIVATE_KEY_ID', None): # Google Sheets support is enabled + self.update_juries_lines_spreadsheet() super().save(force_insert, force_update, using, update_fields) def __str__(self): diff --git a/participation/urls.py b/participation/urls.py index d58167a..2634262 100644 --- a/participation/urls.py +++ b/participation/urls.py @@ -11,7 +11,7 @@ from .views import CreateTeamView, FinalNotationSheetTemplateView, JoinTeamView, ScaleNotationSheetTemplateView, SolutionsDownloadView, SolutionUploadView, SynthesisUploadView, \ TeamAuthorizationsView, TeamDetailView, TeamLeaveView, TeamListView, TeamUpdateView, \ TeamUploadMotivationLetterView, TournamentCreateView, TournamentDetailView, TournamentExportCSVView, \ - TournamentHarmonizeView, TournamentHarmonizeNoteView, TournamentListView, TournamentPaymentsView, \ + TournamentHarmonizeNoteView, TournamentHarmonizeView, TournamentListView, TournamentPaymentsView, \ TournamentPublishNotesView, TournamentUpdateView diff --git a/participation/views.py b/participation/views.py index b6fb4e4..8491d36 100644 --- a/participation/views.py +++ b/participation/views.py @@ -9,7 +9,6 @@ from tempfile import mkdtemp from typing import Any, Dict from zipfile import ZipFile -import gspread from django.conf import settings from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin @@ -29,6 +28,7 @@ from django.views.generic import CreateView, DetailView, FormView, RedirectView, from django.views.generic.detail import SingleObjectMixin from django.views.generic.edit import FormMixin, ProcessFormView from django_tables2 import MultiTableMixin, SingleTableMixin, SingleTableView +import gspread from magic import Magic from odf.opendocument import OpenDocumentSpreadsheet from odf.style import Style, TableCellProperties, TableColumnProperties, TextProperties