Skip to content
Snippets Groups Projects
Commit 0e57dd47 authored by Jan Prachař's avatar Jan Prachař
Browse files

mo/score: Řazení podle roku narození

parent 9fc39f49
No related branches found
No related tags found
No related merge requests found
import decimal
from flask import url_for
from fractions import Fraction
from sqlalchemy import and_
from sqlalchemy.orm import joinedload
......@@ -490,6 +491,7 @@ class Score:
result._order_key.append(-modif_points)
# Na konec třídícího klíče přidáme ročník (menší ročník první)
# a dotřiďovací klíč
for result in self._results.values():
grade = normalize_grade(result.pant.grade)
if grade == -1:
......@@ -500,5 +502,27 @@ class Score:
result._order_key.append(grade)
result._order_key.append(result.pion.score_suborder or 0)
# Pokud stále existují sdílená místa, pokusíme se použít rok narození
same_order = set()
last = None
for result in sorted(self._results.values(), key=lambda result: result._order_key):
if last and result._order_key == last._order_key:
same_order.add(last)
same_order.add(result)
last = result
if len(same_order) > 0:
if all(result.pant.birth_year for result in same_order):
links = [f"{result.user.first_name} {result.user.last_name} ({result.pant.birth_year})" for result in same_order]
self._add_message("info", f"K řazení některých soutěžících byl použit rok narození: {', '.join(links)}.")
for result in self._results.values():
result._order_key.append(-result.pant.birth_year if result.pant.birth_year else 0)
else:
links = [f"<a href='{url_for('org_user_participant_edit', user_id=result.user.user_id, year=result.pant.year)}'>{result.user.first_name} {result.user.last_name}</a>" for result in same_order if not result.pant.birth_year]
self._add_message(
"error",
"Doplňte prosím těmto soutežícím rok narození, aby mohl být použit pro řazení na sdílených místech: "+(", ".join(links))+"."
)
if self._exists_same_order_key():
self.shared_places = "O pořadí na sdílených místech rozhoduje datum narození, případně je třeba ho určit losem."
......@@ -66,8 +66,8 @@ Výsledky {{ round.name|round_genitive|lower }}{% if public %} {{ round.year }}.
{% endif %}
</p>
{% for (type, msg) in messages %}
{% if type == "error" %}<p class="text-danger"><b>{{ msg }}</b></p>
{% elif type == "warning" %}<p class="text-warning">{{ msg }}</p>
{% if type == "error" %}<p class="text-danger"><b>{{ msg | safe }}</b></p>
{% elif type == "warning" %}<p class="text-warning">{{ msg | safe }}</p>
{% else %}<p>{{ msg | safe }}{% endif %}</p>
{% endfor %}
{% endif %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment