Teams may not beeing in a pool of the second round (for example, for the final tournament)

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello 2024-03-31 13:42:34 +02:00
parent 8d7d7cd645
commit 630633bab4
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 26 additions and 15 deletions

View File

@ -453,15 +453,23 @@ class Tournament(models.Model):
tweak1_qs = Tweak.objects.filter(pool=pool1, participation=participation) tweak1_qs = Tweak.objects.filter(pool=pool1, participation=participation)
tweak1 = tweak1_qs.get() if tweak1_qs.exists() else None tweak1 = tweak1_qs.get() if tweak1_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)
if self.pools.filter(round=2, participations=participation).exists():
pool2 = self.pools.get(round=2, participations=participation) pool2 = self.pools.get(round=2, participations=participation)
passage2 = pool2.passages.get(defender=participation) passage2 = pool2.passages.get(defender=participation)
tweak2_qs = Tweak.objects.filter(pool=pool2, participation=participation) tweak2_qs = Tweak.objects.filter(pool=pool2, participation=participation)
tweak2 = tweak2_qs.get() if tweak2_qs.exists() else None 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(
line.append(tweak1.diff if tweak1 else 0) f"=SIERREUR('Poule {pool2.short_name}'!$D{pool2.juries.count() + 10 + passage2.position}; 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) 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"=$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})") line.append(f"=RANG($F{i + 2}; $F$2:$F${participations.count() + 1})")
@ -609,16 +617,19 @@ class Tournament(models.Model):
trigram = line[0][-4:-1] trigram = line[0][-4:-1]
participation = self.participations.get(team__trigram=trigram) participation = self.participations.get(team__trigram=trigram)
pool1 = self.pools.get(round=1, participations=participation) 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) tweak1_qs = Tweak.objects.filter(pool=pool1, participation=participation)
tweak2_qs = Tweak.objects.filter(pool=pool2, participation=participation) tweak1_nb = int(line[2])
tweak1_nb, tweak2_nb = int(line[2]), int(line[4])
if not tweak1_nb: if not tweak1_nb:
tweak1_qs.delete() tweak1_qs.delete()
else: else:
tweak1_qs.update_or_create(defaults={'diff': tweak1_nb}, tweak1_qs.update_or_create(defaults={'diff': tweak1_nb},
create_defaults={'diff': tweak1_nb, 'pool': pool1, create_defaults={'diff': tweak1_nb, 'pool': pool1,
'participation': participation}) 'participation': participation})
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: if not tweak2_nb:
tweak2_qs.delete() tweak2_qs.delete()
else: else: