From 552bb0c67518ca10cdaf62d9d35c49e332dac4a2 Mon Sep 17 00:00:00 2001 From: Jiri Kalvoda <jirikalvoda@kam.mff.cuni.cz> Date: Fri, 2 Jul 2021 23:31:30 +0200 Subject: [PATCH] =?UTF-8?q?Pou=C5=BEit=C3=AD=20user=5Fhtml=5Fflags.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Nahrazuje stávající manuální vytváření hvězdiček pro neaktivní uživatele a podbarvení testuserů. --- mo/web/org_contest.py | 7 ++----- mo/web/table.py | 4 ++++ mo/web/templates/org_contest_solutions.html | 2 +- mo/web/templates/org_contest_user.html | 2 +- mo/web/templates/org_orgs.html | 2 +- mo/web/templates/org_submit_list.html | 2 +- mo/web/templates/org_users.html | 4 ++-- mo/web/templates/parts/org_solution_table.html | 4 ++-- 8 files changed, 14 insertions(+), 13 deletions(-) diff --git a/mo/web/org_contest.py b/mo/web/org_contest.py index fdebce5c..1d72081d 100644 --- a/mo/web/org_contest.py +++ b/mo/web/org_contest.py @@ -25,7 +25,7 @@ from mo.util_format import inflect_number, inflect_by_number from mo.web import app import mo.web.util from mo.web.util import MODecimalField, PagerForm -from mo.web.table import CellCheckbox, Table, Row, Column, cell_pion_link, cell_place_link, cell_email_link +from mo.web.table import CellCheckbox, Table, Row, Column, cell_pion_link, cell_place_link, cell_email_link, cell_email_link_flags, CellMarkup import wtforms.validators as validators from wtforms.widgets.html5 import NumberInput @@ -551,16 +551,13 @@ def make_contestant_table(query: Query, round: db.Round, add_checkbox: bool = Fa html_attr = { 'class': 'state-' + pion.state.name } - if u.is_test: - html_attr['class'] += ' testuser' - html_attr['title'] = 'Testovací uživatel' rows.append(Row( keys={ 'sort_key': u.sort_key(), 'user_id': u.user_id, 'first_name': cell_pion_link(u, pion.contest_id, u.first_name), 'last_name': cell_pion_link(u, pion.contest_id, u.last_name), - 'email': cell_email_link(u), + 'email': cell_email_link_flags(u), 'school': pant.school_place.name, 'school_code': cell_place_link(pant.school_place, pant.school_place.get_code()), 'grade': pant.grade, diff --git a/mo/web/table.py b/mo/web/table.py index 4b4a1577..72cbbcd1 100644 --- a/mo/web/table.py +++ b/mo/web/table.py @@ -11,6 +11,7 @@ import werkzeug.exceptions from mo.csv import FileFormat import mo.db as db from mo.web import app +from mo.web.util import user_html_flags @dataclass @@ -200,6 +201,9 @@ class Table: def cell_email_link(user: db.User) -> CellLink: return CellLink(user.email, 'mailto:' + urllib.parse.quote(user.email, safe='@')) +def cell_email_link_flags(user: db.User) -> CellLink: + return CellLink(user.email, 'mailto:' + urllib.parse.quote(user.email, safe='@'), html_suffix=user_html_flags(user)) + def cell_user_link(user: db.User, text: str) -> CellLink: return CellLink(text, url_for('org_user', id=user.user_id)) diff --git a/mo/web/templates/org_contest_solutions.html b/mo/web/templates/org_contest_solutions.html index 7bda4f7c..7df83f66 100644 --- a/mo/web/templates/org_contest_solutions.html +++ b/mo/web/templates/org_contest_solutions.html @@ -61,7 +61,7 @@ konkrétní úlohu. Symbol <span class="icon">🗐</span> značí, že existuje </thead> {% for pion in pions %} {% set u = pion.user %} - <tr class="state-{{ pion.state.name }}{% if u.is_test %} testuser{% endif %}" {% if u.is_test %}title="Testovací uživatel"{% endif %}> + <tr class="state-{{ pion.state.name }}> <th>{{ u|pion_link(contest.contest_id) }} <td>{{ pion.state.friendly_name() }} {% set sum_points = [] %} diff --git a/mo/web/templates/org_contest_user.html b/mo/web/templates/org_contest_user.html index c6e8e470..d37540fb 100644 --- a/mo/web/templates/org_contest_user.html +++ b/mo/web/templates/org_contest_user.html @@ -32,7 +32,7 @@ </thead> <tr><td>Jméno:<td>{{ user.first_name }} <tr><td>Příjmení:<td>{{ user.last_name }} - <tr><td>E-mail:<td>{{ user.email|mailto }} + <tr><td>E-mail:<td>{{ user.email|mailto }}{{ user|user_flags }} <tr><td>Škola:<td><a href='{{ url_for('org_place', id=pant.school) }}'>{{ pant.school_place.name }}</a> <tr><td>Třída:<td>{{ pant.grade }} <tr><td>Rok narození:<td>{{ pant.birth_year }} diff --git a/mo/web/templates/org_orgs.html b/mo/web/templates/org_orgs.html index 52d30633..dbd6cc7e 100644 --- a/mo/web/templates/org_orgs.html +++ b/mo/web/templates/org_orgs.html @@ -51,7 +51,7 @@ {% for user in users %} <tr> <td>{{ user.first_name }}</td><td>{{ user.last_name }}</td> - <td>{{ user.email|mailto }}{% if user.password_hash == None %}<span class="user-inactive" title='Účet dosud nebyl aktivován'> *</span>{% endif %}</td> + <td>{{ user.email|mailto }}{{ user|user_flags }}</td> <td>{% if user.is_admin %}správce{% elif user.roles|count == 0 %}<i>žádná role</i>{% else %} <ul> {% for role in user.roles %} diff --git a/mo/web/templates/org_submit_list.html b/mo/web/templates/org_submit_list.html index de2b4e61..ff445d3e 100644 --- a/mo/web/templates/org_submit_list.html +++ b/mo/web/templates/org_submit_list.html @@ -9,7 +9,7 @@ {% set site_id = sc.site.place_id if sc.site else None %} <table class="data"> - <tr><th>Účastník<td>{{ sc.user|pion_link(sc.contest.contest_id) }} + <tr><th>Účastník<td>{{ sc.user|pion_link(sc.contest.contest_id) }}{{ sc.user|user_flags }} <tr><th>Úloha<td><a href='{{ url_for('org_contest_task', contest_id=sc.contest.contest_id, site_id=site_id, task_id=sc.task.task_id) }}'>{{ sc.task.code }} {{ sc.task.name }}</a> {% if solution %} <tr><th>Body<td> diff --git a/mo/web/templates/org_users.html b/mo/web/templates/org_users.html index df46553b..e1b2b2f6 100644 --- a/mo/web/templates/org_users.html +++ b/mo/web/templates/org_users.html @@ -73,9 +73,9 @@ </tr> </thead> {% for user in users %} - <tr{% if user.is_test %} class="testuser" title="Testovací uživatel"{% endif %}> + <tr> <td>{{ user.first_name }}</td><td>{{ user.last_name }}</td> - <td>{{ user.email|mailto }}{% if user.password_hash == None %}<span class="user-inactive" title='Účet dosud nebyl aktivován'> *</span>{% endif %}</td> + <td>{{ user.email|mailto }}{{ user|user_flags }}</td> <td>{% if user.participants|count == 0 %}<i>v žádném ročníku</i>{% else %} <ul> {% for participant in user.participants %} diff --git a/mo/web/templates/parts/org_solution_table.html b/mo/web/templates/parts/org_solution_table.html index 6223a92c..c8a85be2 100644 --- a/mo/web/templates/parts/org_solution_table.html +++ b/mo/web/templates/parts/org_solution_table.html @@ -35,14 +35,14 @@ finální (ve výchozím stavu poslední nahrané).{% elif sc.allow_upload_solut {% set u = for_user or obj.user %} {% set task = for_task or obj %} {% if for_task %} - <tr class="state-{{ obj.state.name }}{% if u.is_test %} testuser{% endif %}" {% if u.is_test %}title="Testovací uživatel"{% endif %}> + <tr class="state-{{ obj.state.name }}"> {% else %} <tr> {% endif %} <td>{% if for_user %} <a href='{{ url_for('org_contest_task', contest_id=ct_id, task_id=task.task_id) }}'>{{ task.code }} {{ task.name }}</a> {% else %} - {{ u|pion_link(contest.contest_id) }}</a> + {{ u|pion_link(contest.contest_id) }}{{ u|user_flags }}</a> {% endif %} {% if for_task %}<td>{{ obj.state.friendly_name() }}{% endif %} {% if sol %} -- GitLab