forked from admin/miem_workers
Добавить подтверждение списка ДПО в карточке сотрудника
This commit is contained in:
1 parent
21a6d51432
commit
a4b188d562
14 files changed
+273
-23
No files matched your search
@@ -1,5 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import re
|
||||
from datetime import date, datetime, time
|
||||
from math import ceil
|
||||
@@ -114,6 +116,37 @@ def _display_sections(data):
|
||||
return sections
|
||||
|
||||
|
||||
def dpo_sections(sections):
|
||||
return [s for s in sections if isinstance(s, dict) and s.get("type") == "additional_education"]
|
||||
|
||||
|
||||
def dpo_source_digest(education):
|
||||
# Ignore presentation order and unrelated profile updates.
|
||||
def canonical(value):
|
||||
return json.dumps(value, sort_keys=True, ensure_ascii=False, separators=(",", ":"))
|
||||
|
||||
sources = [canonical({key: sorted(canonical(v) for v in section.get(key, []))
|
||||
for key in ("items", "year_entries", "unresolved", "unresolved_documents", "links")}
|
||||
| {"title": section.get("title")}) for section in education]
|
||||
return hashlib.sha256(canonical(sorted(sources)).encode()).hexdigest()
|
||||
|
||||
|
||||
def dpo_suggestions(education):
|
||||
courses = []
|
||||
for section in education:
|
||||
for title in section.get("items", []):
|
||||
dedicated = str(section.get("title") or "").casefold().strip().rstrip(":") in {
|
||||
_TRAINING_LABEL, "курсы повышения квалификации"}
|
||||
text = _QUOTED_TEXT.sub("", title)
|
||||
year = _TRAINING_YEAR.search(text)
|
||||
kind = "training" if dedicated or _TRAINING_KIND.search(text) or _TRAINING_MENTION.search(text) else "other"
|
||||
if "переподготовк" in text.casefold():
|
||||
kind = "retraining"
|
||||
courses.append({"title": title, "kind": kind, "year": int(year.group(1) or year.group(2)) if year else None,
|
||||
"evidence": ""})
|
||||
return courses
|
||||
|
||||
|
||||
def employee_display_payload(employee: Employee, *, sections=None) -> dict[str, Any]:
|
||||
data = _as_dict(employee.current_data)
|
||||
contacts = _as_dict(data.get("contacts"))
|
||||
@@ -124,7 +157,8 @@ def employee_display_payload(employee: Employee, *, sections=None) -> dict[str,
|
||||
emails = _clean_list(contacts.get("emails"))
|
||||
phones = _clean_list(contacts.get("phones"))
|
||||
degree_values = academic_degrees(data)
|
||||
education = [s for s in sections if isinstance(s, dict) and s.get("type") == "additional_education"]
|
||||
education = dpo_sections(sections)
|
||||
review = employee.dpo_review
|
||||
dpo_count = sum(len(s.get("items", [])) for s in education)
|
||||
return {
|
||||
"id": employee.id,
|
||||
@@ -142,8 +176,8 @@ def employee_display_payload(employee: Employee, *, sections=None) -> dict[str,
|
||||
"address": contacts.get("address"),
|
||||
"academic_degree_text": "; ".join(degree_values),
|
||||
"publications_count": _count_section_items(sections, "publications"),
|
||||
"dpo_count": dpo_count or None,
|
||||
"dpo_uncertain": any(not s.get("items") or s.get("unresolved") or s.get("unresolved_documents") for s in education),
|
||||
"dpo_count": len(review.courses) if review else dpo_count or None,
|
||||
"dpo_uncertain": review.source_digest != dpo_source_digest(education) if review else any(not s.get("items") or s.get("unresolved") or s.get("unresolved_documents") for s in education),
|
||||
"courses_count": _count_section_items(sections, "courses_by_year"),
|
||||
"news_count": len(stored_news_links) or _count_section_items(sections, "news"),
|
||||
"first_seen_at": employee.first_seen_at.isoformat() if employee.first_seen_at else None,
|
||||
@@ -161,6 +195,8 @@ def employee_detail_payload(employee: Employee) -> dict[str, Any]:
|
||||
contacts = _as_dict(data.get("contacts"))
|
||||
return {
|
||||
**employee_display_payload(employee, sections=sections),
|
||||
"dpo_source": dpo_source_digest(dpo_sections(sections)),
|
||||
"dpo_courses": employee.dpo_review.courses if employee.dpo_review else dpo_suggestions(dpo_sections(sections)),
|
||||
"profile_type": employee.profile_type or data.get("profile_type"),
|
||||
"profile_id": employee.profile_id or data.get("profile_id"),
|
||||
"parser_version": employee.parser_version or data.get("parser_version"),
|
||||
@@ -252,8 +288,13 @@ def list_employees_page(
|
||||
if pps and not any("кафедра" in position.casefold() or "департамент" in position.casefold()
|
||||
for position in _clean_list(data.get("positions"))):
|
||||
continue
|
||||
if has_training is not None and _has_training(data, training_since_year) != has_training:
|
||||
continue
|
||||
if has_training is not None:
|
||||
review = employee.dpo_review
|
||||
matches = (any(course["kind"] == "training" and
|
||||
(training_since_year is None or (course["year"] or 0) >= training_since_year)
|
||||
for course in review.courses) if review else _has_training(data, training_since_year))
|
||||
if matches != has_training:
|
||||
continue
|
||||
if paginate and offset and total < limit:
|
||||
first_page.append(employee)
|
||||
if not paginate or offset <= total < offset + limit:
|
||||
|
||||
Reference in new issue
Block a user