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

Opravený typing pro výsledkové listiny

parent f4d0cbd9
No related branches found
No related tags found
No related merge requests found
......@@ -118,6 +118,7 @@ class Score:
# Příprava subquery na účastníky (contest_subq obsahuje master_contest_id)
sess = db.get_session()
contest_subq: Union[List[int], Query]
if contest:
assert contest.master_contest_id is not None
contest_subq = [contest.master_contest_id]
......
......@@ -2,11 +2,11 @@ import decimal
from flask import g, render_template, request
from flask.helpers import flash, url_for
from typing import Iterable, List, Optional, Tuple, Union
from flask_wtf.form import FlaskForm
from flask_wtf.form import FlaskForm # type: ignore
import json
import werkzeug.exceptions
from werkzeug.utils import redirect
import wtforms
import wtforms # type: ignore
import mo
import mo.db as db
......@@ -34,17 +34,12 @@ class SolPointsCell(Cell):
def __str__(self) -> str:
if not self.sol:
return ''
elif self.sol.points is None:
return '?'
return format_decimal(self.sol.points)
return format_decimal(self.sol.points) or '?'
def to_html(self) -> str:
if not self.sol:
return '<td>–'
elif self.sol.points is None:
points = '<span class="unknown">?</span>'
else:
points = format_decimal(self.sol.points)
points = format_decimal(self.sol.points) or '<span class="unknown">?</span>'
if not self.link_to_paper:
return f'<td>{points}'
......@@ -103,7 +98,7 @@ def org_score(round_id: Optional[int] = None, hier_id: Optional[int] = None, ct_
count = 0
for result in results:
try:
score_suborder = int(request.form.get(f"suborder_{result.user.user_id}"))
score_suborder = request.form.get(f"suborder_{result.user.user_id}", type=int)
except ValueError:
score_suborder = None
......@@ -208,7 +203,7 @@ def org_score(round_id: Optional[int] = None, hier_id: Optional[int] = None, ct_
'total_points': format_decimal(result.get_total_points()),
'birth_year': pant.birth_year,
'order_key': result._order_key,
'suborder': CellInput(f"suborder_{user.user_id}", pion.score_suborder, "number", attrs={"size": 6}),
'suborder': CellInput(f"suborder_{user.user_id}", str(pion.score_suborder), "number", attrs={"size": "6"}),
})
sols = result.get_sols_map()
......@@ -300,23 +295,24 @@ def org_score_snapshots(ct_id: int):
snapshot_rows = []
for result in results:
snapshot_row = {
tasks_points: List[Optional[str]] = []
sols = result.get_sols_map()
for task in tasks:
sol = sols.get(task.task_id)
tasks_points.append(format_decimal(sol.points) if sol else None)
snapshot_rows.append({
'order': result.order.__dict__,
'winner': result.winner,
'successful': result.successful,
'name': result.user.full_name(),
'school': result.pant.school_place.name or "?",
'grade': result.pant.grade,
'tasks': [],
'tasks': tasks_points,
'total_points': format_decimal(result.get_total_points()),
'birth_year': result.pant.birth_year,
'order_key': json.dumps(result._order_key, cls=OrderKeyEncoder)
}
sols = result.get_sols_map()
for task in tasks:
sol = sols.get(task.task_id)
snapshot_row['tasks'].append(format_decimal(sol.points) if sol else None)
snapshot_rows.append(snapshot_row)
})
score_table = db.ScoreTable(
contest_id=ct_id,
......
......@@ -6,7 +6,7 @@ import hashlib
import hmac
from sqlalchemy import and_
from sqlalchemy.orm import joinedload
from typing import List, Tuple, Optional
from typing import List, Tuple, Optional, Dict, Any
import werkzeug.exceptions
import wtforms
from wtforms.validators import Required
......@@ -508,13 +508,15 @@ def scoretable_construct(scoretable: db.ScoreTable, is_export: bool = False) ->
if is_export:
columns.insert(1, Column(key='status', name='stav'))
for (code, name) in scoretable.tasks:
tasks: List[Tuple[str, str]] = scoretable.tasks # type: ignore
for (code, name) in tasks:
columns.append(Column(key=f'task_{code}', name=code, title=code))
columns.append(Column(key='total_points', name='celkove_body', title='Celkové body'))
table_rows = []
for row in scoretable.rows:
order_cell = OrderCell(place=row['order']['place'], span=row['order']['span'], continuation=row['order']['continuation'])
rows: List[Dict[str, Any]] = scoretable.rows # type: ignore
for row in rows:
order_cell = OrderCell(place=int(row['order']['place']), span=int(row['order']['span']), continuation=bool(row['order']['continuation']))
row['order'] = order_cell
html_attr = {}
......@@ -525,7 +527,7 @@ def scoretable_construct(scoretable: db.ScoreTable, is_export: bool = False) ->
row['status'] = 'úspěšný'
html_attr = {"class": "successful", "title": "Úspěšný řešitel"}
for ((code, _), points) in zip(scoretable.tasks, row['tasks']):
for ((code, _), points) in zip(tasks, row['tasks']):
row[f'task_{code}'] = points or ''
table_rows.append(Row(keys=row, html_attr=html_attr))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment