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

DB: Přesunutí task_statement_available jako metodu db.Round

parent 45014c19
No related branches found
No related tags found
2 merge requests!12Účastnická část webu podporuje všechny stavy kola,!9WIP: Zárodek uživatelské části webu a submitování
......@@ -15,6 +15,7 @@ from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.ext.declarative import declarative_base
from typing import Optional, List
import mo
# HACK: Work-around for https://github.com/dropbox/sqlalchemy-stubs/issues/114
from typing import TYPE_CHECKING, TypeVar, Type, Any
......@@ -186,6 +187,13 @@ class Round(Base):
def round_code(self):
return f"{self.year}-{self.category}-{self.seq}"
def task_statement_available(self) -> bool:
# Zde jsme raději přepečliví...
return (self.state != RoundState.preparing
and self.tasks_file is not None
and self.ct_tasks_start is not None
and mo.now >= self.ct_tasks_start)
class User(Base):
__tablename__ = 'users'
......
......@@ -76,16 +76,6 @@ def get_task(contest: db.Contest, id: int) -> db.Task:
return task
def task_statement_available(contest: db.Contest) -> bool:
round = contest.round
# Zde jsme raději přepečliví...
return (round.state == db.RoundState.running
and round.tasks_file is not None
and round.ct_tasks_start is not None
and mo.now >= round.ct_tasks_start)
@app.route('/user/contest/<int:id>/')
def user_contest(id: int):
contest = get_contest(id)
......@@ -104,7 +94,7 @@ def user_contest(id: int):
'user_contest.html',
contest=contest,
task_sols=task_sols,
statement_visible=task_statement_available(contest),
statement_visible=contest.round.task_statement_available(),
max_submit_size=config.MAX_CONTENT_LENGTH,
db=db, # kvůli hodnotám enumů
)
......@@ -114,7 +104,7 @@ def user_contest(id: int):
def user_task_statement(id: int):
contest = get_contest(id)
if not task_statement_available(contest):
if not contest.round.task_statement_available():
logger.warn(f'Účastník #{g.user.user_id} chce zadání, na které nemá právo')
raise werkzeug.exceptions.Forbidden()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment