users.py 946 Bytes
Newer Older
1 2
from django.urls import reverse_lazy

3
from django.contrib.auth.models import User
4
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
5 6

from django.views.generic.list import ListView
7
from django.views.generic.edit import UpdateView
8

9
class UserListView(LoginRequiredMixin, PermissionRequiredMixin, ListView):
10
    model = User
11
    paginate_by = 20
12 13
    template_name = 'user/user_list.html'
    permission_required = 'userprofile.can_edit_users'
14 15

    def get_queryset(self):
16 17 18
        qs = super().get_queryset()

        return qs
19 20 21 22 23

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)

        return context
24 25 26 27 28 29 30 31

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")