Skip to content

Commit

Permalink
fixes jazzband#1362: incorrect rendering of history change form if ha…
Browse files Browse the repository at this point in the history
…s_change_permission returns False
  • Loading branch information
fetzig authored Oct 14, 2024
1 parent 7fdebc8 commit b82b9d1
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions simple_history/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.conf import settings
from django.contrib import admin
from django.contrib.admin import helpers
from django.contrib.admin.utils import unquote
from django.contrib.admin.utils import flatten_fieldsets, unquote
from django.contrib.auth import get_permission_codename, get_user_model
from django.core.exceptions import PermissionDenied
from django.db.models import QuerySet
Expand All @@ -21,6 +21,7 @@
from .template_utils import HistoricalRecordContextHelper
from .utils import get_history_manager_for_model, get_history_model_for_model


SIMPLE_HISTORY_EDIT = getattr(settings, "SIMPLE_HISTORY_EDIT", False)


Expand Down Expand Up @@ -240,11 +241,18 @@ def history_form_view(self, request, object_id, version_id, extra_context=None):
else:
form = form_class(instance=obj)

fieldsets = self.get_fieldsets(request, obj)

if object_id and not self.has_change_permission(request, obj):
readonly_fields = flatten_fieldsets(fieldsets)
else:
readonly_fields = self.get_readonly_fields(request, obj)

admin_form = helpers.AdminForm(
form,
self.get_fieldsets(request, obj),
fieldsets,
self.prepopulated_fields,
self.get_readonly_fields(request, obj),
readonly_fields,
model_admin=self,
)

Expand Down

0 comments on commit b82b9d1

Please sign in to comment.