Skip to content
Snippets Groups Projects

Implementace dělených kol pomocí RoundPart

Closed Jiří Setnička requested to merge jirka/delena-kola2 into devel
1 unresolved thread
1 file
+ 29
5
Compare changes
  • Side-by-side
  • Inline
+ 29
5
@@ -15,7 +15,7 @@ from sqlalchemy.orm.attributes import get_history
@@ -15,7 +15,7 @@ from sqlalchemy.orm.attributes import get_history
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.sql.expression import CTE
from sqlalchemy.sql.expression import CTE
from typing import Optional, List, Tuple
from typing import Optional, List, Tuple, Union
import mo
import mo
from mo.util_format import timedelta, time_and_timedelta
from mo.util_format import timedelta, time_and_timedelta
@@ -205,6 +205,30 @@ class Round(Base):
@@ -205,6 +205,30 @@ class Round(Base):
def round_code(self):
def round_code(self):
return f"{self.year}-{self.category}-{self.seq}"
return f"{self.year}-{self.category}-{self.seq}"
 
def single(self) -> bool:
 
return len(self.parts) == 1
 
 
def multipart(self) -> bool:
 
return len(self.parts) > 1
 
 
def state_all(self, states: Union[RoundState, List[RoundState]]) -> bool:
 
"""Test jestli jsou všechny části kola v daném stavu. Lze zadat i množinu stavů."""
 
if not isinstance(states, list):
 
states = [states]
 
for part in self.parts:
 
if part.state not in states:
 
return False
 
return True
 
 
def state_any(self, states: Union[RoundState, List[RoundState]]) -> bool:
 
"""Test jestli existuje alespoň jedna část kola v daném stavu. Lze zadat i množinu stavů."""
 
if not isinstance(states, list):
 
states = [states]
 
for part in self.parts:
 
if part.state in states:
 
return True
 
return False
 
class RoundPart(Base):
class RoundPart(Base):
__tablename__ = 'round_parts'
__tablename__ = 'round_parts'
@@ -460,13 +484,13 @@ class Paper(Base):
@@ -460,13 +484,13 @@ class Paper(Base):
for_user_obj = relationship('User', primaryjoin='Paper.for_user == User.user_id')
for_user_obj = relationship('User', primaryjoin='Paper.for_user == User.user_id')
uploaded_by_obj = relationship('User', primaryjoin='Paper.uploaded_by == User.user_id')
uploaded_by_obj = relationship('User', primaryjoin='Paper.uploaded_by == User.user_id')
def check_deadline(self, round: Round) -> Optional[str]:
def check_deadline(self, round_part: RoundPart) -> Optional[str]:
# K round se dá dostat přes self.task.round, ale nejspíš to není nakešované.
# K round_part se dá dostat přes self.task.round, ale nejspíš to není nakešované.
if self.uploaded_by == self.for_user:
if self.uploaded_by == self.for_user:
deadline = round.ct_submit_end
deadline = round_part.ct_submit_end
suffix = ' účastnickém termínu'
suffix = ' účastnickém termínu'
else:
else:
deadline = round.pr_submit_end
deadline = round_part.pr_submit_end
suffix = ' dozorovém termínu'
suffix = ' dozorovém termínu'
if deadline is not None and self.uploaded_at > deadline:
if deadline is not None and self.uploaded_at > deadline:
return timedelta(self.uploaded_at, deadline, descriptive=True) + suffix
return timedelta(self.uploaded_at, deadline, descriptive=True) + suffix
Loading