Add paginator

This commit is contained in:
Andros Fenollosa 2021-11-12 22:16:42 +01:00
parent 7f65835db7
commit b8b101b466
4 changed files with 29 additions and 11 deletions

6
TODO
View File

@ -1,3 +1,3 @@
- Template base
- change about
- Single talk.
- Single talk.
- List profiles
- Chat

View File

@ -20,7 +20,8 @@ class WebsiteConsumer(AsyncWebsocketConsumer):
await self.channel_layer.group_send(
self.room_group_name,
{
"type": "send_page_talks"
"type": "send_page_talks",
"page": 1,
}
)
@ -36,10 +37,14 @@ class WebsiteConsumer(AsyncWebsocketConsumer):
if data["action"] == "page":
# Talks
if data["value"] == "talks":
page = 1
if "page" in data:
page = int(data["page"])
await self.channel_layer.group_send(
self.room_group_name,
{
"type": "send_page_talks"
"type": "send_page_talks",
"page": page,
}
)
# About
@ -53,12 +58,12 @@ class WebsiteConsumer(AsyncWebsocketConsumer):
# Pages
def _get_talks(self):
return page_talks()
def _get_talks(self, page):
return page_talks(page=page)
async def send_page_talks(self, event):
''' Send Home page '''
html = await sync_to_async(self._get_talks)()
html = await sync_to_async(self._get_talks)(event["page"])
await self.send(text_data=html)
def _get_about(self):

View File

@ -17,4 +17,13 @@
</article>
</a>
{% endfor %}
{# Pagination #}
<div class="loading" >
<form>
<input type="hidden" name="action" value="page">
<input type="hidden" name="value" value="talks">
<input type="hidden" name="page" value="{{ next_page }}">
<p hx-ws="send" hx-trigger="click,revealed">Show more</p>
</form>
</div>
</main>

View File

@ -14,9 +14,13 @@ def index(request):
})
def page_talks():
return render_to_string("pages/talks.html", {
"talks": Talk.objects.order_by("title")[:5]
def page_talks(page=1):
TALK_PER_PAGE = 5
return render_to_string("pages/talks.html",
{
"talks": Talk.objects.order_by("title")[:TALK_PER_PAGE * page],
"page": page,
"next_page": page + 1,
})