diff --git a/participation/models.py b/participation/models.py index 1d35f29..86c30e0 100644 --- a/participation/models.py +++ b/participation/models.py @@ -453,15 +453,23 @@ class Tournament(models.Model): tweak1_qs = Tweak.objects.filter(pool=pool1, participation=participation) tweak1 = tweak1_qs.get() if tweak1_qs.exists() else None - pool2 = self.pools.get(round=2, participations=participation) - passage2 = pool2.passages.get(defender=participation) - tweak2_qs = Tweak.objects.filter(pool=pool2, participation=participation) - tweak2 = tweak2_qs.get() if tweak2_qs.exists() else None - line.append(f"=SIERREUR('Poule {pool1.short_name}'!$D{pool1.juries.count() + 10 + passage1.position}; 0)") line.append(tweak1.diff if tweak1 else 0) - line.append(f"=SIERREUR('Poule {pool2.short_name}'!$D{pool2.juries.count() + 10 + passage2.position}; 0)") - line.append(tweak2.diff if tweak2 else 0) + + if self.pools.filter(round=2, participations=participation).exists(): + pool2 = self.pools.get(round=2, participations=participation) + passage2 = pool2.passages.get(defender=participation) + tweak2_qs = Tweak.objects.filter(pool=pool2, participation=participation) + tweak2 = tweak2_qs.get() if tweak2_qs.exists() else None + + line.append( + f"=SIERREUR('Poule {pool2.short_name}'!$D{pool2.juries.count() + 10 + passage2.position}; 0)") + line.append(tweak2.diff if tweak2 else 0) + else: + # User has no second pool yet + line.append(0) + line.append(0) + line.append(f"=$B{i + 2} + $C{i + 2} + $D{i + 2} + E{i + 2}") line.append(f"=RANG($F{i + 2}; $F$2:$F${participations.count() + 1})") @@ -609,21 +617,24 @@ class Tournament(models.Model): trigram = line[0][-4:-1] participation = self.participations.get(team__trigram=trigram) pool1 = self.pools.get(round=1, participations=participation) - pool2 = self.pools.get(round=2, participations=participation) tweak1_qs = Tweak.objects.filter(pool=pool1, participation=participation) - tweak2_qs = Tweak.objects.filter(pool=pool2, participation=participation) - tweak1_nb, tweak2_nb = int(line[2]), int(line[4]) + tweak1_nb = int(line[2]) if not tweak1_nb: tweak1_qs.delete() else: tweak1_qs.update_or_create(defaults={'diff': tweak1_nb}, create_defaults={'diff': tweak1_nb, 'pool': pool1, 'participation': participation}) - if not tweak2_nb: - tweak2_qs.delete() - else: - tweak2_qs.update_or_create(defaults={'diff': tweak2_nb}, - create_defaults={'diff': tweak2_nb, 'pool': pool2, + + if self.pools.filter(round=2, participations=participation).exists(): + pool2 = self.pools.get(round=2, participations=participation) + tweak2_qs = Tweak.objects.filter(pool=pool2, participation=participation) + tweak2_nb = int(line[4]) + if not tweak2_nb: + tweak2_qs.delete() + else: + tweak2_qs.update_or_create(defaults={'diff': tweak2_nb}, + create_defaults={'diff': tweak2_nb, 'pool': pool2, 'participation': participation}) def get_absolute_url(self):