feat: account sessions and usable template editors
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import calendar
|
||||
import json
|
||||
from datetime import datetime
|
||||
from io import BytesIO
|
||||
@@ -99,6 +100,38 @@ class TemplateRenderer:
|
||||
x, y, w, h = block["box"]
|
||||
if block["kind"] == "rule":
|
||||
draw.rectangle((x, y, x + w, y + h), fill=accent)
|
||||
elif block["kind"] == "month":
|
||||
try:
|
||||
shown = datetime.strptime(str(values["date"]), "%Y-%m-%d")
|
||||
except ValueError:
|
||||
raise FlowError(
|
||||
E.INVALID_REQUEST, "Calendar date must be YYYY-MM-DD"
|
||||
) from None
|
||||
text(shown.strftime("%Y-%m"), x, y, w, 70, 48)
|
||||
cells = calendar.Calendar(firstweekday=0).monthdayscalendar(
|
||||
shown.year, shown.month
|
||||
)
|
||||
cell_w, cell_h = w // 7, (h - 140) // len(cells)
|
||||
for col, label in enumerate(
|
||||
["一 M", "二 T", "三 W", "四 T", "五 F", "六 S", "日 S"]
|
||||
):
|
||||
text(label, x + col * cell_w + 10, y + 80, cell_w - 20, 60, 30)
|
||||
for row, week in enumerate(cells):
|
||||
for col, day in enumerate(week):
|
||||
if not day:
|
||||
continue
|
||||
left, top = x + col * cell_w, y + 140 + row * cell_h
|
||||
if (shown.year, shown.month, day) == (
|
||||
current.year,
|
||||
current.month,
|
||||
current.day,
|
||||
):
|
||||
draw.rectangle(
|
||||
(left, top, left + cell_w - 6, top + cell_h - 6),
|
||||
outline=accent,
|
||||
width=5,
|
||||
)
|
||||
text(day, left + 25, top + 10, cell_w - 35, cell_h, 38)
|
||||
elif block["kind"] == "photo":
|
||||
asset_id = values.get("photo_id")
|
||||
if asset_id:
|
||||
|
||||
Reference in New Issue
Block a user