1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- from django.contrib.auth import get_user_model
- from django.views.generic.edit import DeleteView
- from django_tables2 import SingleTableView
- from SharixAdmin.tables import UserInfoTable
- from django.contrib.auth.mixins import UserPassesTestMixin
- from django.contrib.auth.models import Group
- from django.urls import reverse
- from django.utils.translation import gettext as _
- class UserListView(UserPassesTestMixin, SingleTableView):
- table_class = UserInfoTable
- queryset = get_user_model().objects.all()
- template_name = 'SharixAdmin/user_information.html'
- def get_context_data(self, **kwargs):
- context = super().get_context_data(**kwargs)
- context.update({
- 'title': _('Управление правами'),
- 'object_list': context['object_list'],
- 'groups': Group.objects.all(),
- 'current_page': "user_information"
- })
- return context
-
- def testing(self, queryset, is_descending):
- queryset = queryset.annotate.order_by("-" if is_descending else "")
- return (queryset, True)
- def test_func(self) -> bool or None:
- group_names = ('METASERVICE-ADMIN')
- if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
- return True
- return False
- class UserDelete(UserPassesTestMixin, DeleteView):
- model = get_user_model()
- template_name = "SharixAdmin/user_information_delete.html"
- def get_context_data(self, **kwargs):
- context = super().get_context_data(**kwargs)
- context.update({
- 'title': 'Управление правами',
- 'object': self.object,
- "current_page": "user_information"
- })
- return context
-
- def get_success_url(self):
- return reverse('user_information')
-
- def test_func(self) -> bool or None:
- group_names = ('METASERVICE-ADMIN')
- if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
- return True
- return False
|