Add paginator
This commit is contained in:
parent
7f65835db7
commit
b8b101b466
6
TODO
6
TODO
@ -1,3 +1,3 @@
|
||||
- Template base
|
||||
- change about
|
||||
- Single talk.
|
||||
- Single talk.
|
||||
- List profiles
|
||||
- Chat
|
@ -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):
|
||||
|
@ -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>
|
||||
|
@ -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,
|
||||
})
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user