From ca3bf0f296db9430eb52a58624ecbb1c2022e9f9 Mon Sep 17 00:00:00 2001 From: Jan Remmer Siebels Date: Sun, 5 Oct 2025 23:03:56 +0200 Subject: [PATCH] fix: Use bound fields in rights management system - Replace raw field objects with bound fields in get_permission_groups() - Bound fields render properly as HTML checkboxes in templates - Fixes display of Django field object strings instead of actual form inputs - Rights management system now shows proper checkboxes with permission names --- app/stiftung/forms.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/stiftung/forms.py b/app/stiftung/forms.py index 757ebae..97b0a28 100644 --- a/app/stiftung/forms.py +++ b/app/stiftung/forms.py @@ -1348,6 +1348,9 @@ class UserPermissionForm(forms.Form): permission = Permission.objects.get(id=perm_id) label = permission.name.lower() codename = permission.codename.lower() + + # Get bound field for proper template rendering + bound_field = self[field_name] # More precise categorization based on both name and codename if ( @@ -1365,7 +1368,7 @@ class UserPermissionForm(forms.Form): or "view_" in codename ): groups["entities"]["permissions"].append( - (field_name, field, permission) + (field_name, bound_field, permission) ) elif ( any( @@ -1374,7 +1377,7 @@ class UserPermissionForm(forms.Form): or "dokument" in label ): groups["documents"]["permissions"].append( - (field_name, field, permission) + (field_name, bound_field, permission) ) elif any( word in codename @@ -1394,7 +1397,7 @@ class UserPermissionForm(forms.Form): ] ): groups["financial"]["permissions"].append( - (field_name, field, permission) + (field_name, bound_field, permission) ) elif any( word in codename @@ -1416,11 +1419,11 @@ class UserPermissionForm(forms.Form): ] ): groups["administration"]["permissions"].append( - (field_name, field, permission) + (field_name, bound_field, permission) ) else: groups["system"]["permissions"].append( - (field_name, field, permission) + (field_name, bound_field, permission) ) except Permission.DoesNotExist: # Create a fallback permission-like object with proper display @@ -1430,7 +1433,8 @@ class UserPermissionForm(forms.Form): self.codename = field_name fallback_perm = FallbackPermission(field_name) - groups["system"]["permissions"].append((field_name, field, fallback_perm)) + bound_field = self[field_name] # Get bound field for exception case too + groups["system"]["permissions"].append((field_name, bound_field, fallback_perm)) return groups