Evgeny Polivanov 1 vuosi sitten
vanhempi
commit
386c4bcc5f

+ 11 - 0
SharixAdmin/tables.py

@@ -160,3 +160,14 @@ class ServiceTable(tables.Table):
             return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-service-id="{}">', record.id)
         else:
             return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-service-id="{}">', record.id)     
+
+class UserInfoTable(tables.Table):
+
+    id = tables.Column(verbose_name='ID', attrs={"td":{"width":"5%"}})
+
+    class Meta:
+        model = SharixUser
+        attrs = {"class": "table table-layout-fixed"}
+        exclude = ('password', 'phone_number', 
+                   'last_login','is_staff', 'is_superuser',
+                   'date_joined')

+ 4 - 3
SharixAdmin/urls.py

@@ -41,9 +41,6 @@ urlpatterns = [
 
     path('service_information/add/', login_required(ServiceInformationCreate.as_view()), name='service_information/add/'),
     path('service_information/edit/<int:pk>', login_required(ServiceInformationUpdateView.as_view()), name='service_information/edit/'),
-
-
-
     
     path('service/', ServiceListView.as_view(), name='service'),
     path('service/change_status/', change_service_status, name='service/change_status'),
@@ -51,6 +48,10 @@ urlpatterns = [
     path('partner_information/add/', login_required(PartnerInformationCreate.as_view()), name='partner_information/add/'),
     path('partner_information/edit/<int:pk>', login_required(PartnerInformationUpdateView.as_view()), name='partner_information/edit/'),
     #path('v1/auth/', include('djoser.urls'), name='auth-reg'),
+
+    path('user_information', login_required(UserListView.as_view()), name='user_information'),
+
+    #path('v1/auth/', include('djoser.urls')),
     path('auth/', include('djoser.urls.authtoken'), name='auth'),
     path('platform/api/', include(router.urls), name="sharix-api"),
     path('senderphone/', PhoneSender.as_view()),

+ 2 - 1
SharixAdmin/views/__init__.py

@@ -13,4 +13,5 @@ from .login import *
 from .test import testPage
 from .balance import balance
 from .trans_id import trans_id
-from .schema import schema_v3
+from .schema import schema_v3
+from .user_info import UserListView

+ 1 - 0
SharixAdmin/views/context.py

@@ -27,6 +27,7 @@ menu = [
      'roles':['PARTNER-ADMIN']},
     {'title':'Тарифы',                  'link':'service', 'sel':'tikets',
      'roles':['PARTNER-ADMIN']},
+    {'title':'Управление пользователями','link':'user_information', 'sel':'person'}
 ]
 
 def get_context(request, page_context) -> dict:

+ 26 - 0
SharixAdmin/views/user_info.py

@@ -0,0 +1,26 @@
+from django_tables2 import SingleTableView
+from SharixAdmin.tables import UserInfoTable
+from SharixAdmin.models import SharixUser
+from SharixAdmin.views.context import get_context
+from django.contrib.auth.mixins import UserPassesTestMixin
+from django.contrib.auth.models import Group
+
+class UserListView(UserPassesTestMixin, SingleTableView):
+    table_class = UserInfoTable
+    queryset = SharixUser.objects.all()
+    template_name = 'SharixAdmin/user_information.html'
+
+    def get_context_data(self, **kwargs):
+        context = super().get_context_data(**kwargs)
+        context.update(get_context(self.request, {
+            'title': 'Управление пользователями',
+            'object_list': context['object_list'],
+            'groups': Group.objects.all()
+        }))
+        return context
+    
+    def test_func(self) -> bool or None:
+        group_names = ('PROVIDER')
+        if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
+            return True
+        return False