Merge pull request #1193 from ae-utbm/optimize-jinja

Optimisations
This commit is contained in:
thomas girod
2025-10-02 19:05:03 +02:00
committed by GitHub
4 changed files with 46 additions and 42 deletions

View File

@@ -76,18 +76,20 @@
It will stay hidden for other users until it has been published. It will stay hidden for other users until it has been published.
{% endtrans %} {% endtrans %}
</p> </p>
{% if user.has_perm("com.moderate_news") %} {%- if user.has_perm("com.moderate_news") -%}
{# This is an additional query for each non-moderated news, {# This is an additional query for each non-moderated news,
but it will be executed only for admin users, and only one time but it will be executed only for admin users, and only one time
(if they do their job and moderated news as soon as they see them), (if they do their job and moderate news as soon as they see them),
so it's still reasonable #} so it's still reasonable #}
<div <div
{% if news is integer or news is string %} {% if news is integer or news is string -%}
x-data="{ nbEvents: 0 }" x-data="{ nbEvents: 0 }"
x-init="nbEvents = await nbToPublish()" x-init="nbEvents = await nbToPublish()"
{% else %} {%- elif news.is_published -%}
x-data="{ nbEvents: 0 }"
{%- else -%}
x-data="{ nbEvents: {{ news.dates.count() }} }" x-data="{ nbEvents: {{ news.dates.count() }} }"
{% endif %} {%- endif -%}
> >
<template x-if="nbEvents > 1"> <template x-if="nbEvents > 1">
<div> <div>

View File

@@ -77,22 +77,22 @@
<div class="notification" x-data="{display: false}" :class="{white: display}"> <div class="notification" x-data="{display: false}" :class="{white: display}">
<a href="#" @click.prevent="display = !display"> <a href="#" @click.prevent="display = !display">
<i :class="`fa-${display ? 'solid': 'regular'} fa-bell`" x-transition></i> <i :class="`fa-${display ? 'solid': 'regular'} fa-bell`" x-transition></i>
{% set notification_count = user.notifications.filter(viewed=False).count() %} {% set notifications = user.notifications.filter(viewed=False).order_by("-date")|list %}
{% if notification_count > 0 %} {%- if notifications|length > 0 -%}
<span> <span>
{% if notification_count < 100 %} {% if notifications|length < 100 %}
{{ notification_count }} {{ notifications|length }}
{% else %} {%- else -%}
&nbsp; 99+
{% endif %} {%- endif -%}
</span> </span>
{% endif %} {% endif %}
</a> </a>
<div id="header_notif" x-show="display" x-cloak x-transition @click.outside="display = false"> <div id="header_notif" x-show="display" x-cloak x-transition @click.outside="display = false">
<ul> <ul>
{% if user.notifications.filter(viewed=False).count() > 0 %} {%- if notifications|length > 0 -%}
{% for n in user.notifications.filter(viewed=False).order_by('-date') %} {%- for n in notifications -%}
<li> <li>
<a href="{{ url("core:notification", notif_id=n.id) }}"> <a href="{{ url("core:notification", notif_id=n.id) }}">
<div class="datetime"> <div class="datetime">
@@ -108,10 +108,10 @@
</div> </div>
</a> </a>
</li> </li>
{% endfor %} {%- endfor -%}
{% else %} {%- else -%}
<li class="empty-notification">{% trans %}You do not have any unread notification{% endtrans %}</li> <li class="empty-notification">{% trans %}You do not have any unread notification{% endtrans %}</li>
{% endif %} {%- endif -%}
</ul> </ul>
<div class="options"> <div class="options">
<a href="{{ url('core:notification_list') }}"> <a href="{{ url('core:notification_list') }}">

View File

@@ -1,3 +1,4 @@
{% spaceless %}
{% for js in statics.js %} {% for js in statics.js %}
<script-once type="module" src="{{ js }}"></script-once> <script-once type="module" src="{{ js }}"></script-once>
{% endfor %} {% endfor %}
@@ -21,3 +22,4 @@
<slot style="display:none" name="initial">{{ initial }}</slot> <slot style="display:none" name="initial">{{ initial }}</slot>
{% endif %} {% endif %}
</{{ component }}> </{{ component }}>
{% endspaceless %}

View File

@@ -67,13 +67,13 @@
<option value="FIN">{% trans %}Confirm (FIN){% endtrans %}</option> <option value="FIN">{% trans %}Confirm (FIN){% endtrans %}</option>
<option value="ANN">{% trans %}Cancel (ANN){% endtrans %}</option> <option value="ANN">{% trans %}Cancel (ANN){% endtrans %}</option>
</optgroup> </optgroup>
{% for category in categories.keys() %} {%- for category in categories.keys() -%}
<optgroup label="{{ category }}"> <optgroup label="{{ category }}">
{% for product in categories[category] %} {%- for product in categories[category] -%}
<option value="{{ product.id }}">{{ product }}</option> <option value="{{ product.id }}">{{ product }}</option>
{% endfor %} {%- endfor -%}
</optgroup> </optgroup>
{% endfor %} {%- endfor -%}
</counter-product-select> </counter-product-select>
<input type="submit" value="{% trans %}Go{% endtrans %}"/> <input type="submit" value="{% trans %}Go{% endtrans %}"/>