Allow some customisation in core/edit.jinja

This commit is contained in:
imperosol 2025-02-12 16:32:04 +01:00
parent 05d4a09f8c
commit 6bf02cecd9
4 changed files with 51 additions and 12 deletions

View File

@ -1,19 +1,40 @@
{% extends "core/base.jinja" %} {% 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 %} {% block title %}
{% if object %} {% if object_name %}
{% trans obj=object %}Edit {{ obj }}{% endtrans %} {% trans name=object_name %}Edit {{ name }}{% endtrans %}
{% else %} {% else %}
{% trans %}Save{% endtrans %} {% trans %}Save{% endtrans %}
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block content %} {% block content %}
{% if object %} {% if object_name %}
<h2>{% trans obj=object %}Edit {{ obj }}{% endtrans %}</h2> <h2>{% trans name=object_name %}Edit {{ name }}{% endtrans %}</h2>
{% else %} {% else %}
<h2>{% trans %}Save{% endtrans %}</h2> <h2>{% trans %}Save{% endtrans %}</h2>
{% endif %} {% endif %}
{% if messages %}
<div x-data="{show_alert: true}" class="alert alert-green" x-show="show_alert" x-transition>
<span class="alert-main">
{% for message in messages %}
{% if message.level_tag == "success" %}
{{ message }}
{% endif %}
{% endfor %}
</span>
<span class="clickable" @click="show_alert = false">
<i class="fa fa-close"></i>
</span>
</div>
{% endif %}
<form action="" method="post" enctype="multipart/form-data"> <form action="" method="post" enctype="multipart/form-data">
{% csrf_token %} {% csrf_token %}
{{ form.as_p() }} {{ form.as_p() }}

View File

@ -18,6 +18,7 @@
from django import forms from django import forms
from django.contrib.auth.mixins import PermissionRequiredMixin from django.contrib.auth.mixins import PermissionRequiredMixin
from django.contrib.auth.models import Permission from django.contrib.auth.models import Permission
from django.contrib.messages.views import SuccessMessageMixin
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.urls import reverse_lazy from django.urls import reverse_lazy
@ -136,7 +137,9 @@ class GroupDeleteView(CanEditMixin, DeleteView):
success_url = reverse_lazy("core:group_list") success_url = reverse_lazy("core:group_list")
class PermissionGroupsUpdateView(PermissionRequiredMixin, UpdateView): class PermissionGroupsUpdateView(
PermissionRequiredMixin, SuccessMessageMixin, UpdateView
):
"""Manage the groups that have a specific permission. """Manage the groups that have a specific permission.
Notes: Notes:
@ -151,9 +154,8 @@ class PermissionGroupsUpdateView(PermissionRequiredMixin, UpdateView):
Example: Example:
```python ```python
class AddSubscriptionGroupsView(PermissionGroupsUpdateView): class SubscriptionPermissionView(PermissionGroupsUpdateView):
permission = "subscription.add_subscription" permission = "subscription.add_subscription"
success_url = reverse_lazy("foo:bar")
``` ```
""" """
@ -161,6 +163,7 @@ class PermissionGroupsUpdateView(PermissionRequiredMixin, UpdateView):
template_name = "core/edit.jinja" template_name = "core/edit.jinja"
form_class = PermissionGroupsForm form_class = PermissionGroupsForm
permission = None permission = None
success_message = _("Groups have been successfully updated.")
def get_object(self, *args, **kwargs): def get_object(self, *args, **kwargs):
if not self.permission: if not self.permission:

View File

@ -6,7 +6,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Report-Msgid-Bugs-To: \n" "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" "PO-Revision-Date: 2016-07-18\n"
"Last-Translator: Maréchal <thomas.girod@utbm.fr\n" "Last-Translator: Maréchal <thomas.girod@utbm.fr\n"
"Language-Team: AE info <ae.info@utbm.fr>\n" "Language-Team: AE info <ae.info@utbm.fr>\n"
@ -2383,11 +2383,10 @@ msgstr "Confirmation"
msgid "Cancel" msgid "Cancel"
msgstr "Annuler" msgstr "Annuler"
#: core/templates/core/edit.jinja core/templates/core/file_edit.jinja #: core/templates/core/edit.jinja
#: counter/templates/counter/cash_register_summary.jinja
#, python-format #, python-format
msgid "Edit %(obj)s" msgid "Edit %(name)s"
msgstr "Éditer %(obj)s" msgstr "Éditer %(name)s"
#: core/templates/core/file.jinja core/templates/core/file_list.jinja #: core/templates/core/file.jinja core/templates/core/file_list.jinja
msgid "File list" msgid "File list"
@ -2457,6 +2456,12 @@ msgstr "octets"
msgid "Download" msgid "Download"
msgstr "Télécharger" 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 #: core/templates/core/file_list.jinja
msgid "There is no file in this website." msgid "There is no file in this website."
msgstr "Il n'y a pas de fichier sur ce site web." 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" msgid "Users to remove from group"
msgstr "Utilisateurs à retirer du groupe" 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 #: core/views/user.py
msgid "We couldn't verify that this email actually exists" msgid "We couldn't verify that this email actually exists"
msgstr "Nous n'avons pas réussi à vérifier que cette adresse mail existe." 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" msgid "Existing member"
msgstr "Membre existant" msgstr "Membre existant"
#: subscription/views.py
msgid "the groups that can create subscriptions"
msgstr "les groupes pouvant créer des cotisations"
#: trombi/models.py #: trombi/models.py
msgid "subscription deadline" msgid "subscription deadline"
msgstr "fin des inscriptions" msgstr "fin des inscriptions"

View File

@ -18,6 +18,7 @@ from django.contrib.auth.mixins import PermissionRequiredMixin
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from django.urls import reverse, reverse_lazy from django.urls import reverse, reverse_lazy
from django.utils.timezone import localdate 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 import CreateView, DetailView, TemplateView
from django.views.generic.edit import FormView 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.""" """Manage the groups that have access to the subscription creation page."""
permission = "subscription.add_subscription" permission = "subscription.add_subscription"
extra_context = {"object_name": _("the groups that can create subscriptions")}
class SubscriptionsStatsView(FormView): class SubscriptionsStatsView(FormView):