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" %}
{# 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 %}
<h2>{% trans obj=object %}Edit {{ obj }}{% endtrans %}</h2>
{% if object_name %}
<h2>{% trans name=object_name %}Edit {{ name }}{% endtrans %}</h2>
{% else %}
<h2>{% trans %}Save{% endtrans %}</h2>
{% 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">
{% csrf_token %}
{{ form.as_p() }}

View File

@ -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: