fix: 补上未进子任务的首页、课程筛选和客户端构造
This commit is contained in:
@@ -13,6 +13,8 @@ from sqlalchemy.orm import Session
|
||||
from euniv.client import EUNIV
|
||||
from euniv.models import Account, Course, CourseSync
|
||||
|
||||
UNCATEGORIZED = "__none__"
|
||||
|
||||
_lock = threading.Lock()
|
||||
_running = False
|
||||
_message = ""
|
||||
@@ -65,19 +67,26 @@ def course_message() -> str:
|
||||
return _message
|
||||
|
||||
|
||||
def _like_pattern(value: str) -> str:
|
||||
escaped = value.replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_")
|
||||
return f"%{escaped}%"
|
||||
|
||||
|
||||
def course_page(db: Session, query: str, offset: int, limit: int, kind: str = "") -> dict:
|
||||
text = query.strip()
|
||||
base = []
|
||||
if text:
|
||||
like = f"%{text}%"
|
||||
base.append(or_(Course.title.like(like), Course.contributor.like(like)))
|
||||
like = _like_pattern(text)
|
||||
base.append(or_(Course.title.like(like, escape="\\"), Course.contributor.like(like, escape="\\")))
|
||||
counts = db.execute(select(Course.kind, func.count()).where(*base).group_by(Course.kind)).all()
|
||||
kinds = [
|
||||
{"name": name or "未分类", "value": name, "count": int(count)}
|
||||
{"name": name or "未分类", "value": name if name else UNCATEGORIZED, "count": int(count)}
|
||||
for name, count in sorted(counts, key=lambda row: (_kind_rank(row[0]), row[0]))
|
||||
]
|
||||
filters = list(base)
|
||||
if kind:
|
||||
if kind == UNCATEGORIZED:
|
||||
filters.append(Course.kind == "")
|
||||
elif kind:
|
||||
filters.append(Course.kind == kind)
|
||||
total = db.scalar(select(func.count()).select_from(Course).where(*filters)) or 0
|
||||
rows = db.scalars(
|
||||
|
||||
@@ -176,10 +176,7 @@ def _client(factory, employee_id: str, password: str, account: Account | None =
|
||||
from euniv.proxy import bind_url
|
||||
|
||||
proxy = bind_url(account) if account is not None else None
|
||||
try:
|
||||
return factory(employee_id, password, proxy)
|
||||
except TypeError:
|
||||
return factory(employee_id, password)
|
||||
return factory(employee_id, password, proxy)
|
||||
|
||||
|
||||
def _switch_proxy(account: Account | None, client, exc: BaseException) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user