Nuovo decoratore per django 4
parent
075f507412
commit
900978936e
|
|
@ -5,6 +5,7 @@ from django.core.cache import cache
|
|||
from django.core.exceptions import PermissionDenied
|
||||
from django.template.response import TemplateResponse
|
||||
from django.contrib.admin.options import TO_FIELD_VAR
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.utils.translation import gettext as _
|
||||
from django.contrib.admin import helpers
|
||||
from django.db.models import Model, ManyToManyField, FileField, ImageField
|
||||
|
|
@ -103,7 +104,7 @@ class AdminConfirmMixin:
|
|||
context,
|
||||
)
|
||||
|
||||
@cache_control(private=True)
|
||||
@method_decorator(cache_control(private=True))
|
||||
def changeform_view(self, request, object_id=None, form_url="", extra_context=None):
|
||||
if request.method == "POST":
|
||||
if (not object_id and CONFIRM_ADD in request.POST) or (
|
||||
|
|
@ -185,7 +186,7 @@ class AdminConfirmMixin:
|
|||
else:
|
||||
# Parse the changed data - Note that using form.changed_data would not work because initial is not set
|
||||
for name, new_value in form.cleaned_data.items():
|
||||
|
||||
|
||||
# Since the form considers initial as the value first shown in the form
|
||||
# It could be incorrect when user hits save, and then hits "No, go back to edit"
|
||||
obj.refresh_from_db()
|
||||
|
|
@ -193,10 +194,9 @@ class AdminConfirmMixin:
|
|||
try:
|
||||
field_object = model._meta.get_field(name)
|
||||
initial_value = getattr(obj, name)
|
||||
except (AttributeError, FieldDoesNotExist) as e :
|
||||
except (AttributeError, FieldDoesNotExist) as e:
|
||||
print(e)
|
||||
continue
|
||||
|
||||
|
||||
# Note: getattr does not work on ManyToManyFields
|
||||
if isinstance(field_object, ManyToManyField):
|
||||
|
|
|
|||
2
setup.py
2
setup.py
|
|
@ -7,7 +7,7 @@ README = open(os.path.join(here, "README.md")).read()
|
|||
|
||||
setup(
|
||||
name="django-admin-confirm",
|
||||
version="0.2.4",
|
||||
version="0.2.5",
|
||||
packages=["admin_confirm"],
|
||||
description=("Adds confirmation to Django Admin changes, additions and actions"),
|
||||
long_description_content_type="text/markdown",
|
||||
|
|
|
|||
Loading…
Reference in New Issue