fix: 清掉无用接口和样式,并收紧登录与工号边界
This commit is contained in:
@@ -24,6 +24,26 @@ def validate_start(day: object, hour: object, minute: object, second: object) ->
|
||||
return int(day), int(hour), int(minute), int(second)
|
||||
|
||||
|
||||
def _clamp_int(value: object, low: int, high: int, default: int) -> int:
|
||||
if isinstance(value, bool):
|
||||
return default
|
||||
try:
|
||||
number = int(value) # type: ignore[arg-type]
|
||||
except (TypeError, ValueError):
|
||||
return default
|
||||
return min(high, max(low, number))
|
||||
|
||||
|
||||
def stored_start(account) -> tuple[int, int, int, int]:
|
||||
"""读取时把非法时刻收进合法范围,避免首页状态接口报错。"""
|
||||
return (
|
||||
_clamp_int(getattr(account, "study_start_day", 1), 1, 31, 1),
|
||||
_clamp_int(getattr(account, "study_start_hour", 0), 0, 23, 0),
|
||||
_clamp_int(getattr(account, "study_start_minute", 0), 0, 59, 0),
|
||||
_clamp_int(getattr(account, "study_start_second", 0), 0, 59, 0),
|
||||
)
|
||||
|
||||
|
||||
def apply(account, day: object, hour: object, minute: object, second: object) -> None:
|
||||
d, h, m, s = validate_start(day, hour, minute, second)
|
||||
account.study_start_day = d
|
||||
@@ -33,18 +53,12 @@ def apply(account, day: object, hour: object, minute: object, second: object) ->
|
||||
|
||||
|
||||
def label_of(account) -> str:
|
||||
day = int(getattr(account, "study_start_day", 1) or 1)
|
||||
hour = int(getattr(account, "study_start_hour", 0) or 0)
|
||||
minute = int(getattr(account, "study_start_minute", 0) or 0)
|
||||
second = int(getattr(account, "study_start_second", 0) or 0)
|
||||
day, hour, minute, second = stored_start(account)
|
||||
return f"每月{day}日 {hour:02d}:{minute:02d}:{second:02d}"
|
||||
|
||||
|
||||
def view_of(account) -> dict:
|
||||
day = int(getattr(account, "study_start_day", 1) or 1)
|
||||
hour = int(getattr(account, "study_start_hour", 0) or 0)
|
||||
minute = int(getattr(account, "study_start_minute", 0) or 0)
|
||||
second = int(getattr(account, "study_start_second", 0) or 0)
|
||||
day, hour, minute, second = stored_start(account)
|
||||
enabled = getattr(account, "study_schedule_enabled", True)
|
||||
return {
|
||||
"day": day,
|
||||
@@ -71,12 +85,7 @@ def month_key(now: datetime | None = None) -> str:
|
||||
def start_at(account, now: datetime | None = None) -> datetime:
|
||||
"""该账号在 now 所在月的开始时刻。2 月 31 日等按当月最后一天。"""
|
||||
current = as_cn(now)
|
||||
day, hour, minute, second = validate_start(
|
||||
int(getattr(account, "study_start_day", 1) or 1),
|
||||
int(getattr(account, "study_start_hour", 0) or 0),
|
||||
int(getattr(account, "study_start_minute", 0) or 0),
|
||||
int(getattr(account, "study_start_second", 0) or 0),
|
||||
)
|
||||
day, hour, minute, second = stored_start(account)
|
||||
last = calendar.monthrange(current.year, current.month)[1]
|
||||
return datetime(
|
||||
current.year,
|
||||
|
||||
Reference in New Issue
Block a user