Files
RexiMemo-OSE/hatenadir/ds/v2-xx/channels.ugo.py
T
rekushi 6e77720167 feat(dsi): add a paginated channel directory
List configured channels in a native menu with browsing and posting links.
2026-10-29 04:41:36 +00:00

21 lines
1.0 KiB
Python

from twisted.web import resource
from DB import Database
from reximemo import dsi_url, make_menu, page_number, pagination_buttons
class PyResource(resource.Resource):
isLeaf = True
def render_GET(self, request):
channels = Database.list_channels()
page = page_number(request, len(channels), 25)
buttons = [{"label": channel["title"], "url": dsi_url(request, f"ch/{channel['id']}.uls"), "icon": 101}
for channel in channels[(page - 1) * 25:page * 25]]
pager = pagination_buttons(request, "channels.uls", page, len(channels), 25)
before = [button for button in pager if button["label"].startswith("Previous")]
after = [button for button in pager if button["label"].startswith("Next")]
request.setHeader(b"content-type", b"text/plain")
return make_menu(layout=(2, 1), title="Channels", subtitle_bottom="Choose a channel to browse or post.",
left="Channels", right=str(len(channels)), buttons=before + buttons + after)