Skip to content
Snippets Groups Projects
Commit 13c1e0e5 authored by Martin Mareš's avatar Martin Mareš
Browse files

Klikací odkazy v tabulkach

parent 609c0013
No related branches found
No related tags found
No related merge requests found
...@@ -16,7 +16,7 @@ import mo.imports ...@@ -16,7 +16,7 @@ import mo.imports
import mo.rights import mo.rights
import mo.util import mo.util
from mo.web import app from mo.web import app
from mo.web.table import Table, Column, cell_place_link, cell_user_link from mo.web.table import Table, Column, cell_place_link, cell_user_link, cell_email_link
import wtforms.validators as validators import wtforms.validators as validators
...@@ -255,20 +255,22 @@ def make_contestant_table(round: db.Round, contest: Optional[db.Contest]) -> Tab ...@@ -255,20 +255,22 @@ def make_contestant_table(round: db.Round, contest: Optional[db.Contest]) -> Tab
rows: List[dict] = [] rows: List[dict] = []
for pion, pant, ct in ctants: for pion, pant, ct in ctants:
u = pion.user
rows.append({ rows.append({
'first_name': pion.user.first_name, 'sort_key': (locale.strxfrm(u.last_name), locale.strxfrm(u.first_name), u.user_id),
'last_name': pion.user.last_name, 'first_name': cell_user_link(u, u.first_name),
'email': cell_user_link(pion.user, pion.user.email), 'last_name': cell_user_link(u, u.last_name),
'email': cell_email_link(u),
'school': pant.school_place.name, 'school': pant.school_place.name,
'school_code': cell_place_link(pant.school_place, pant.school_place.get_code()), 'school_code': cell_place_link(pant.school_place, pant.school_place.get_code()),
'grade': pant.grade, 'grade': pant.grade,
'born_year': pant.birth_year, 'born_year': pant.birth_year,
'region_code': ct.place.get_code(), 'region_code': cell_place_link(ct.place, ct.place.get_code()),
'place_code': pion.place.get_code(), 'place_code': cell_place_link(pion.place, pion.place.get_code()),
'status': pion.state.name, 'status': pion.state.name,
}) })
rows.sort(key=lambda r: (locale.strxfrm(r['last_name']), locale.strxfrm(r['first_name']))) rows.sort(key=lambda r: r['sort_key'])
cols: Sequence[Column] = contest_list_columns cols: Sequence[Column] = contest_list_columns
if not contest: if not contest:
......
...@@ -5,6 +5,7 @@ from html import escape ...@@ -5,6 +5,7 @@ from html import escape
import io import io
from markupsafe import Markup from markupsafe import Markup
from typing import Sequence, Optional, Iterable from typing import Sequence, Optional, Iterable
import urllib.parse
import werkzeug.exceptions import werkzeug.exceptions
import mo.csv import mo.csv
...@@ -40,13 +41,18 @@ class Cell: ...@@ -40,13 +41,18 @@ class Cell:
class CellLink(Cell): class CellLink(Cell):
url: str url: str
hint: Optional[str]
def __init__(self, text: str, url: str): def __init__(self, text: str, url: str, hint: Optional[str] = None):
Cell.__init__(self, text) Cell.__init__(self, text)
self.url = url self.url = url
self.hint = hint
def to_html(self) -> str: def to_html(self) -> str:
return '<a href="' + escape(self.url) + '">' + escape(self.text) + '</a>' a = '<a href="' + escape(self.url) + '"'
if self.hint:
a += ' title="' + escape(self.hint) + '"'
return a + '>' + escape(self.text) + '</a>'
class Table: class Table:
...@@ -138,9 +144,13 @@ class Table: ...@@ -138,9 +144,13 @@ class Table:
# Pomocné funkce na generování různých typů odkazů # Pomocné funkce na generování různých typů odkazů
def cell_email_link(user: db.User) -> CellLink:
return CellLink(user.email, 'mailto:' + urllib.parse.quote(user.email, safe='@'))
def cell_user_link(user: db.User, text: str) -> CellLink: def cell_user_link(user: db.User, text: str) -> CellLink:
return CellLink(text, '/FIXME') return CellLink(text, url_for('org_user', id=user.user_id))
def cell_place_link(place: db.Place, text: str) -> CellLink: def cell_place_link(place: db.Place, text: str) -> CellLink:
return CellLink(text, url_for('org_place', id=place.place_id)) return CellLink(text, url_for('org_place', id=place.place_id), hint=place.name)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment