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 @@ ...@@ -43,7 +43,10 @@
<td>{{user.email}}</td> <td>{{user.email}}</td>
<td>{{user.date_joined | date:'d/m/Y - H:i:s'}}</td> <td>{{user.date_joined | date:'d/m/Y - H:i:s'}}</td>
<td>{{user.groups.last.name}}</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> </tr>
{% endfor %} {% endfor %}
</tbody> </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 django.conf.urls import url
from userprofile.views.users import UserListView from userprofile.views.users import UserEditView, UserListView
urlpatterns = [ urlpatterns = [
url( url(
r"^list", r"^list",
UserListView.as_view(), 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.models import User
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
from django.views.generic.list import ListView from django.views.generic.list import ListView
from django.views.generic.edit import UpdateView
class UserListView(LoginRequiredMixin, PermissionRequiredMixin, ListView): class UserListView(LoginRequiredMixin, PermissionRequiredMixin, ListView):
model = User model = User
...@@ -18,3 +21,11 @@ class UserListView(LoginRequiredMixin, PermissionRequiredMixin, ListView): ...@@ -18,3 +21,11 @@ class UserListView(LoginRequiredMixin, PermissionRequiredMixin, ListView):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
return context 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 = [ ...@@ -22,7 +22,7 @@ urlpatterns = [
url(r"^feeds/", include("rp.feeds.urls", namespace="feeds")), url(r"^feeds/", include("rp.feeds.urls", namespace="feeds")),
url(r"^rp/", include("rp.urls", namespace="rp")), url(r"^rp/", include("rp.urls", namespace="rp")),
url(r'^accounts/', include('allauth.urls')), url(r'^accounts/', include('allauth.urls')),
url(r"^users/", include('userprofile.urls')) url(r"^users/", include('userprofile.urls', namespace="users"))
] ]
if settings.DEBUG: 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