2021-11-08 23:32:13 +01:00
|
|
|
from django.shortcuts import render
|
2021-11-12 18:59:01 +01:00
|
|
|
from django.template.loader import render_to_string
|
|
|
|
from random import randint
|
|
|
|
from django.conf import settings
|
2021-11-20 23:55:39 +01:00
|
|
|
from .models import Talk, Profile
|
2021-11-12 18:59:01 +01:00
|
|
|
from asgiref.sync import sync_to_async
|
2021-11-08 23:32:13 +01:00
|
|
|
|
2021-11-12 13:52:41 +01:00
|
|
|
|
|
|
|
def index(request):
|
2021-11-12 18:59:01 +01:00
|
|
|
"""Render layout page"""
|
2021-11-13 09:07:55 +01:00
|
|
|
return render(
|
|
|
|
request,
|
|
|
|
"layouts/base.html",
|
|
|
|
{
|
|
|
|
"room_random": randint(1000000, 9999999),
|
|
|
|
"DOMAIN": settings.DOMAIN,
|
|
|
|
},
|
|
|
|
)
|
2021-11-12 18:59:01 +01:00
|
|
|
|
2021-11-12 20:54:20 +01:00
|
|
|
|
2021-11-12 22:16:42 +01:00
|
|
|
def page_talks(page=1):
|
|
|
|
TALK_PER_PAGE = 5
|
2021-11-20 23:55:39 +01:00
|
|
|
START = TALK_PER_PAGE * (page - 1)
|
|
|
|
END = TALK_PER_PAGE * page
|
2021-11-13 09:07:55 +01:00
|
|
|
return render_to_string(
|
|
|
|
"pages/talks.html",
|
|
|
|
{
|
2021-11-20 23:55:39 +01:00
|
|
|
"talks": Talk.objects.order_by("title")[START:END],
|
2021-11-13 09:07:55 +01:00
|
|
|
"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),
|
|
|
|
},
|
|
|
|
)
|
2021-11-12 18:59:01 +01:00
|
|
|
|
2021-11-21 09:34:54 +01:00
|
|
|
|
2021-11-20 23:55:39 +01:00
|
|
|
def page_profiles():
|
|
|
|
return render_to_string(
|
|
|
|
"pages/profiles.html",
|
|
|
|
{
|
2021-11-21 09:34:54 +01:00
|
|
|
"profiles": Profile.objects.filter(talkspeaker__isnull=False)
|
|
|
|
.order_by("full_name")
|
|
|
|
.distinct()
|
|
|
|
.all(),
|
2021-11-20 23:55:39 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-11-12 18:59:01 +01:00
|
|
|
def page_about():
|
2021-11-13 09:07:55 +01:00
|
|
|
return render_to_string("pages/about.html", {})
|
2021-11-20 20:29:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
def page_results(search):
|
|
|
|
return render_to_string(
|
|
|
|
"pages/talks.html",
|
|
|
|
{
|
2021-11-21 09:34:54 +01:00
|
|
|
"talks": Talk.objects.filter(title__icontains=search.lower()).order_by(
|
|
|
|
"title"
|
|
|
|
),
|
2021-11-20 20:29:44 +01:00
|
|
|
"search": search,
|
|
|
|
},
|
|
|
|
)
|