From b82b9d166d466a4bf2787e94dc3592ed68dcdcb1 Mon Sep 17 00:00:00 2001 From: Klemens Mantzos Date: Mon, 14 Oct 2024 23:36:39 +0200 Subject: [PATCH 1/3] fixes #1362: incorrect rendering of history change form if has_change_permission returns False --- simple_history/admin.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/simple_history/admin.py b/simple_history/admin.py index 6a55e2e1c..fe556ec71 100644 --- a/simple_history/admin.py +++ b/simple_history/admin.py @@ -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 @@ -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) @@ -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, ) From 65485687ed689274f03a441abab965308a309e44 Mon Sep 17 00:00:00 2001 From: Klemens Mantzos Date: Tue, 15 Oct 2024 00:08:24 +0200 Subject: [PATCH 2/3] fixes pre-commit-job by upgrading to python 3.9 --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index abba0c549..0e5536233 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,7 +10,7 @@ repos: rev: 24.8.0 hooks: - id: black - language_version: python3.8 + language_version: python3.9 - repo: https://github.com/pycqa/flake8 rev: 7.1.1 From f33a08617a07075afcd8c226b74052bdb4980299 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 14 Oct 2024 22:08:40 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- simple_history/admin.py | 1 - 1 file changed, 1 deletion(-) diff --git a/simple_history/admin.py b/simple_history/admin.py index fe556ec71..1da2016fd 100644 --- a/simple_history/admin.py +++ b/simple_history/admin.py @@ -21,7 +21,6 @@ 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)