Fix permission checkboxes for Django 3.1

pull/6276/head
Matt Westcott 2020-07-03 16:06:13 +01:00 zatwierdzone przez Matt Westcott
rodzic 884b055289
commit 12a35c79b4
1 zmienionych plików z 14 dodań i 6 usunięć

Wyświetl plik

@ -1,5 +1,6 @@
import itertools
from django import VERSION as DJANGO_VERSION
from django import template
from wagtail.core import hooks
@ -29,8 +30,7 @@ def format_permissions(permission_bound_field):
]
(where 'checkbox' is an object with a tag() method that renders the checkbox as HTML;
this is an instance of django.forms.widgets.CheckboxChoiceInput on Django <1.11,
and a BoundWidget on Django >=1.11)
this is a BoundWidget on Django >=1.11)
- and returns a table template formatted with this list.
@ -41,10 +41,18 @@ def format_permissions(permission_bound_field):
# iterate over permission_bound_field to build a lookup of individual renderable
# checkbox objects
checkboxes_by_id = {
int(checkbox.data['value']): checkbox
for checkbox in permission_bound_field
}
if DJANGO_VERSION < (3, 1):
# checkbox.data['value'] gives the ID
checkboxes_by_id = {
int(checkbox.data['value']): checkbox
for checkbox in permission_bound_field
}
else:
# checkbox.data['value'] gives a ModelChoiceIteratorValue
checkboxes_by_id = {
int(checkbox.data['value'].value): checkbox
for checkbox in permission_bound_field
}
object_perms = []
other_perms = []