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
Branches
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í
This commit is part of merge request !12. Comments created here will be created in the context of that merge request.
...@@ -15,6 +15,7 @@ from sqlalchemy.dialects.postgresql import JSONB ...@@ -15,6 +15,7 @@ from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
from typing import Optional, List from typing import Optional, List
import mo
# HACK: Work-around for https://github.com/dropbox/sqlalchemy-stubs/issues/114 # HACK: Work-around for https://github.com/dropbox/sqlalchemy-stubs/issues/114
from typing import TYPE_CHECKING, TypeVar, Type, Any from typing import TYPE_CHECKING, TypeVar, Type, Any
...@@ -186,6 +187,13 @@ class Round(Base): ...@@ -186,6 +187,13 @@ 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 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): class User(Base):
__tablename__ = 'users' __tablename__ = 'users'
......
...@@ -76,16 +76,6 @@ def get_task(contest: db.Contest, id: int) -> db.Task: ...@@ -76,16 +76,6 @@ def get_task(contest: db.Contest, id: int) -> db.Task:
return 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>/') @app.route('/user/contest/<int:id>/')
def user_contest(id: int): def user_contest(id: int):
contest = get_contest(id) contest = get_contest(id)
...@@ -104,7 +94,7 @@ def user_contest(id: int): ...@@ -104,7 +94,7 @@ def user_contest(id: int):
'user_contest.html', 'user_contest.html',
contest=contest, contest=contest,
task_sols=task_sols, task_sols=task_sols,
statement_visible=task_statement_available(contest), statement_visible=contest.round.task_statement_available(),
max_submit_size=config.MAX_CONTENT_LENGTH, max_submit_size=config.MAX_CONTENT_LENGTH,
db=db, # kvůli hodnotám enumů db=db, # kvůli hodnotám enumů
) )
...@@ -114,7 +104,7 @@ def user_contest(id: int): ...@@ -114,7 +104,7 @@ def user_contest(id: int):
def user_task_statement(id: int): def user_task_statement(id: int):
contest = get_contest(id) 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') logger.warn(f'Účastník #{g.user.user_id} chce zadání, na které nemá právo')
raise werkzeug.exceptions.Forbidden() 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