feat(dsi): add a paginated channel directory
List configured channels in a native menu with browsing and posting links.
This commit is contained in:
1 parent
5ded340997
commit
6e77720167
1 file changed
+20
@@ -0,0 +1,20 @@
|
|||||||
|
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)
|
||||||
Reference in new issue
Block a user
