optimise post show view
This commit is contained in:
@@ -16,6 +16,7 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
|
|
||||||
from core.models import CustomFlatPage
|
from core.models import CustomFlatPage
|
||||||
from documents import create_pad, get_pad_html, set_pad_html
|
from documents import create_pad, get_pad_html, set_pad_html
|
||||||
|
from documents.api import get_pad_link
|
||||||
from .managers import (
|
from .managers import (
|
||||||
PostManager,
|
PostManager,
|
||||||
ArticleManager,
|
ArticleManager,
|
||||||
@@ -198,6 +199,38 @@ class Post(models.Model):
|
|||||||
)
|
)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def agenda_link(self):
|
||||||
|
agenda_link = "#"
|
||||||
|
if self.has_agenda:
|
||||||
|
agenda_link = get_pad_link(self.agenda_key)
|
||||||
|
|
||||||
|
return agenda_link
|
||||||
|
|
||||||
|
@property
|
||||||
|
def protocol_link(self):
|
||||||
|
protocol_link = "#"
|
||||||
|
if self.has_protocol:
|
||||||
|
protocol_link = get_pad_link(self.protocol_key)
|
||||||
|
|
||||||
|
return protocol_link
|
||||||
|
|
||||||
|
@property
|
||||||
|
def filename_agenda(self):
|
||||||
|
filename_agenda = None
|
||||||
|
if self.has_agenda and self.agenda_link != "#":
|
||||||
|
filename_agenda = self.slug + "-agenda.pdf"
|
||||||
|
|
||||||
|
return filename_agenda
|
||||||
|
|
||||||
|
@property
|
||||||
|
def filename_protocol(self):
|
||||||
|
filename_protocol = None
|
||||||
|
if self.has_agenda and self.protocol_link != "#":
|
||||||
|
filename_protocol = self.slug + "-protokoll.pdf"
|
||||||
|
|
||||||
|
return filename_protocol
|
||||||
|
|
||||||
def get_agenda_key(self):
|
def get_agenda_key(self):
|
||||||
"""
|
"""
|
||||||
Create a Etherpad Id for the Pad associated to this post.
|
Create a Etherpad Id for the Pad associated to this post.
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ from django.template.loader import render_to_string
|
|||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
from authentications.decorators import authenticated_user
|
from authentications.decorators import authenticated_user
|
||||||
from documents.api import get_pad_link
|
|
||||||
from documents.etherpadlib import add_ep_cookie
|
from documents.etherpadlib import add_ep_cookie
|
||||||
from members.models import Member
|
from members.models import Member
|
||||||
from .forms import PostSearchForm
|
from .forms import PostSearchForm
|
||||||
@@ -119,25 +118,6 @@ def show(request, id=None):
|
|||||||
author = post_author
|
author = post_author
|
||||||
author_image = post_author.image["avatar"].url
|
author_image = post_author.image["avatar"].url
|
||||||
|
|
||||||
# etherpad links for agenda and protocol
|
|
||||||
ep_agenda_link = "#"
|
|
||||||
ep_protocol_link = "#"
|
|
||||||
# set filename for pdf, not a nice solution
|
|
||||||
filename_agenda = None
|
|
||||||
filename_protocol = None
|
|
||||||
|
|
||||||
if post.has_agenda:
|
|
||||||
ep_agenda_link = get_pad_link(post.agenda_key)
|
|
||||||
|
|
||||||
if ep_agenda_link != "#":
|
|
||||||
filename_agenda = post.slug + "-agenda.pdf"
|
|
||||||
|
|
||||||
if post.has_protocol:
|
|
||||||
ep_protocol_link = get_pad_link(post.protocol_key)
|
|
||||||
|
|
||||||
if ep_protocol_link != "#":
|
|
||||||
filename_protocol = post.slug + "-protokoll.pdf"
|
|
||||||
|
|
||||||
related_posts = post.tags.similar_objects()
|
related_posts = post.tags.similar_objects()
|
||||||
# list of non 'is_hidden' posts for related_posts
|
# list of non 'is_hidden' posts for related_posts
|
||||||
for obj in related_posts:
|
for obj in related_posts:
|
||||||
@@ -152,16 +132,12 @@ def show(request, id=None):
|
|||||||
"next": __next(post, public_only),
|
"next": __next(post, public_only),
|
||||||
"previous": __previous(post, public_only),
|
"previous": __previous(post, public_only),
|
||||||
"related_posts": related_posts[:4],
|
"related_posts": related_posts[:4],
|
||||||
"ep_agenda_link": ep_agenda_link,
|
|
||||||
"ep_protocol_link": ep_protocol_link,
|
|
||||||
"filename_agenda": filename_agenda,
|
|
||||||
"filename_protocol": filename_protocol,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
response = render(request, "posts/show.html", context)
|
response = render(request, "posts/show.html", context)
|
||||||
|
|
||||||
# check if etherpad server works
|
# check if etherpad server works
|
||||||
if ep_agenda_link or ep_protocol_link:
|
if post.agenda_link or post.protocol_link:
|
||||||
try:
|
try:
|
||||||
response = add_ep_cookie(request, response)
|
response = add_ep_cookie(request, response)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -205,12 +205,12 @@
|
|||||||
x-transition:leave-end="transform origin-right opacity-0 scale-95"
|
x-transition:leave-end="transform origin-right opacity-0 scale-95"
|
||||||
>
|
>
|
||||||
<li class="block sm:inline-block group hover:bg-gray-100 dark:hover:bg-gray-800 hover:text-gray-800 dark:hover:text-gray-200">
|
<li class="block sm:inline-block group hover:bg-gray-100 dark:hover:bg-gray-800 hover:text-gray-800 dark:hover:text-gray-200">
|
||||||
<a href="{{ ep_agenda_link }}" class="inline-flex items-center px-2 py-1">
|
<a href="{{ post.agenda_link }}" class="inline-flex items-center px-2 py-1">
|
||||||
<i class="fa-solid fa-file-signature fa-fw text-proprietary dark:text-proprietary-light md:text-inherit group-hover:text-proprietary dark:group-hover:text-proprietary-light"></i>
|
<i class="fa-solid fa-file-signature fa-fw text-proprietary dark:text-proprietary-light md:text-inherit group-hover:text-proprietary dark:group-hover:text-proprietary-light"></i>
|
||||||
<span class="ml-2 sm:ml-1">Bearbeiten</span>
|
<span class="ml-2 sm:ml-1">Bearbeiten</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{% if filename_agenda %}
|
{% if post.filename_agenda %}
|
||||||
<li class="block sm:inline-block group hover:bg-gray-200 dark:hover:bg-gray-800 hover:text-gray-800 dark:hover:text-gray-200">
|
<li class="block sm:inline-block group hover:bg-gray-200 dark:hover:bg-gray-800 hover:text-gray-800 dark:hover:text-gray-200">
|
||||||
<a href="{% url 'posts:show_pdf_agenda' post.slug %}" class="inline-flex items-center px-2 py-1">
|
<a href="{% url 'posts:show_pdf_agenda' post.slug %}" class="inline-flex items-center px-2 py-1">
|
||||||
<i class="fa-solid fa-file-pdf fa-fw text-red-800 dark:text-red-500 md:text-inherit group-hover:text-red-800 dark:group-hover:text-red-500"></i>
|
<i class="fa-solid fa-file-pdf fa-fw text-red-800 dark:text-red-500 md:text-inherit group-hover:text-red-800 dark:group-hover:text-red-500"></i>
|
||||||
@@ -241,11 +241,11 @@
|
|||||||
x-transition:leave-end="transform origin-right opacity-0 scale-95"
|
x-transition:leave-end="transform origin-right opacity-0 scale-95"
|
||||||
>
|
>
|
||||||
<li class="block sm:inline-block group hover:bg-gray-100 dark:hover:bg-gray-800 hover:text-gray-800 dark:hover:text-gray-200">
|
<li class="block sm:inline-block group hover:bg-gray-100 dark:hover:bg-gray-800 hover:text-gray-800 dark:hover:text-gray-200">
|
||||||
<a href="{{ ep_protocol_link }}" class="inline-flex items-center px-2 py-1"><i class="fa-solid fa-file-signature fa-fw text-proprietary dark:text-proprietary-light md:text-inherit group-hover:text-proprietary dark:group-hover:text-proprietary-light"></i>
|
<a href="{{ post.protocol_link }}" class="inline-flex items-center px-2 py-1"><i class="fa-solid fa-file-signature fa-fw text-proprietary dark:text-proprietary-light md:text-inherit group-hover:text-proprietary dark:group-hover:text-proprietary-light"></i>
|
||||||
<span class="ml-2 sm:ml-1">Bearbeiten</span>
|
<span class="ml-2 sm:ml-1">Bearbeiten</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{% if filename_protocol %}
|
{% if post.filename_protocol %}
|
||||||
<li class="block sm:inline-block group hover:bg-gray-200 dark:hover:bg-gray-800 hover:text-gray-800 dark:hover:text-gray-200">
|
<li class="block sm:inline-block group hover:bg-gray-200 dark:hover:bg-gray-800 hover:text-gray-800 dark:hover:text-gray-200">
|
||||||
<a href="{% url 'posts:show_pdf_protocol' post.slug %}" class="inline-flex items-center px-2 py-1">
|
<a href="{% url 'posts:show_pdf_protocol' post.slug %}" class="inline-flex items-center px-2 py-1">
|
||||||
<i class="fa-solid fa-file-pdf fa-fw text-red-800 dark:text-red-500 md:text-inherit group-hover:text-red-800 dark:group-hover:text-red-500"></i>
|
<i class="fa-solid fa-file-pdf fa-fw text-red-800 dark:text-red-500 md:text-inherit group-hover:text-red-800 dark:group-hover:text-red-500"></i>
|
||||||
|
|||||||
Reference in New Issue
Block a user