Add an (ugly) form to change users' groups

parent 8da1de6a
Pipeline #1793 passed with stages
in 2 minutes and 21 seconds
......@@ -43,7 +43,10 @@
<td>{{user.email}}</td>
<td>{{user.date_joined | date:'d/m/Y - H:i:s'}}</td>
<td>{{user.groups.last.name}}</td>
<td></td>
<td><a href="{% url 'users:edit' user.id %}">
<i class="fa fa-fw fa-pencil" aria-hidden="true"></i>
Edit</a>
</td>
</tr>
{% endfor %}
</tbody>
......
{% extends "base.html" %}
{% block content %}
<form action="" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Update" />
</form>
{% endblock %}
from django.conf.urls import url
from userprofile.views.users import UserListView
from userprofile.views.users import UserEditView, UserListView
urlpatterns = [
url(
r"^list",
UserListView.as_view(),
name="user-list"
name="list"
),
url(
r"^edit/(?P<pk>\d+)",
UserEditView.as_view(),
name="edit"
)
]
from django.urls import reverse_lazy
from django.contrib.auth.models import User
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
from django.views.generic.list import ListView
from django.views.generic.edit import UpdateView
class UserListView(LoginRequiredMixin, PermissionRequiredMixin, ListView):
model = User
......@@ -18,3 +21,11 @@ class UserListView(LoginRequiredMixin, PermissionRequiredMixin, ListView):
context = super().get_context_data(**kwargs)
return context
class UserEditView(LoginRequiredMixin, PermissionRequiredMixin, UpdateView):
model = User
permission_required = 'userprofile.can_edit_users'
template_name = 'user/user_update_form.html'
fields = ['groups']
success_url = reverse_lazy("users:list")
......@@ -22,7 +22,7 @@ urlpatterns = [
url(r"^feeds/", include("rp.feeds.urls", namespace="feeds")),
url(r"^rp/", include("rp.urls", namespace="rp")),
url(r'^accounts/', include('allauth.urls')),
url(r"^users/", include('userprofile.urls'))
url(r"^users/", include('userprofile.urls', namespace="users"))
]
if settings.DEBUG:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment