feat: add council employee sorting by name and publication counts

This commit is contained in:
codex committed 2026-10-07 16:50:29 +03:00
1 parent fac0431a03
commit 32e26ccdd2
9 files changed
+105 -20

No files matched your search

+3 -2
View File
@@ -134,9 +134,10 @@ def directory(
@router.get("/council", response_class=HTMLResponse)
def council(request: Request, q: str = "", offset: int = 0, db: Session = Depends(get_db)):
def council(request: Request, q: str = "", offset: int = 0, sort: str = "csv_count", direction: str = "desc",
db: Session = Depends(get_db)):
try:
result = council_candidates(db, q=q, offset=offset)
result = council_candidates(db, q=q, offset=offset, sort=sort, direction=direction)
except (SQLAlchemyError, OSError, ValueError, KeyError):
db.rollback()
return _render(request, "council.html", {"error": True, "public_page": True}, status_code=503)
+8 -3
View File
@@ -149,7 +149,8 @@ def _unique_articles(articles: list[dict], start: date, end: date) -> list[dict]
return sorted(unique.values(), key=lambda item: (not item["csv_qualifies"], -(item["year"] or 0), item["title"].casefold()))
def council_candidates(db: Session, today: date | None = None, q: str = "", offset: int = 0) -> dict:
def council_candidates(db: Session, today: date | None = None, q: str = "", offset: int = 0,
sort: str = "csv_count", direction: str = "desc") -> dict:
today = today or datetime.now(ZoneInfo("Europe/Moscow")).date()
start, end = period(today)
employees = db.scalars(select(Employee).options(selectinload(Employee.publications))).all()
@@ -175,7 +176,11 @@ def council_candidates(db: Session, today: date | None = None, q: str = "", offs
"db_count": sum(a["in_db"] for a in articles), "articles": articles,
"profile_url": _safe_url(employee.canonical_url), "ambiguous": ambiguous,
"dismissed": employee.status == "dismissed"})
candidates.sort(key=lambda item: (-item["csv_count"], -item["count"], item["name"].casefold()))
sort = sort if sort in {"full_name", "csv_count", "db_count", "count"} else "csv_count"
direction = direction if direction in {"asc", "desc"} else "desc"
candidates.sort(key=lambda item: _name(item["name"]), reverse=sort == "full_name" and direction == "desc")
if sort != "full_name":
candidates.sort(key=lambda item: (item[sort], item["count"]), reverse=direction == "desc")
total = len(candidates)
query = _name(q)
candidates = [item for item in candidates if query in _name(item["name"])]
@@ -183,4 +188,4 @@ def council_candidates(db: Session, today: date | None = None, q: str = "", offs
limit = 25
offset = min(max(0, offset), ((matched - 1) // limit) * limit) if matched else 0
return {"candidates": candidates[offset:offset + limit], "start": start, "end": end, "total": total,
"matched": matched, "q": q, "offset": offset, "limit": limit}
"matched": matched, "q": q, "offset": offset, "limit": limit, "sort": sort, "direction": direction}
+18 -5
View File
@@ -26,8 +26,21 @@
<label class="directory__field" for="council-search">Поиск по ФИО
<input class="directory__input" id="council-search" name="q" type="search" value="{{ q }}" placeholder="Фамилия или полное имя">
</label>
<button class="button" type="submit">Найти</button>
{% if q %}<a class="admin__link" href="/admin/council">Сбросить поиск</a>{% endif %}
<label class="directory__field">Сортировать по
<select class="directory__input" name="sort">
{% for value, label in [('full_name', 'ФИО'), ('csv_count', 'Публикациям CSV по критериям'), ('db_count', 'Публикациям в БД'), ('count', 'Всего публикаций без дублей')] %}
<option value="{{ value }}"{% if sort == value %} selected{% endif %}>{{ label }}</option>
{% endfor %}
</select>
</label>
<label class="directory__field">Направление
<select class="directory__input" name="direction">
<option value="asc"{% if direction == 'asc' %} selected{% endif %}>По возрастанию</option>
<option value="desc"{% if direction == 'desc' %} selected{% endif %}>По убыванию</option>
</select>
</label>
<button class="button" type="submit">Применить</button>
{% if q %}<a class="admin__link" href="?sort={{ sort }}&amp;direction={{ direction }}">Сбросить поиск</a>{% endif %}
</form>
<div class="council__list-heading">
<h3>Сотрудники</h3>
@@ -76,16 +89,16 @@
</div>
{% if matched > limit %}
<nav class="directory__pagination" aria-label="Страницы сотрудников">
{% if offset > 0 %}<a class="admin__link" href="?q={{ q|urlencode }}&amp;offset={{ offset - limit }}">Назад</a>{% endif %}
{% if offset > 0 %}<a class="admin__link" href="?q={{ q|urlencode }}&amp;sort={{ sort }}&amp;direction={{ direction }}&amp;offset={{ offset - limit }}">Назад</a>{% endif %}
<span class="directory__page">{{ offset // limit + 1 }} / {{ (matched + limit - 1) // limit }}</span>
{% if offset + limit < matched %}<a class="admin__link" href="?q={{ q|urlencode }}&amp;offset={{ offset + limit }}">Далее</a>{% endif %}
{% if offset + limit < matched %}<a class="admin__link" href="?q={{ q|urlencode }}&amp;sort={{ sort }}&amp;direction={{ direction }}&amp;offset={{ offset + limit }}">Далее</a>{% endif %}
</nav>
{% endif %}
{% else %}
<div class="council__message">
<h4>{% if q %}Сотрудники не найдены{% else %}Сотрудники с докторской степенью и публикациями пока не найдены{% endif %}</h4>
<p>{% if q %}Попробуйте другую фамилию или сбросьте поиск.{% else %}Для включения в список нужны докторская степень в профиле и хотя бы одна публикация, однозначно связанная с сотрудником.{% endif %}</p>
{% if q %}<a class="admin__link" href="/admin/council">Сбросить поиск</a>{% endif %}
{% if q %}<a class="admin__link" href="?sort={{ sort }}&amp;direction={{ direction }}">Сбросить поиск</a>{% endif %}
</div>
{% endif %}
{% endif %}
+3 -3
View File
@@ -1,3 +1,3 @@
APP_VERSION = "0.11.1"
FRONTEND_VERSION = "0.11.1"
BACKEND_VERSION = "0.11.1"
APP_VERSION = "0.12.0"
FRONTEND_VERSION = "0.12.0"
BACKEND_VERSION = "0.12.0"