Skip to content
Snippets Groups Projects
Commit 30f9677f authored by Jiří Setnička's avatar Jiří Setnička
Browse files

DB: Pomocné metody pro skupiny kol/soutěží

Round code teď obsahuje v případě part > 0 i přilepené písmenko.
parent 22e47e75
Branches
No related tags found
1 merge request!48Dělená kola napotřetí
......@@ -210,12 +210,32 @@ class Round(Base):
master = relationship('Round', primaryjoin='Round.master_round_id == Round.round_id', remote_side='Round.round_id', post_update=True)
def round_code(self):
def round_code_short(self):
""" Pro samostatné kolo ekvivalentní s `round_code()`, pro skupinu kol společná část kódu. """
return f"{self.year}-{self.category}-{self.seq}"
def part_code(self):
return chr(ord('a') + self.part - 1) if self.part > 0 else ""
def round_code(self):
""" Kód kola včetně označení části, pokud je ve skupině kol. """
code = self.round_code_short()
part = self.part_code()
return f"{code}{part}"
def has_tasks(self):
return self.tasks_file
def is_subround(self) -> bool:
return self.master_round_id != self.round_id
def get_group_rounds(self, add_self=False) -> List['Round']:
# podle PEP484 se má použít string při forward typové referenci
return get_session().query(Round).filter(
Round.master_round_id == self.master_round_id,
add_self or Round.round_id != self.round_id,
).all()
def long_state(self) -> str:
details = ""
if self.state == RoundState.preparing:
......@@ -287,6 +307,15 @@ class Contest(Base):
place = relationship('Place')
round = relationship('Round')
def is_subcontest(self) -> bool:
return self.master_contest_id != self.contest_id
def get_group_contests(self, add_self=False) -> List['Contest']:
# podle PEP484 se má použít string při forward typové referenci
return get_session().query(Contest).filter(
Contest.master_contest_id == self.master_contest_id,
add_self or Contest.contest_id != self.contest_id,
).options(joinedload(Contest.round)).all()
class LogType(MOEnum):
general = auto()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment