user_info.py 1.0 KB

123456789101112131415161718192021222324252627
  1. from django_tables2 import SingleTableView
  2. from SharixAdmin.tables import UserInfoTable
  3. from SharixAdmin.models import SharixUser
  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 = SharixUser.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