Skip to content

Commit

Permalink
Fix bug where get_fieldsets is called twice
Browse files Browse the repository at this point in the history
* If get_fieldsets is called twice, the 'is_active' field will already
  have been replaced by ('is_active', 'email_verification_required')
* Reverts 49105af
* Update CHANGELOG
  • Loading branch information
LilyFoote committed Jul 30, 2014
1 parent 6dd99a3 commit 1172a7e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## Upcoming Release

* Fix bug where VerifyUserAdmin.get_fieldsets is called twice

## v1.2.1

* Bump required version of `incuna-mail` in order to fix circular import.
Expand Down
8 changes: 7 additions & 1 deletion user_management/models/admin.py
Expand Up @@ -55,7 +55,13 @@ def get_fieldsets(self, request, obj=None):
except KeyError:
return fieldsets

index = fields.index('is_active')
try:
index = fields.index('is_active')
except ValueError:
# If get_fieldsets is called twice, 'is_active' will already be
# removed and fieldsets will be correct so return it
return fieldsets

fields[index] = ('is_active', 'email_verification_required')
fieldsets_dict['Permissions']['fields'] = tuple(fields)
return tuple(fieldsets_dict.items())
6 changes: 6 additions & 0 deletions user_management/models/tests/test_admin.py
Expand Up @@ -48,3 +48,9 @@ def test_fieldsets(self):
verify_user_admin.get_fieldsets(request=None, obj=user),
expected_fieldsets,
)

# Django admin can call get_fieldsets twice, so check we don't break
self.assertEqual(
verify_user_admin.get_fieldsets(request=None, obj=user),
expected_fieldsets,
)

0 comments on commit 1172a7e

Please sign in to comment.