1
0

user_info.py 1.0 KB

1234567891011121314151617181920212223242526
  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. class UserListView(UserPassesTestMixin, SingleTableView):
  8. table_class = UserInfoTable
  9. queryset = SharixUser.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(get_context(self.request, {
  14. 'title': 'Управление пользователями',
  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