We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
When changing your password from with admin a user is presented with an edit button. 
I've just reset my password from within admin and I get this horrible large edit button. 
<img width="1267" alt="screen shot 2018-01-16 at 12 33 46" src="https://user-images.githubusercontent.com/7290588/34989276-e10b3338-fab9-11e7-9e69-05d1c7846af4.png">

Can we remove the edit button and amend the message to say 'Your details have been updated. You've been logged out for security reasons, please login to continue.' or something like this. 
When changing your password from with admin a user is presented with an edit button. 
I've just reset my password from within admin and I get this horrible large edit button. 
<img width="1267" alt="screen shot 2018-01-16 at 12 33 46" src="https://user-images.githubusercontent.com/7290588/34989276-e10b3338-fab9-11e7-9e69-05d1c7846af4.png">

Can we remove the edit button and amend the message to say 'Your details have been updated. You've been logged out for security reasons, please login to continue.' or something like this. 

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `wagtail/users/views/users.py`
Content:
```
1 from django.conf import settings
2 from django.contrib.auth import get_user_model
3 from django.db.models import Q
4 from django.shortcuts import get_object_or_404, redirect, render
5 from django.urls import reverse
6 from django.utils.translation import ugettext as _
7 from django.views.decorators.vary import vary_on_headers
8 
9 from wagtail.admin import messages
10 from wagtail.admin.forms.search import SearchForm
11 from wagtail.admin.utils import any_permission_required, permission_denied, permission_required
12 from wagtail.core import hooks
13 from wagtail.core.compat import AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME
14 from wagtail.users.forms import UserCreationForm, UserEditForm
15 from wagtail.users.utils import user_can_delete_user
16 from wagtail.utils.loading import get_custom_form
17 from wagtail.utils.pagination import paginate
18 
19 User = get_user_model()
20 
21 # Typically we would check the permission 'auth.change_user' (and 'auth.add_user' /
22 # 'auth.delete_user') for user management actions, but this may vary according to
23 # the AUTH_USER_MODEL setting
24 add_user_perm = "{0}.add_{1}".format(AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME.lower())
25 change_user_perm = "{0}.change_{1}".format(AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME.lower())
26 delete_user_perm = "{0}.delete_{1}".format(AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME.lower())
27 
28 
29 def get_user_creation_form():
30     form_setting = 'WAGTAIL_USER_CREATION_FORM'
31     if hasattr(settings, form_setting):
32         return get_custom_form(form_setting)
33     else:
34         return UserCreationForm
35 
36 
37 def get_user_edit_form():
38     form_setting = 'WAGTAIL_USER_EDIT_FORM'
39     if hasattr(settings, form_setting):
40         return get_custom_form(form_setting)
41     else:
42         return UserEditForm
43 
44 
45 @any_permission_required(add_user_perm, change_user_perm, delete_user_perm)
46 @vary_on_headers('X-Requested-With')
47 def index(request):
48     q = None
49     is_searching = False
50 
51     model_fields = [f.name for f in User._meta.get_fields()]
52 
53     if 'q' in request.GET:
54         form = SearchForm(request.GET, placeholder=_("Search users"))
55         if form.is_valid():
56             q = form.cleaned_data['q']
57             is_searching = True
58             conditions = Q()
59 
60             for term in q.split():
61                 if 'username' in model_fields:
62                     conditions |= Q(username__icontains=term)
63 
64                 if 'first_name' in model_fields:
65                     conditions |= Q(first_name__icontains=term)
66 
67                 if 'last_name' in model_fields:
68                     conditions |= Q(last_name__icontains=term)
69 
70                 if 'email' in model_fields:
71                     conditions |= Q(email__icontains=term)
72 
73             users = User.objects.filter(conditions)
74     else:
75         form = SearchForm(placeholder=_("Search users"))
76 
77     if not is_searching:
78         users = User.objects.all()
79 
80     if 'last_name' in model_fields and 'first_name' in model_fields:
81         users = users.order_by('last_name', 'first_name')
82 
83     if 'ordering' in request.GET:
84         ordering = request.GET['ordering']
85 
86         if ordering == 'username':
87             users = users.order_by(User.USERNAME_FIELD)
88     else:
89         ordering = 'name'
90 
91     paginator, users = paginate(request, users)
92 
93     if request.is_ajax():
94         return render(request, "wagtailusers/users/results.html", {
95             'users': users,
96             'is_searching': is_searching,
97             'query_string': q,
98             'ordering': ordering,
99         })
100     else:
101         return render(request, "wagtailusers/users/index.html", {
102             'search_form': form,
103             'users': users,
104             'is_searching': is_searching,
105             'ordering': ordering,
106             'query_string': q,
107         })
108 
109 
110 @permission_required(add_user_perm)
111 def create(request):
112     for fn in hooks.get_hooks('before_create_user'):
113         result = fn(request)
114         if hasattr(result, 'status_code'):
115             return result
116     if request.method == 'POST':
117         form = get_user_creation_form()(request.POST, request.FILES)
118         if form.is_valid():
119             user = form.save()
120             messages.success(request, _("User '{0}' created.").format(user), buttons=[
121                 messages.button(reverse('wagtailusers_users:edit', args=(user.pk,)), _('Edit'))
122             ])
123             for fn in hooks.get_hooks('after_create_user'):
124                 result = fn(request, user)
125                 if hasattr(result, 'status_code'):
126                     return result
127             return redirect('wagtailusers_users:index')
128         else:
129             messages.error(request, _("The user could not be created due to errors."))
130     else:
131         form = get_user_creation_form()()
132 
133     return render(request, 'wagtailusers/users/create.html', {
134         'form': form,
135     })
136 
137 
138 @permission_required(change_user_perm)
139 def edit(request, user_id):
140     user = get_object_or_404(User, pk=user_id)
141     can_delete = user_can_delete_user(request.user, user)
142     editing_self = request.user == user
143 
144     for fn in hooks.get_hooks('before_edit_user'):
145         result = fn(request, user)
146         if hasattr(result, 'status_code'):
147             return result
148     if request.method == 'POST':
149         form = get_user_edit_form()(request.POST, request.FILES, instance=user, editing_self=editing_self)
150         if form.is_valid():
151             user = form.save()
152             messages.success(request, _("Your details have been updated. You've been logged out for security reasons, "
153                                         "please login to continue."))
154             for fn in hooks.get_hooks('after_edit_user'):
155                 result = fn(request, user)
156                 if hasattr(result, 'status_code'):
157                     return result
158             return redirect('wagtailusers_users:index')
159         else:
160             messages.error(request, _("The user could not be saved due to errors."))
161     else:
162         form = get_user_edit_form()(instance=user, editing_self=editing_self)
163 
164     return render(request, 'wagtailusers/users/edit.html', {
165         'user': user,
166         'form': form,
167         'can_delete': can_delete,
168     })
169 
170 
171 @permission_required(delete_user_perm)
172 def delete(request, user_id):
173     user = get_object_or_404(User, pk=user_id)
174 
175     if not user_can_delete_user(request.user, user):
176         return permission_denied(request)
177 
178     for fn in hooks.get_hooks('before_delete_user'):
179         result = fn(request, user)
180         if hasattr(result, 'status_code'):
181             return result
182     if request.method == 'POST':
183         user.delete()
184         messages.success(request, _("User '{0}' deleted.").format(user))
185         for fn in hooks.get_hooks('after_delete_user'):
186             result = fn(request, user)
187             if hasattr(result, 'status_code'):
188                 return result
189         return redirect('wagtailusers_users:index')
190 
191     return render(request, "wagtailusers/users/confirm_delete.html", {
192         'user': user,
193     })
194
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/wagtail/users/views/users.py b/wagtail/users/views/users.py
--- a/wagtail/users/views/users.py
+++ b/wagtail/users/views/users.py
@@ -1,5 +1,5 @@
 from django.conf import settings
-from django.contrib.auth import get_user_model
+from django.contrib.auth import get_user_model, update_session_auth_hash
 from django.db.models import Q
 from django.shortcuts import get_object_or_404, redirect, render
 from django.urls import reverse
@@ -149,8 +149,14 @@
         form = get_user_edit_form()(request.POST, request.FILES, instance=user, editing_self=editing_self)
         if form.is_valid():
             user = form.save()
-            messages.success(request, _("Your details have been updated. You've been logged out for security reasons, "
-                                        "please login to continue."))
+
+            if user == request.user and 'password1' in form.changed_data:
+                # User is changing their own password; need to update their session hash
+                update_session_auth_hash(request, user)
+
+            messages.success(request, _("User '{0}' updated.").format(user), buttons=[
+                messages.button(reverse('wagtailusers_users:edit', args=(user.pk,)), _('Edit'))
+            ])
             for fn in hooks.get_hooks('after_edit_user'):
                 result = fn(request, user)
                 if hasattr(result, 'status_code'):

{"golden_diff": "diff --git a/wagtail/users/views/users.py b/wagtail/users/views/users.py\n--- a/wagtail/users/views/users.py\n+++ b/wagtail/users/views/users.py\n@@ -1,5 +1,5 @@\n from django.conf import settings\n-from django.contrib.auth import get_user_model\n+from django.contrib.auth import get_user_model, update_session_auth_hash\n from django.db.models import Q\n from django.shortcuts import get_object_or_404, redirect, render\n from django.urls import reverse\n@@ -149,8 +149,14 @@\n         form = get_user_edit_form()(request.POST, request.FILES, instance=user, editing_self=editing_self)\n         if form.is_valid():\n             user = form.save()\n-            messages.success(request, _(\"Your details have been updated. You've been logged out for security reasons, \"\n-                                        \"please login to continue.\"))\n+\n+            if user == request.user and 'password1' in form.changed_data:\n+                # User is changing their own password; need to update their session hash\n+                update_session_auth_hash(request, user)\n+\n+            messages.success(request, _(\"User '{0}' updated.\").format(user), buttons=[\n+                messages.button(reverse('wagtailusers_users:edit', args=(user.pk,)), _('Edit'))\n+            ])\n             for fn in hooks.get_hooks('after_edit_user'):\n                 result = fn(request, user)\n                 if hasattr(result, 'status_code'):\n", "issue": "When changing your password from with admin a user is presented with an edit button. \nI've just reset my password from within admin and I get this horrible large edit button. \r\n<img width=\"1267\" alt=\"screen shot 2018-01-16 at 12 33 46\" src=\"https://user-images.githubusercontent.com/7290588/34989276-e10b3338-fab9-11e7-9e69-05d1c7846af4.png\">\r\n\r\nCan we remove the edit button and amend the message to say 'Your details have been updated. You've been logged out for security reasons, please login to continue.' or something like this. \nWhen changing your password from with admin a user is presented with an edit button. \nI've just reset my password from within admin and I get this horrible large edit button. \r\n<img width=\"1267\" alt=\"screen shot 2018-01-16 at 12 33 46\" src=\"https://user-images.githubusercontent.com/7290588/34989276-e10b3338-fab9-11e7-9e69-05d1c7846af4.png\">\r\n\r\nCan we remove the edit button and amend the message to say 'Your details have been updated. You've been logged out for security reasons, please login to continue.' or something like this. \n", "before_files": [{"content": "from django.conf import settings\nfrom django.contrib.auth import get_user_model\nfrom django.db.models import Q\nfrom django.shortcuts import get_object_or_404, redirect, render\nfrom django.urls import reverse\nfrom django.utils.translation import ugettext as _\nfrom django.views.decorators.vary import vary_on_headers\n\nfrom wagtail.admin import messages\nfrom wagtail.admin.forms.search import SearchForm\nfrom wagtail.admin.utils import any_permission_required, permission_denied, permission_required\nfrom wagtail.core import hooks\nfrom wagtail.core.compat import AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME\nfrom wagtail.users.forms import UserCreationForm, UserEditForm\nfrom wagtail.users.utils import user_can_delete_user\nfrom wagtail.utils.loading import get_custom_form\nfrom wagtail.utils.pagination import paginate\n\nUser = get_user_model()\n\n# Typically we would check the permission 'auth.change_user' (and 'auth.add_user' /\n# 'auth.delete_user') for user management actions, but this may vary according to\n# the AUTH_USER_MODEL setting\nadd_user_perm = \"{0}.add_{1}\".format(AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME.lower())\nchange_user_perm = \"{0}.change_{1}\".format(AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME.lower())\ndelete_user_perm = \"{0}.delete_{1}\".format(AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME.lower())\n\n\ndef get_user_creation_form():\n    form_setting = 'WAGTAIL_USER_CREATION_FORM'\n    if hasattr(settings, form_setting):\n        return get_custom_form(form_setting)\n    else:\n        return UserCreationForm\n\n\ndef get_user_edit_form():\n    form_setting = 'WAGTAIL_USER_EDIT_FORM'\n    if hasattr(settings, form_setting):\n        return get_custom_form(form_setting)\n    else:\n        return UserEditForm\n\n\n@any_permission_required(add_user_perm, change_user_perm, delete_user_perm)\n@vary_on_headers('X-Requested-With')\ndef index(request):\n    q = None\n    is_searching = False\n\n    model_fields = [f.name for f in User._meta.get_fields()]\n\n    if 'q' in request.GET:\n        form = SearchForm(request.GET, placeholder=_(\"Search users\"))\n        if form.is_valid():\n            q = form.cleaned_data['q']\n            is_searching = True\n            conditions = Q()\n\n            for term in q.split():\n                if 'username' in model_fields:\n                    conditions |= Q(username__icontains=term)\n\n                if 'first_name' in model_fields:\n                    conditions |= Q(first_name__icontains=term)\n\n                if 'last_name' in model_fields:\n                    conditions |= Q(last_name__icontains=term)\n\n                if 'email' in model_fields:\n                    conditions |= Q(email__icontains=term)\n\n            users = User.objects.filter(conditions)\n    else:\n        form = SearchForm(placeholder=_(\"Search users\"))\n\n    if not is_searching:\n        users = User.objects.all()\n\n    if 'last_name' in model_fields and 'first_name' in model_fields:\n        users = users.order_by('last_name', 'first_name')\n\n    if 'ordering' in request.GET:\n        ordering = request.GET['ordering']\n\n        if ordering == 'username':\n            users = users.order_by(User.USERNAME_FIELD)\n    else:\n        ordering = 'name'\n\n    paginator, users = paginate(request, users)\n\n    if request.is_ajax():\n        return render(request, \"wagtailusers/users/results.html\", {\n            'users': users,\n            'is_searching': is_searching,\n            'query_string': q,\n            'ordering': ordering,\n        })\n    else:\n        return render(request, \"wagtailusers/users/index.html\", {\n            'search_form': form,\n            'users': users,\n            'is_searching': is_searching,\n            'ordering': ordering,\n            'query_string': q,\n        })\n\n\n@permission_required(add_user_perm)\ndef create(request):\n    for fn in hooks.get_hooks('before_create_user'):\n        result = fn(request)\n        if hasattr(result, 'status_code'):\n            return result\n    if request.method == 'POST':\n        form = get_user_creation_form()(request.POST, request.FILES)\n        if form.is_valid():\n            user = form.save()\n            messages.success(request, _(\"User '{0}' created.\").format(user), buttons=[\n                messages.button(reverse('wagtailusers_users:edit', args=(user.pk,)), _('Edit'))\n            ])\n            for fn in hooks.get_hooks('after_create_user'):\n                result = fn(request, user)\n                if hasattr(result, 'status_code'):\n                    return result\n            return redirect('wagtailusers_users:index')\n        else:\n            messages.error(request, _(\"The user could not be created due to errors.\"))\n    else:\n        form = get_user_creation_form()()\n\n    return render(request, 'wagtailusers/users/create.html', {\n        'form': form,\n    })\n\n\n@permission_required(change_user_perm)\ndef edit(request, user_id):\n    user = get_object_or_404(User, pk=user_id)\n    can_delete = user_can_delete_user(request.user, user)\n    editing_self = request.user == user\n\n    for fn in hooks.get_hooks('before_edit_user'):\n        result = fn(request, user)\n        if hasattr(result, 'status_code'):\n            return result\n    if request.method == 'POST':\n        form = get_user_edit_form()(request.POST, request.FILES, instance=user, editing_self=editing_self)\n        if form.is_valid():\n            user = form.save()\n            messages.success(request, _(\"Your details have been updated. You've been logged out for security reasons, \"\n                                        \"please login to continue.\"))\n            for fn in hooks.get_hooks('after_edit_user'):\n                result = fn(request, user)\n                if hasattr(result, 'status_code'):\n                    return result\n            return redirect('wagtailusers_users:index')\n        else:\n            messages.error(request, _(\"The user could not be saved due to errors.\"))\n    else:\n        form = get_user_edit_form()(instance=user, editing_self=editing_self)\n\n    return render(request, 'wagtailusers/users/edit.html', {\n        'user': user,\n        'form': form,\n        'can_delete': can_delete,\n    })\n\n\n@permission_required(delete_user_perm)\ndef delete(request, user_id):\n    user = get_object_or_404(User, pk=user_id)\n\n    if not user_can_delete_user(request.user, user):\n        return permission_denied(request)\n\n    for fn in hooks.get_hooks('before_delete_user'):\n        result = fn(request, user)\n        if hasattr(result, 'status_code'):\n            return result\n    if request.method == 'POST':\n        user.delete()\n        messages.success(request, _(\"User '{0}' deleted.\").format(user))\n        for fn in hooks.get_hooks('after_delete_user'):\n            result = fn(request, user)\n            if hasattr(result, 'status_code'):\n                return result\n        return redirect('wagtailusers_users:index')\n\n    return render(request, \"wagtailusers/users/confirm_delete.html\", {\n        'user': user,\n    })\n", "path": "wagtail/users/views/users.py"}], "after_files": [{"content": "from django.conf import settings\nfrom django.contrib.auth import get_user_model, update_session_auth_hash\nfrom django.db.models import Q\nfrom django.shortcuts import get_object_or_404, redirect, render\nfrom django.urls import reverse\nfrom django.utils.translation import ugettext as _\nfrom django.views.decorators.vary import vary_on_headers\n\nfrom wagtail.admin import messages\nfrom wagtail.admin.forms.search import SearchForm\nfrom wagtail.admin.utils import any_permission_required, permission_denied, permission_required\nfrom wagtail.core import hooks\nfrom wagtail.core.compat import AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME\nfrom wagtail.users.forms import UserCreationForm, UserEditForm\nfrom wagtail.users.utils import user_can_delete_user\nfrom wagtail.utils.loading import get_custom_form\nfrom wagtail.utils.pagination import paginate\n\nUser = get_user_model()\n\n# Typically we would check the permission 'auth.change_user' (and 'auth.add_user' /\n# 'auth.delete_user') for user management actions, but this may vary according to\n# the AUTH_USER_MODEL setting\nadd_user_perm = \"{0}.add_{1}\".format(AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME.lower())\nchange_user_perm = \"{0}.change_{1}\".format(AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME.lower())\ndelete_user_perm = \"{0}.delete_{1}\".format(AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME.lower())\n\n\ndef get_user_creation_form():\n    form_setting = 'WAGTAIL_USER_CREATION_FORM'\n    if hasattr(settings, form_setting):\n        return get_custom_form(form_setting)\n    else:\n        return UserCreationForm\n\n\ndef get_user_edit_form():\n    form_setting = 'WAGTAIL_USER_EDIT_FORM'\n    if hasattr(settings, form_setting):\n        return get_custom_form(form_setting)\n    else:\n        return UserEditForm\n\n\n@any_permission_required(add_user_perm, change_user_perm, delete_user_perm)\n@vary_on_headers('X-Requested-With')\ndef index(request):\n    q = None\n    is_searching = False\n\n    model_fields = [f.name for f in User._meta.get_fields()]\n\n    if 'q' in request.GET:\n        form = SearchForm(request.GET, placeholder=_(\"Search users\"))\n        if form.is_valid():\n            q = form.cleaned_data['q']\n            is_searching = True\n            conditions = Q()\n\n            for term in q.split():\n                if 'username' in model_fields:\n                    conditions |= Q(username__icontains=term)\n\n                if 'first_name' in model_fields:\n                    conditions |= Q(first_name__icontains=term)\n\n                if 'last_name' in model_fields:\n                    conditions |= Q(last_name__icontains=term)\n\n                if 'email' in model_fields:\n                    conditions |= Q(email__icontains=term)\n\n            users = User.objects.filter(conditions)\n    else:\n        form = SearchForm(placeholder=_(\"Search users\"))\n\n    if not is_searching:\n        users = User.objects.all()\n\n    if 'last_name' in model_fields and 'first_name' in model_fields:\n        users = users.order_by('last_name', 'first_name')\n\n    if 'ordering' in request.GET:\n        ordering = request.GET['ordering']\n\n        if ordering == 'username':\n            users = users.order_by(User.USERNAME_FIELD)\n    else:\n        ordering = 'name'\n\n    paginator, users = paginate(request, users)\n\n    if request.is_ajax():\n        return render(request, \"wagtailusers/users/results.html\", {\n            'users': users,\n            'is_searching': is_searching,\n            'query_string': q,\n            'ordering': ordering,\n        })\n    else:\n        return render(request, \"wagtailusers/users/index.html\", {\n            'search_form': form,\n            'users': users,\n            'is_searching': is_searching,\n            'ordering': ordering,\n            'query_string': q,\n        })\n\n\n@permission_required(add_user_perm)\ndef create(request):\n    for fn in hooks.get_hooks('before_create_user'):\n        result = fn(request)\n        if hasattr(result, 'status_code'):\n            return result\n    if request.method == 'POST':\n        form = get_user_creation_form()(request.POST, request.FILES)\n        if form.is_valid():\n            user = form.save()\n            messages.success(request, _(\"User '{0}' created.\").format(user), buttons=[\n                messages.button(reverse('wagtailusers_users:edit', args=(user.pk,)), _('Edit'))\n            ])\n            for fn in hooks.get_hooks('after_create_user'):\n                result = fn(request, user)\n                if hasattr(result, 'status_code'):\n                    return result\n            return redirect('wagtailusers_users:index')\n        else:\n            messages.error(request, _(\"The user could not be created due to errors.\"))\n    else:\n        form = get_user_creation_form()()\n\n    return render(request, 'wagtailusers/users/create.html', {\n        'form': form,\n    })\n\n\n@permission_required(change_user_perm)\ndef edit(request, user_id):\n    user = get_object_or_404(User, pk=user_id)\n    can_delete = user_can_delete_user(request.user, user)\n    editing_self = request.user == user\n\n    for fn in hooks.get_hooks('before_edit_user'):\n        result = fn(request, user)\n        if hasattr(result, 'status_code'):\n            return result\n    if request.method == 'POST':\n        form = get_user_edit_form()(request.POST, request.FILES, instance=user, editing_self=editing_self)\n        if form.is_valid():\n            user = form.save()\n\n            if user == request.user and 'password1' in form.changed_data:\n                # User is changing their own password; need to update their session hash\n                update_session_auth_hash(request, user)\n\n            messages.success(request, _(\"User '{0}' updated.\").format(user), buttons=[\n                messages.button(reverse('wagtailusers_users:edit', args=(user.pk,)), _('Edit'))\n            ])\n            for fn in hooks.get_hooks('after_edit_user'):\n                result = fn(request, user)\n                if hasattr(result, 'status_code'):\n                    return result\n            return redirect('wagtailusers_users:index')\n        else:\n            messages.error(request, _(\"The user could not be saved due to errors.\"))\n    else:\n        form = get_user_edit_form()(instance=user, editing_self=editing_self)\n\n    return render(request, 'wagtailusers/users/edit.html', {\n        'user': user,\n        'form': form,\n        'can_delete': can_delete,\n    })\n\n\n@permission_required(delete_user_perm)\ndef delete(request, user_id):\n    user = get_object_or_404(User, pk=user_id)\n\n    if not user_can_delete_user(request.user, user):\n        return permission_denied(request)\n\n    for fn in hooks.get_hooks('before_delete_user'):\n        result = fn(request, user)\n        if hasattr(result, 'status_code'):\n            return result\n    if request.method == 'POST':\n        user.delete()\n        messages.success(request, _(\"User '{0}' deleted.\").format(user))\n        for fn in hooks.get_hooks('after_delete_user'):\n            result = fn(request, user)\n            if hasattr(result, 'status_code'):\n                return result\n        return redirect('wagtailusers_users:index')\n\n    return render(request, \"wagtailusers/users/confirm_delete.html\", {\n        'user': user,\n    })\n", "path": "wagtail/users/views/users.py"}]}