Merge branch 'performances' into 'master'

Improve performances on forum and SAS

See merge request ae/Sith!235
This commit is contained in:
2019-09-16 14:23:52 +02:00
7 changed files with 48 additions and 24 deletions

View File

@ -114,22 +114,24 @@
{% endmacro %}
{% macro paginate(page_obj, paginator) %}
{% if page_obj.has_previous() or page_obj.has_next() %}
{% if page_obj.has_previous() %}
<a href="?page={{ page_obj.previous_page_number() }}">{% trans %}Previous{% endtrans %}</a>
{% else %}
<span class="disabled">{% trans %}Previous{% endtrans %}</span>
{% endif %}
{% for i in paginator.page_range %}
{% if page_obj.number == i %}
<span class="active">{{ i }} <span class="sr-only">({% trans %}current{% endtrans %})</span></span>
{% for i in paginator.page_range %}
{% if page_obj.number == i %}
<span class="active">{{ i }} <span class="sr-only">({% trans %}current{% endtrans %})</span></span>
{% else %}
<a href="?page={{ i }}">{{ i }}</a>
{% endif %}
{% endfor %}
{% if page_obj.has_next() %}
<a href="?page={{ page_obj.next_page_number() }}">{% trans %}Next{% endtrans %}</a>
{% else %}
<a href="?page={{ i }}">{{ i }}</a>
<span class="disabled">{% trans %}Next{% endtrans %}</span>
{% endif %}
{% endfor %}
{% if page_obj.has_next() %}
<a href="?page={{ page_obj.next_page_number() }}">{% trans %}Next{% endtrans %}</a>
{% else %}
<span class="disabled">{% trans %}Next{% endtrans %}</span>
{% endif %}
{% endmacro %}

View File

@ -23,7 +23,7 @@
#
# This file contains all the views that concern the page model
from django.shortcuts import redirect
from django.shortcuts import redirect, get_object_or_404
from django.views.generic import ListView, DetailView, TemplateView
from django.views.generic.edit import UpdateView, FormMixin, DeleteView
from django.views.generic.detail import SingleObjectMixin
@ -51,9 +51,7 @@ def send_file(request, file_id, file_class=SithFile, file_attr="file"):
memory at once. The FileWrapper will turn the file object into an
iterator for chunks of 8KB.
"""
f = file_class.objects.filter(id=file_id).first()
if f is None or not f.file:
return not_found(request)
f = get_object_or_404(file_class, id=file_id)
if not (
can_view(f, request.user)
or (