diff --git a/participation/management/commands/update_notation_sheets.py b/participation/management/commands/update_notation_sheets.py index d265654..b3ec992 100644 --- a/participation/management/commands/update_notation_sheets.py +++ b/participation/management/commands/update_notation_sheets.py @@ -6,12 +6,32 @@ from participation.models import Tournament class Command(BaseCommand): + def add_arguments(self, parser): + parser.add_argument( + '--tournament', '-t', help="Tournament name to update (if not set, all tournaments will be updated)", + ) + parser.add_argument( + '--round', '-r', type=int, help="Round number to update (if not set, all rounds will be updated)", + ) + parser.add_argument( + '--letter', '-l', help="Letter of the pool to update (if not set, all pools will be updated)", + ) + def handle(self, *args, **options): - for tournament in Tournament.objects.all(): + tournaments = Tournament.objects.all() if not options['tournament'] \ + else Tournament.objects.filter(name=options['tournament']).all() + + for tournament in tournaments: if options['verbosity'] >= 1: self.stdout.write(f"Updating notation sheet for {tournament}") tournament.create_spreadsheet() - for pool in tournament.pools.all(): + + pools = tournament.pools.all() + if options['round']: + pools = pools.filter(round=options['round']) + if options['letter']: + pools = pools.filter(letter=ord(options['letter']) - 64) + for pool in pools.all(): if options['verbosity'] >= 1: self.stdout.write(f"Updating notation sheet for pool {pool.short_name} for {tournament}") pool.update_spreadsheet() diff --git a/participation/models.py b/participation/models.py index 1edf492..bc919c0 100644 --- a/participation/models.py +++ b/participation/models.py @@ -616,6 +616,9 @@ class Pool(models.Model): return super().validate_constraints() def update_spreadsheet(self): # noqa: C901 + # Create tournament sheet if it does not exist + self.tournament.create_spreadsheet() + gc = gspread.service_account_from_dict(settings.GOOGLE_SERVICE_CLIENT) spreadsheet = gc.open_by_key(self.tournament.notes_sheet_id) worksheets = spreadsheet.worksheets()