diff --git a/TODO b/TODO index 0e635c9..0af044b 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,4 @@ -- Single talk. +- Component link with scroll up +- Search - List profiles - Chat \ No newline at end of file diff --git a/app/website/consumers.py b/app/website/consumers.py index 6b6f025..1c3972e 100644 --- a/app/website/consumers.py +++ b/app/website/consumers.py @@ -1,12 +1,12 @@ import json from channels.generic.websocket import AsyncWebsocketConsumer from asgiref.sync import sync_to_async -from .views import page_talks, page_about +from .views import page_talks, page_about, page_single_talk + class WebsiteConsumer(AsyncWebsocketConsumer): - async def connect(self): - '''Connect user''' + """Connect user""" self.room_name = self.scope["url_route"]["kwargs"]["room_id"] self.room_group_name = "root_%s" % self.room_name @@ -22,11 +22,11 @@ class WebsiteConsumer(AsyncWebsocketConsumer): { "type": "send_page_talks", "page": 1, - } + }, ) async def disconnect(self, close_code): - ''' Cliente se desconecta ''' + """Cliente se desconecta""" # Leave room group await self.channel_layer.group_discard(self.room_group_name, self.channel_name) @@ -45,15 +45,20 @@ class WebsiteConsumer(AsyncWebsocketConsumer): { "type": "send_page_talks", "page": page, + }, + ) + # Single talk + if data["value"] == "single-talk": + await self.channel_layer.group_send( + self.room_group_name, { + "type": "send_page_single_talk", + "id": data["id"], } ) # About if data["value"] == "about": await self.channel_layer.group_send( - self.room_group_name, - { - "type": "send_page_about" - } + self.room_group_name, {"type": "send_page_about"} ) # Pages @@ -62,14 +67,22 @@ class WebsiteConsumer(AsyncWebsocketConsumer): return page_talks(page=page) async def send_page_talks(self, event): - ''' Send Home page ''' + """Send Home page""" html = await sync_to_async(self._get_talks)(event["page"]) await self.send(text_data=html) + def _get_single_talk(self, id): + return page_single_talk(id) + + async def send_page_single_talk(self, event): + """Send Single talk page""" + html = await sync_to_async(self._get_single_talk)(event["id"]) + await self.send(text_data=html) + def _get_about(self): return page_about() async def send_page_about(self, event): - ''' Send About page ''' + """Send About page""" html = await sync_to_async(self._get_about)() - await self.send(text_data=html) \ No newline at end of file + await self.send(text_data=html) diff --git a/app/website/routing.py b/app/website/routing.py index a90b7a8..fcc37e1 100644 --- a/app/website/routing.py +++ b/app/website/routing.py @@ -3,5 +3,5 @@ from django.urls import re_path from . import consumers websocket_urlpatterns = [ - re_path(r'ws/pages/(?P\w+)/$', consumers.WebsiteConsumer), -] \ No newline at end of file + re_path(r"ws/pages/(?P\w+)/$", consumers.WebsiteConsumer), +] diff --git a/app/website/templates/pages/talk-single.html b/app/website/templates/pages/talk-single.html new file mode 100644 index 0000000..0a25b51 --- /dev/null +++ b/app/website/templates/pages/talk-single.html @@ -0,0 +1,22 @@ +
+
+
+

+ +

+

{{ talk.title }}

+
+

+ {{ talk.content }} +

+
Author {{ talk.author.full_name }} - {{ talk.category.name }}
+
+

+

+ + + + Back +
+

+
\ No newline at end of file diff --git a/app/website/templates/pages/talks.html b/app/website/templates/pages/talks.html index 5a8e27f..fce3ba0 100644 --- a/app/website/templates/pages/talks.html +++ b/app/website/templates/pages/talks.html @@ -1,21 +1,26 @@
{% for talk in talks %} - -
-
-
-

- -

-

{{ talk.title }}

-
-
-

- {{ talk.content|truncatechars:150 }} -

-
Author {{ talk.author.full_name }} - {{ talk.category.name }}
-
-
+
+ + + + +
+
+
+

+ +

+

{{ talk.title }}

+
+
+

+ {{ talk.content|truncatechars:150 }} +

+
Author {{ talk.author.full_name }} - {{ talk.category.name }}
+
+
+
{% endfor %} {# Pagination #}
diff --git a/app/website/views.py b/app/website/views.py index eb6d614..6ec1bcc 100644 --- a/app/website/views.py +++ b/app/website/views.py @@ -8,21 +8,36 @@ from asgiref.sync import sync_to_async def index(request): """Render layout page""" - return render(request, "layouts/base.html", { - "room_random": randint(1000000, 9999999), - "DOMAIN": settings.DOMAIN, - }) + return render( + request, + "layouts/base.html", + { + "room_random": randint(1000000, 9999999), + "DOMAIN": settings.DOMAIN, + }, + ) 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, - }) + return render_to_string( + "pages/talks.html", + { + "talks": Talk.objects.order_by("title")[: TALK_PER_PAGE * page], + "page": page, + "next_page": page + 1, + }, + ) + + +def page_single_talk(id): + return render_to_string( + "pages/talk-single.html", + { + "talk": Talk.objects.get(id=id), + }, + ) def page_about(): - return render_to_string("pages/about.html", {}) \ No newline at end of file + return render_to_string("pages/about.html", {})