From 9a7ccb0973c18b812088d2402cc5c04c7257a640 Mon Sep 17 00:00:00 2001 From: Herculino Trotta Date: Mon, 27 Jan 2025 21:49:32 -0300 Subject: [PATCH] feat: add "Clear cache" button to user menu --- app/apps/common/urls.py | 5 +++++ app/apps/common/views.py | 23 ++++++++++++++++++++ app/locale/nl/LC_MESSAGES/django.po | 16 ++++++++++++-- app/locale/pt_BR/LC_MESSAGES/django.po | 14 +++++++++--- app/templates/includes/navbar/user_menu.html | 5 +++++ 5 files changed, 58 insertions(+), 5 deletions(-) diff --git a/app/apps/common/urls.py b/app/apps/common/urls.py index 45f0f1b..77c09c3 100644 --- a/app/apps/common/urls.py +++ b/app/apps/common/urls.py @@ -13,4 +13,9 @@ urlpatterns = [ views.month_year_picker, name="month_year_picker", ), + path( + "cache/invalidate/", + views.invalidate_cache, + name="invalidate_cache", + ), ] diff --git a/app/apps/common/views.py b/app/apps/common/views.py index cd4efd7..172b433 100644 --- a/app/apps/common/views.py +++ b/app/apps/common/views.py @@ -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", + }, + ) diff --git a/app/locale/nl/LC_MESSAGES/django.po b/app/locale/nl/LC_MESSAGES/django.po index 4a6c264..8ba03da 100644 --- a/app/locale/nl/LC_MESSAGES/django.po +++ b/app/locale/nl/LC_MESSAGES/django.po @@ -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" diff --git a/app/locale/pt_BR/LC_MESSAGES/django.po b/app/locale/pt_BR/LC_MESSAGES/django.po index 842b1de..3839aff 100644 --- a/app/locale/pt_BR/LC_MESSAGES/django.po +++ b/app/locale/pt_BR/LC_MESSAGES/django.po @@ -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" diff --git a/app/templates/includes/navbar/user_menu.html b/app/templates/includes/navbar/user_menu.html index ed381b1..4010a85 100644 --- a/app/templates/includes/navbar/user_menu.html +++ b/app/templates/includes/navbar/user_menu.html @@ -33,6 +33,11 @@ {% endspaceless %}
  • +
  • + + {% translate 'Clear cache' %} + +
  • {% translate 'Logout' %}