user_info.py 1002 B

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