feat: add "Clear cache" button to user menu

This commit is contained in:
Herculino Trotta
2025-01-27 21:49:32 -03:00
parent 233b9629a2
commit 9a7ccb0973
5 changed files with 58 additions and 5 deletions

View File

@@ -13,4 +13,9 @@ urlpatterns = [
views.month_year_picker,
name="month_year_picker",
),
path(
"cache/invalidate/",
views.invalidate_cache,
name="invalidate_cache",
),
]

View File

@@ -1,10 +1,17 @@
from dateutil.relativedelta import relativedelta
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.db.models import Count
from django.db.models.functions import ExtractYear, ExtractMonth
from django.http import HttpResponse
from django.shortcuts import render
from django.urls import reverse
from django.utils import timezone
from django.views.decorators.http import require_http_methods
from django.utils.translation import gettext_lazy as _
from cachalot.api import invalidate
from apps.common.decorators.htmx import only_htmx
from apps.transactions.models import Transaction
@@ -92,3 +99,19 @@ def month_year_picker(request):
"current_year": current_year,
},
)
@only_htmx
@login_required
@require_http_methods(["GET"])
def invalidate_cache(request):
invalidate()
messages.success(request, _("Cache cleared successfully"))
return HttpResponse(
status=204,
headers={
"HX-Trigger": "updated",
},
)

View File

@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-01-27 16:26+0000\n"
"POT-Creation-Date: 2025-01-28 00:49+0000\n"
"PO-Revision-Date: 2025-01-27 13:27-0300\n"
"Last-Translator: Herculino Trotta\n"
"Language-Team: \n"
@@ -322,6 +322,12 @@ msgstr "Fout"
msgid "Info"
msgstr "Info"
#: apps/common/views.py:110
#, fuzzy
#| msgid "Category updated successfully"
msgid "Cache cleared successfully"
msgstr "Categorie succesvol bijgewerkt"
#: apps/common/widgets/datepicker.py:47 apps/common/widgets/datepicker.py:186
msgid "Today"
msgstr "Vandaag"
@@ -1899,7 +1905,13 @@ msgstr "Rekenmachine"
msgid "Settings"
msgstr "Instellingen"
#: templates/includes/navbar/user_menu.html:37
#: templates/includes/navbar/user_menu.html:38
#, fuzzy
#| msgid "Clear"
msgid "Clear cache"
msgstr "Leegmaken"
#: templates/includes/navbar/user_menu.html:42
msgid "Logout"
msgstr "Uitloggen"

View File

@@ -8,8 +8,8 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-01-27 16:26+0000\n"
"PO-Revision-Date: 2025-01-27 13:27-0300\n"
"POT-Creation-Date: 2025-01-28 00:49+0000\n"
"PO-Revision-Date: 2025-01-27 21:49-0300\n"
"Last-Translator: Herculino Trotta\n"
"Language-Team: \n"
"Language: pt_BR\n"
@@ -320,6 +320,10 @@ msgstr "Erro"
msgid "Info"
msgstr "Informação"
#: apps/common/views.py:110
msgid "Cache cleared successfully"
msgstr "Cache limpo com sucesso"
#: apps/common/widgets/datepicker.py:47 apps/common/widgets/datepicker.py:186
msgid "Today"
msgstr "Hoje"
@@ -1898,7 +1902,11 @@ msgstr "Calculadora"
msgid "Settings"
msgstr "Configurações"
#: templates/includes/navbar/user_menu.html:37
#: templates/includes/navbar/user_menu.html:38
msgid "Clear cache"
msgstr "Limpar cache"
#: templates/includes/navbar/user_menu.html:42
msgid "Logout"
msgstr "Sair"

View File

@@ -33,6 +33,11 @@
</li>
{% endspaceless %}
<li><hr class="dropdown-divider"></li>
<li>
<a class="dropdown-item" hx-get="{% url 'invalidate_cache' %}" role="button">
<i class="fa-solid fa-broom me-2 fa-fw"></i>{% translate 'Clear cache' %}
</a>
</li>
<li><a class="dropdown-item" href="{% url 'logout' %}"><i class="fa-solid fa-door-open me-2 fa-fw"></i
>{% translate 'Logout' %}</a></li>
</ul>