Explorar o código

Review of the functionality of automatic creation of lists and groups

TonyKurts hai 6 meses
pai
achega
2caf82ee0b

+ 2 - 5
SharixAdmin/apps.py

@@ -5,10 +5,7 @@ from django.apps import AppConfig
 class SharixadminConfig(AppConfig):
     default_auto_field = 'django.db.models.BigAutoField'
     name = 'SharixAdmin'
-    verbose_name = "SHARIX_PLATFORM"
+    verbose_name = "SHARIX_OPEN"
 
     def ready(self):
-        # Импортируем обработчик сигнала, чтобы зарегистрировать его
-        from django.db.models.signals import post_migrate
-        from .groups import create_groups
-        post_migrate.connect(create_groups, sender=self)
+       import SharixAdmin.signals

+ 2 - 12
SharixAdmin/groups.py → SharixAdmin/signals.py

@@ -1,9 +1,9 @@
 from django.contrib.auth.models import Group
 from django.dispatch import receiver
 from django.db.models.signals import post_migrate
-from django.contrib.auth.decorators import user_passes_test
 
-#Создание групп
+
+# Создание групп
 @receiver(post_migrate)
 def create_groups(sender, **kwargs):
     Group.objects.get_or_create(pk=21, name='METASERVICE-ADMIN')
@@ -19,15 +19,5 @@ def create_groups(sender, **kwargs):
     Group.objects.get_or_create(pk=41, name='PROVIDER')
     Group.objects.get_or_create(pk=51, name='CLIENT')
     Group.objects.get_or_create(pk=61, name='GUEST')
-    
-
 
-# Функция позволяющая определить принадлежность к группе, перенаправляет на авторизацию
-def group_required(*group_names):
-    def in_groups(u):
-        if u.is_authenticated:
-            if u.groups.filter(name=group_names).exists() or u.is_superuser:
-                return True
-        return False
 
-    return user_passes_test(in_groups)

+ 12 - 0
SharixAdmin/utils.py

@@ -0,0 +1,12 @@
+from django.contrib.auth.decorators import user_passes_test
+
+
+# Функция позволяющая определить принадлежность к группе, перенаправляет на авторизацию
+def group_required(*group_names):
+    def in_groups(u):
+        if u.is_authenticated:
+            if u.groups.filter(name=group_names).exists() or u.is_superuser:
+                return True
+        return False
+
+    return user_passes_test(in_groups)

+ 1 - 1
SharixAdmin/views/partner_info.py

@@ -1,6 +1,6 @@
 from django.shortcuts import render
 from SharixAdmin.forms import PartnerInformationCreateForm, PartnerInformationUpdateForm
-from SharixAdmin.groups import group_required
+from SharixAdmin.utils import group_required
 from dbsynce.models import Company
 from django.contrib.auth.mixins import UserPassesTestMixin
 from django.views.generic.edit import UpdateView, CreateView

+ 1 - 1
SharixAdmin/views/partners.py

@@ -1,6 +1,6 @@
 from django_tables2 import SingleTableView
 from django.contrib.auth.mixins import UserPassesTestMixin
-from SharixAdmin.groups import group_required
+from SharixAdmin.utils import group_required
 from SharixAdmin.tables import PartnersTable
 from django.contrib.auth.decorators import login_required
 from dbsynce.models import Company

+ 1 - 1
SharixAdmin/views/provider.py

@@ -1,5 +1,5 @@
 from django_tables2 import SingleTableView
-from SharixAdmin.groups import group_required
+from SharixAdmin.utils import group_required
 from SharixAdmin.tables import ProviderTable
 from dbsynce.models import Provider
 from django.contrib.auth.decorators import login_required

+ 1 - 1
SharixAdmin/views/resource.py

@@ -1,6 +1,6 @@
 from django_tables2 import SingleTableView
 from django.contrib.auth.mixins import UserPassesTestMixin
-from SharixAdmin.groups import group_required
+from SharixAdmin.utils import group_required
 from SharixAdmin.tables import ResourceTable
 from django.contrib.auth.decorators import login_required
 from dbsynce.models import Resource

+ 1 - 1
SharixAdmin/views/service.py

@@ -1,5 +1,5 @@
 from django_tables2 import SingleTableView
-from SharixAdmin.groups import group_required
+from SharixAdmin.utils import group_required
 from SharixAdmin.tables import ServiceTable
 from dbsynce.models import Service
 from django.contrib.auth.decorators import login_required