- 新增 reflections 应用:Work / WorkImage / Reflection 及迁移 - 条目分类(电影/书籍/其他),图片墙与随感时间线 - 浏览公开;新建、上传、写随感复用拾匣密码解锁 - 抽出 cabinet/access.py 共享解锁状态 - 首页新增「拾味」入口
32 lines
737 B
Python
32 lines
737 B
Python
"""站点写操作的共用解锁状态(目前由拾匣与拾味共用)。"""
|
|
|
|
import time
|
|
|
|
from django.conf import settings
|
|
|
|
UNLOCK_SESSION_KEY = "cabinet_unlocked_at"
|
|
|
|
|
|
def unlock_minutes():
|
|
return max(1, int(getattr(settings, "CABINET_UNLOCK_MINUTES", 120)))
|
|
|
|
|
|
def _stamp(request):
|
|
try:
|
|
return float(request.session.get(UNLOCK_SESSION_KEY) or 0)
|
|
except (TypeError, ValueError):
|
|
return 0.0
|
|
|
|
|
|
def is_unlocked(request):
|
|
stamp = _stamp(request)
|
|
return bool(stamp) and (time.time() - stamp) < unlock_minutes() * 60
|
|
|
|
|
|
def minutes_left(request):
|
|
stamp = _stamp(request)
|
|
if not stamp:
|
|
return 0
|
|
left = unlock_minutes() * 60 - (time.time() - stamp)
|
|
return max(0, int(left // 60))
|