feat: 增加公告栏并让用户自选学时判断
This commit is contained in:
@@ -144,7 +144,7 @@ def heartbeat_intervals() -> dict:
|
||||
|
||||
|
||||
def hours_source_of(row: SystemConfig | None = None) -> str:
|
||||
"""api:接口本月学时;history:学时历史本月分钟合计。"""
|
||||
"""管理端为新用户准备的默认依据。api:官方统计;history:历史统计。"""
|
||||
if row is None:
|
||||
from euniv.db import SessionLocal
|
||||
|
||||
@@ -154,6 +154,25 @@ def hours_source_of(row: SystemConfig | None = None) -> str:
|
||||
return value if value in ("api", "history") else "api"
|
||||
|
||||
|
||||
def account_hours_source(account) -> str:
|
||||
value = str(getattr(account, "hours_source", "") or "").strip().lower()
|
||||
return value if value in ("api", "history") else hours_source_of()
|
||||
|
||||
|
||||
def source_for_employee(employee_id: str) -> str:
|
||||
from euniv.db import SessionLocal
|
||||
from euniv.models import Account
|
||||
|
||||
key = (employee_id or "").strip()
|
||||
if not key:
|
||||
return hours_source_of()
|
||||
with SessionLocal() as db:
|
||||
account = db.get(Account, key)
|
||||
if account is None:
|
||||
return hours_source_of()
|
||||
return account_hours_source(account)
|
||||
|
||||
|
||||
def settings_view(row: SystemConfig) -> dict:
|
||||
return {
|
||||
"refresh_interval_minutes": int(row.refresh_interval_minutes),
|
||||
@@ -234,7 +253,6 @@ def save_settings(db: Session, payload: dict) -> SystemConfig:
|
||||
row = load_config(db)
|
||||
previous_interval = int(row.refresh_interval_minutes)
|
||||
previous_username = row.admin_username
|
||||
previous_source = hours_source_of(row)
|
||||
row.refresh_interval_minutes = interval
|
||||
row.show_manual_jigsaw = bool(payload.get("show_manual_jigsaw"))
|
||||
row.manual_preference = bool(payload.get("manual_preference"))
|
||||
@@ -261,8 +279,4 @@ def save_settings(db: Session, payload: dict) -> SystemConfig:
|
||||
from euniv.service import notify_refresh_interval_changed
|
||||
|
||||
notify_refresh_interval_changed()
|
||||
if source != previous_source:
|
||||
from euniv.service import notify_hours_source_changed
|
||||
|
||||
notify_hours_source_changed()
|
||||
return row
|
||||
|
||||
Reference in New Issue
Block a user