user_info.py 1.1 KB

12345678910111213141516171819202122232425262728
  1. from django.contrib.auth import get_user_model
  2. from django_tables2 import SingleTableView
  3. from SharixAdmin.tables import UserInfoTable
  4. from SharixAdmin.views.context import get_context
  5. from django.contrib.auth.mixins import UserPassesTestMixin
  6. from django.contrib.auth.models import Group
  7. from django.utils.translation import gettext as _
  8. class UserListView(UserPassesTestMixin, SingleTableView):
  9. table_class = UserInfoTable
  10. queryset = get_user_model().objects.all()
  11. template_name = 'SharixAdmin/user_information.html'
  12. def get_context_data(self, **kwargs):
  13. context = super().get_context_data(**kwargs)
  14. context.update(get_context(self.request, {
  15. 'title': _('User Management'),
  16. 'object_list': context['object_list'],
  17. 'groups': Group.objects.all()
  18. }))
  19. return context
  20. def test_func(self) -> bool or None:
  21. group_names = ('PROVIDER')
  22. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
  23. return True
  24. return False