fix(admin-invites): left-align create card conditional fields, convert local datetime to UTC on save
This commit is contained in:
@@ -47,6 +47,14 @@ def _to_local(dt: datetime) -> datetime:
|
||||
return dt.astimezone(_CST)
|
||||
|
||||
|
||||
def _to_utc(dt_str: str) -> datetime:
|
||||
"""Parse local datetime-local string and convert to UTC."""
|
||||
dt = datetime.fromisoformat(dt_str)
|
||||
if dt.tzinfo is None:
|
||||
dt = dt.replace(tzinfo=_CST)
|
||||
return dt.astimezone(timezone.utc).replace(tzinfo=None)
|
||||
|
||||
|
||||
templates.env.filters["to_local"] = _to_local
|
||||
|
||||
|
||||
@@ -218,7 +226,7 @@ def admin_add_invite(
|
||||
if limit_type == "uses" and max_uses:
|
||||
m_uses = max_uses
|
||||
elif limit_type == "expires" and expires_at:
|
||||
exp_at = datetime.fromisoformat(expires_at)
|
||||
exp_at = _to_utc(expires_at)
|
||||
new_code = InviteCode(
|
||||
code=code, max_uses=m_uses, expires_at=exp_at,
|
||||
use_count=0, created_by=user.id,
|
||||
@@ -251,7 +259,7 @@ def admin_edit_invite(
|
||||
code_obj.max_uses = max_uses
|
||||
code_obj.expires_at = None
|
||||
elif limit_type == "expires" and expires_at:
|
||||
code_obj.expires_at = datetime.fromisoformat(expires_at)
|
||||
code_obj.expires_at = _to_utc(expires_at)
|
||||
code_obj.max_uses = None
|
||||
else:
|
||||
code_obj.max_uses = None
|
||||
|
||||
@@ -28,11 +28,11 @@
|
||||
<option value="expires">有效期</option>
|
||||
</select>
|
||||
</div>
|
||||
<div id="max_uses_field" style="display:none;align-items:center;gap:.3rem;align-self:flex-end">
|
||||
<div id="max_uses_field" style="display:none;align-items:center;gap:.3rem">
|
||||
<label style="margin:0;font-size:.8rem;white-space:nowrap">次数</label>
|
||||
<input type="number" name="max_uses" min="1" value="1" class="aif-input aif-short">
|
||||
</div>
|
||||
<div id="expires_field" style="display:none;align-items:center;gap:.3rem;align-self:flex-end">
|
||||
<div id="expires_field" style="display:none;align-items:center;gap:.3rem">
|
||||
<label style="margin:0;font-size:.8rem;white-space:nowrap">有效期</label>
|
||||
<input type="datetime-local" name="expires_at" class="aif-input aif-date">
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user