Add profile
This commit is contained in:
parent
cd79957fe6
commit
912cd4eea4
@ -1,7 +1,7 @@
|
||||
import json
|
||||
from channels.generic.websocket import AsyncWebsocketConsumer
|
||||
from asgiref.sync import sync_to_async
|
||||
from .views import page_talks, page_about, page_single_talk, page_results
|
||||
from .views import page_talks, page_about, page_single_talk, page_results, page_profiles
|
||||
|
||||
|
||||
class WebsiteConsumer(AsyncWebsocketConsumer):
|
||||
@ -55,6 +55,12 @@ class WebsiteConsumer(AsyncWebsocketConsumer):
|
||||
"id": data["id"],
|
||||
}
|
||||
)
|
||||
# Profiles
|
||||
if data["value"] == "profiles":
|
||||
await self.channel_layer.group_send(
|
||||
self.room_group_name, {"type": "send_page_profiles"}
|
||||
)
|
||||
|
||||
# About
|
||||
if data["value"] == "about":
|
||||
await self.channel_layer.group_send(
|
||||
@ -72,7 +78,7 @@ class WebsiteConsumer(AsyncWebsocketConsumer):
|
||||
|
||||
# Pages
|
||||
|
||||
def _get_talks(self, page):
|
||||
def _get_talks(self, page=1):
|
||||
return page_talks(page=page)
|
||||
|
||||
async def send_page_talks(self, event):
|
||||
@ -88,6 +94,14 @@ class WebsiteConsumer(AsyncWebsocketConsumer):
|
||||
html = await sync_to_async(self._get_single_talk)(event["id"])
|
||||
await self.send(text_data=html)
|
||||
|
||||
def _get_profiles(self):
|
||||
return page_profiles()
|
||||
|
||||
async def send_page_profiles(self, event):
|
||||
"""Send Profiles page"""
|
||||
html = await sync_to_async(self._get_profiles)()
|
||||
await self.send(text_data=html)
|
||||
|
||||
def _get_about(self):
|
||||
return page_about()
|
||||
|
||||
@ -101,9 +115,8 @@ class WebsiteConsumer(AsyncWebsocketConsumer):
|
||||
|
||||
async def send_page_search(self, event):
|
||||
"""Send results talks"""
|
||||
print(event)
|
||||
if event["search"] != "":
|
||||
html = await sync_to_async(self._get_results)(event["search"])
|
||||
else:
|
||||
html = await sync_to_async(self._get_talks)(event["page"])
|
||||
html = await sync_to_async(self._get_talks)()
|
||||
await self.send(text_data=html)
|
||||
|
19
app/website/migrations/0002_alter_talk_author.py
Normal file
19
app/website/migrations/0002_alter_talk_author.py
Normal file
@ -0,0 +1,19 @@
|
||||
# Generated by Django 3.2.9 on 2021-11-20 22:38
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('website', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='talk',
|
||||
name='author',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='talk_profile', to='website.profile', verbose_name='Autor'),
|
||||
),
|
||||
]
|
@ -48,7 +48,7 @@ class Talk(models.Model):
|
||||
Profile,
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
related_name="author",
|
||||
related_name="talk_profile",
|
||||
verbose_name="Autor",
|
||||
)
|
||||
image = models.ImageField(verbose_name="Imagen", upload_to="uploads/talks/")
|
||||
|
28
app/website/templates/pages/profiles.html
Normal file
28
app/website/templates/pages/profiles.html
Normal file
@ -0,0 +1,28 @@
|
||||
{% load static %}
|
||||
<main id="main" data-scroll-to-top="true">
|
||||
{# List Profiles #}
|
||||
<div style="display: flex; flex-wrap: wrap; justify-content: space-between; ">
|
||||
{% for profile in profiles %}
|
||||
<article style="max-width: 12rem">
|
||||
<header>
|
||||
<h2>
|
||||
{{ profile.full_name }}
|
||||
</h2>
|
||||
<p>
|
||||
<img src="{{ profile.avatar.url }}" alt="{{ profile.full_name }}">
|
||||
</p>
|
||||
</header>
|
||||
<h3>Talks</h3>
|
||||
<ul>
|
||||
{% for talk in profile.talk_profile_set.all %}
|
||||
<li>
|
||||
{{ talk.title }}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<footer>Email: {{ profile.email }}</footer>
|
||||
</article>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{# End List talks #}
|
||||
</main>
|
@ -1,3 +1,4 @@
|
||||
{% load static %}
|
||||
{% load slippers %}
|
||||
<main id="main" data-scroll-to-top="true">
|
||||
|
||||
@ -7,12 +8,11 @@
|
||||
<input type="hidden" name="value" value="search-talks">
|
||||
<label>
|
||||
<input
|
||||
autofocus="autofocus"
|
||||
onfocus="const miVal = this.value; this.value= ''; this.value = miVal"
|
||||
id="search"
|
||||
type="search"
|
||||
name="search"
|
||||
hx-ws="send"
|
||||
hx-trigger="keyup changed delay:1000ms"
|
||||
hx-trigger="keyup changed delay:1s"
|
||||
value="{{ search }}"
|
||||
>
|
||||
</label>
|
||||
@ -20,29 +20,33 @@
|
||||
{# End search #}
|
||||
|
||||
{# List talks #}
|
||||
{% for talk in talks %}
|
||||
<form>
|
||||
<input type="hidden" name="action" value="page">
|
||||
<input type="hidden" name="value" value="single-talk">
|
||||
<input type="hidden" name="id" value="{{ talk.id }}">
|
||||
<a href="#" hx-ws="send" hx-trigger="click">
|
||||
<article>
|
||||
<header>
|
||||
<div class="grid">
|
||||
<p>
|
||||
<img width="200" src="{{ talk.image.url }}">
|
||||
</p>
|
||||
<h2>{{ talk.title }}</h2>
|
||||
</div>
|
||||
</header>
|
||||
<p>
|
||||
{{ talk.content|truncatechars:150 }}
|
||||
</p>
|
||||
<footer>Author {{ talk.author.full_name }} - {{ talk.category.name }}</footer>
|
||||
</article>
|
||||
</a>
|
||||
</form>
|
||||
{% endfor %}
|
||||
{% if talks %}
|
||||
{% for talk in talks %}
|
||||
<form>
|
||||
<input type="hidden" name="action" value="page">
|
||||
<input type="hidden" name="value" value="single-talk">
|
||||
<input type="hidden" name="id" value="{{ talk.id }}">
|
||||
<a href="#" hx-ws="send" hx-trigger="click">
|
||||
<article>
|
||||
<header>
|
||||
<div class="grid">
|
||||
<p>
|
||||
<img width="200" src="{{ talk.image.url }}">
|
||||
</p>
|
||||
<h2>{{ talk.title }}</h2>
|
||||
</div>
|
||||
</header>
|
||||
<p>
|
||||
{{ talk.content|truncatechars:150 }}
|
||||
</p>
|
||||
<footer>Author {{ talk.author.full_name }} - {{ talk.category.name }}</footer>
|
||||
</article>
|
||||
</a>
|
||||
</form>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<h1>No talks found.</h1>
|
||||
{% endif %}
|
||||
{# End List talks #}
|
||||
|
||||
{# Paginator #}
|
||||
@ -54,4 +58,5 @@
|
||||
{% endif %}
|
||||
{# End Paginator #}
|
||||
|
||||
<script src="{% static "js/talks.js" %}"></script>
|
||||
</main>
|
||||
|
@ -2,7 +2,7 @@ from django.shortcuts import render
|
||||
from django.template.loader import render_to_string
|
||||
from random import randint
|
||||
from django.conf import settings
|
||||
from .models import Talk
|
||||
from .models import Talk, Profile
|
||||
from asgiref.sync import sync_to_async
|
||||
|
||||
|
||||
@ -20,10 +20,12 @@ def index(request):
|
||||
|
||||
def page_talks(page=1):
|
||||
TALK_PER_PAGE = 5
|
||||
START = TALK_PER_PAGE * (page - 1)
|
||||
END = TALK_PER_PAGE * page
|
||||
return render_to_string(
|
||||
"pages/talks.html",
|
||||
{
|
||||
"talks": Talk.objects.order_by("title")[: TALK_PER_PAGE * page],
|
||||
"talks": Talk.objects.order_by("title")[START:END],
|
||||
"page": page,
|
||||
"next_page": page + 1,
|
||||
},
|
||||
@ -38,6 +40,15 @@ def page_single_talk(id):
|
||||
},
|
||||
)
|
||||
|
||||
def page_profiles():
|
||||
return render_to_string(
|
||||
"pages/profiles.html",
|
||||
{
|
||||
"profiles": Profile.objects.order_by("full_name"),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
|
||||
def page_about():
|
||||
return render_to_string("pages/about.html", {})
|
||||
|
Loading…
Reference in New Issue
Block a user