Source code for ferrosoft.apps.ferrobase.views.group

#  Copyright (c) 2025 Ferrosoft GmbH. All rights reserved.
"""Views for group management. Groups are used in the Django permission system."""

from django.contrib.auth.models import Group
from django.urls import reverse
from django.utils.translation import gettext_lazy as _

from ferrosoft.apps.ferrobase.forms import GroupPermissionsForm
from ferrosoft.apps.ferrobase.views.generic import (
    CreateView,
    UpdateView,
    DeleteView,
    ListView,
    model_crud_routes,
)


[docs] class GroupListView(ListView): """List Django auth groups ordered by name.""" activity_app = "ferrobase" model = Group ordering = "name"
[docs] class GroupCreateView(CreateView): """Create an auth group; redirects to the update view on success.""" activity_app = "ferrobase" fields = ["name"] model = Group
[docs] def get_success_url(self): """Send the user to the freshly-created group's update page.""" return reverse("ferrobase:group_update", args=[self.object.pk])
[docs] class GroupUpdateView(UpdateView): """Rename an auth group.""" activity_app = "ferrobase" fields = ["name"] model = Group template_name = "ferrobase/group/update.html"
[docs] def get_success_url(self): """Stay on the same group's update page after a successful save.""" return reverse("ferrobase:group_update", args=[self.object.pk])
[docs] class GroupDeleteView(DeleteView): """Delete an auth group.""" activity_app = "ferrobase" model = Group
[docs] def get_success_url(self): """Return to the group list after deletion.""" return reverse("ferrobase:group_index")
group_urls = model_crud_routes( Group, create_view=GroupCreateView, read_view=GroupListView, update_view=GroupUpdateView, delete_view=GroupDeleteView, )
[docs] class GroupPermissionsView(UpdateView): """Manage the permission set attached to an auth group.""" activity_app = "ferrobase" activity_title = _("Group permissions") form_class = GroupPermissionsForm model = Group
[docs] def get_success_url(self): """Return to the group's update view after saving permissions.""" return reverse("ferrobase:group_update", args=[self.object.pk])