From 6bf02cecd9d82284d550b53382a1c7e604537e0d Mon Sep 17 00:00:00 2001 From: imperosol Date: Wed, 12 Feb 2025 16:32:04 +0100 Subject: [PATCH] Allow some customisation in `core/edit.jinja` --- core/templates/core/edit.jinja | 29 +++++++++++++++++++++++++---- core/views/group.py | 9 ++++++--- locale/fr/LC_MESSAGES/django.po | 23 ++++++++++++++++++----- subscription/views.py | 2 ++ 4 files changed, 51 insertions(+), 12 deletions(-) diff --git a/core/templates/core/edit.jinja b/core/templates/core/edit.jinja index 25c6bd74..82c7a035 100644 --- a/core/templates/core/edit.jinja +++ b/core/templates/core/edit.jinja @@ -1,19 +1,40 @@ {% extends "core/base.jinja" %} +{# if the template context has the `object_name` variable, + then this one will be used in the page title, + instead of the result of `str(object)` #} +{% if object and not object_name %} + {% set object_name=object %} +{% endif %} + {% block title %} - {% if object %} - {% trans obj=object %}Edit {{ obj }}{% endtrans %} + {% if object_name %} + {% trans name=object_name %}Edit {{ name }}{% endtrans %} {% else %} {% trans %}Save{% endtrans %} {% endif %} {% endblock %} {% block content %} - {% if object %} -

{% trans obj=object %}Edit {{ obj }}{% endtrans %}

+ {% if object_name %} +

{% trans name=object_name %}Edit {{ name }}{% endtrans %}

{% else %}

{% trans %}Save{% endtrans %}

{% endif %} + {% if messages %} +
+ + {% for message in messages %} + {% if message.level_tag == "success" %} + {{ message }} + {% endif %} + {% endfor %} + + + + +
+ {% endif %}
{% csrf_token %} {{ form.as_p() }} diff --git a/core/views/group.py b/core/views/group.py index 017b550f..ba6b406d 100644 --- a/core/views/group.py +++ b/core/views/group.py @@ -18,6 +18,7 @@ from django import forms from django.contrib.auth.mixins import PermissionRequiredMixin from django.contrib.auth.models import Permission +from django.contrib.messages.views import SuccessMessageMixin from django.core.exceptions import ImproperlyConfigured from django.shortcuts import get_object_or_404 from django.urls import reverse_lazy @@ -136,7 +137,9 @@ class GroupDeleteView(CanEditMixin, DeleteView): success_url = reverse_lazy("core:group_list") -class PermissionGroupsUpdateView(PermissionRequiredMixin, UpdateView): +class PermissionGroupsUpdateView( + PermissionRequiredMixin, SuccessMessageMixin, UpdateView +): """Manage the groups that have a specific permission. Notes: @@ -151,9 +154,8 @@ class PermissionGroupsUpdateView(PermissionRequiredMixin, UpdateView): Example: ```python - class AddSubscriptionGroupsView(PermissionGroupsUpdateView): + class SubscriptionPermissionView(PermissionGroupsUpdateView): permission = "subscription.add_subscription" - success_url = reverse_lazy("foo:bar") ``` """ @@ -161,6 +163,7 @@ class PermissionGroupsUpdateView(PermissionRequiredMixin, UpdateView): template_name = "core/edit.jinja" form_class = PermissionGroupsForm permission = None + success_message = _("Groups have been successfully updated.") def get_object(self, *args, **kwargs): if not self.permission: diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index 3f881bd0..0cfef902 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-02-12 15:32+0100\n" +"POT-Creation-Date: 2025-02-12 15:55+0100\n" "PO-Revision-Date: 2016-07-18\n" "Last-Translator: Maréchal \n" @@ -2383,11 +2383,10 @@ msgstr "Confirmation" msgid "Cancel" msgstr "Annuler" -#: core/templates/core/edit.jinja core/templates/core/file_edit.jinja -#: counter/templates/counter/cash_register_summary.jinja +#: core/templates/core/edit.jinja #, python-format -msgid "Edit %(obj)s" -msgstr "Éditer %(obj)s" +msgid "Edit %(name)s" +msgstr "Éditer %(name)s" #: core/templates/core/file.jinja core/templates/core/file_list.jinja msgid "File list" @@ -2457,6 +2456,12 @@ msgstr "octets" msgid "Download" msgstr "Télécharger" +#: core/templates/core/file_edit.jinja +#: counter/templates/counter/cash_register_summary.jinja +#, python-format +msgid "Edit %(obj)s" +msgstr "Éditer %(obj)s" + #: core/templates/core/file_list.jinja msgid "There is no file in this website." msgstr "Il n'y a pas de fichier sur ce site web." @@ -3359,6 +3364,10 @@ msgstr "Utilisateurs à ajouter au groupe" msgid "Users to remove from group" msgstr "Utilisateurs à retirer du groupe" +#: core/views/group.py +msgid "Groups have been successfully updated." +msgstr "Les groupes ont été mis à jour avec succès." + #: core/views/user.py msgid "We couldn't verify that this email actually exists" msgstr "Nous n'avons pas réussi à vérifier que cette adresse mail existe." @@ -5680,6 +5689,10 @@ msgstr "Cotisations par type" msgid "Existing member" msgstr "Membre existant" +#: subscription/views.py +msgid "the groups that can create subscriptions" +msgstr "les groupes pouvant créer des cotisations" + #: trombi/models.py msgid "subscription deadline" msgstr "fin des inscriptions" diff --git a/subscription/views.py b/subscription/views.py index 5e5d9420..d5f9d75d 100644 --- a/subscription/views.py +++ b/subscription/views.py @@ -18,6 +18,7 @@ from django.contrib.auth.mixins import PermissionRequiredMixin from django.core.exceptions import PermissionDenied from django.urls import reverse, reverse_lazy from django.utils.timezone import localdate +from django.utils.translation import gettext_lazy as _ from django.views.generic import CreateView, DetailView, TemplateView from django.views.generic.edit import FormView @@ -82,6 +83,7 @@ class SubscriptionPermissionView(PermissionGroupsUpdateView): """Manage the groups that have access to the subscription creation page.""" permission = "subscription.add_subscription" + extra_context = {"object_name": _("the groups that can create subscriptions")} class SubscriptionsStatsView(FormView):