Bladeren bron

change form partner

Denis 1 jaar geleden
bovenliggende
commit
38afa9e799
4 gewijzigde bestanden met toevoegingen van 91 en 4 verwijderingen
  1. 2 0
      SharixAdmin/forms.py
  2. 2 1
      SharixAdmin/urls.py
  3. 1 1
      SharixAdmin/views/context.py
  4. 86 2
      SharixAdmin/views/partner_info.py

+ 2 - 0
SharixAdmin/forms.py

@@ -155,6 +155,7 @@ class PartnerInformationUpdateForm(forms.ModelForm):
                    "is_global", 
                    "is_visible", 
                    "id_metaservice",
+                   "status"
                    ]
         widgets = {
             'description': forms.Select(attrs={'class': 'form-select'}),
@@ -176,6 +177,7 @@ class PartnerInformationCreateForm(forms.ModelForm):
                    "is_global", 
                    "is_visible", 
                    "id_metaservice",
+                   "status"
                    ]
 
         widgets = {

+ 2 - 1
SharixAdmin/urls.py

@@ -47,6 +47,7 @@ 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('partner_information/', login_required(PartnerInfoView.as_view()), name='partner_information/'),
     #path('v1/auth/', include('djoser.urls'), name='auth-reg'),
 
     path('user_information', login_required(UserListView.as_view()), name='user_information'),
@@ -62,5 +63,5 @@ urlpatterns = [
     
     re_path(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
 ]
-#if DEBUG:
+# if DEBUG:
 #    urlpatterns += path('v1/auth/', include('djoser.urls')),

+ 1 - 1
SharixAdmin/views/context.py

@@ -24,7 +24,7 @@ menu = [
      'roles':['METASERVICE-ADMIN']},
     {'title':_('Information about the service'),    'link':'service_information/add/', 'sel':'hdd-network',
      'roles':['METASERVICE-ADMIN']},
-    {'title':_('Partner Information'),   'link':'partner_information/add/', 'sel':'person',
+    {'title':_('Partner Information'),   'link':'partner_information/', 'sel':'person',
      'roles':['PARTNER-ADMIN']},
     {'title':_('Rates'),                  'link':'service', 'sel':'tikets',
      'roles':['PARTNER-ADMIN']},

+ 86 - 2
SharixAdmin/views/partner_info.py

@@ -11,7 +11,7 @@ from django.utils.translation import gettext as _
 from core.utils.AuthAPI import AuthAPI
 from tickets.models import Task
 from core.config import API_URL
-api = AuthAPI("89855703300", "12345")
+api = AuthAPI("79999999999", "Pa$$w0rd1")
 import requests
 from django.urls import reverse_lazy
 from django.contrib.auth.hashers import check_password
@@ -65,13 +65,97 @@ class PartnerInformationUpdateView(UserPassesTestMixin, UpdateView):
     template_name = "SharixAdmin/partner_information_form.html"
 
     def get_context_data(self, **kwargs):
-        context = super().get_context_data(**kwargs)
+        context = super().get_context_data(**kwargs)       
         context.update(get_context(self.request, {
             'title': _('Partner Information'),
             'object': self.object,
         }))
         return context
     
+    def form_valid(self, form):
+        # Получаем текущий объект Company
+        self.object = form.save()
+
+        # Проверяем, изменились ли поля inn, ogrn, kpp, ответственный, название
+        if (self.object.inn != form.initial['inn'] or
+            self.object.ogrn != form.initial['ogrn'] or
+            self.object.kpp != form.initial['kpp'] or
+            self.object.repr_id != form.initial['repr_id'] or
+            self.object.legal_name != form.initial['legal_name']):
+            new_ticket = {
+            "task_list": 1,
+            "created_by": self.request.user.pk,
+            "type": 1,
+            "title": "service_update",
+            "note": str(form.data),
+            }
+            resp = requests.post(f"{API_URL}/tickets/api/tickets/", data=new_ticket, headers=api.headers)
+            jso = resp.json()
+            form.instance.ticket_status = Task.objects.get(pk=int(jso['id']))
+            print(form.cleaned_data)
+            cli.send_message("open_tickets_backend@ej.sharix-app.org", "eb177b1c9f99a7a13798928318d7a72c", "open_strequest_new@ej.sharix-app.org", str(jso))
+            self.object.status = "deactivate"
+            responce = super().form_valid(form)
+            return responce
+        else:
+            return super().form_valid(form)
+
+    def get_success_url(self):
+        return reverse('test-page')
+    
+    def test_func(self) -> bool or None:
+        group_names = ('PARTNER-ADMIN')
+        if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
+            return True
+        return False
+
+class PartnerInfoView(UserPassesTestMixin, UpdateView):
+    model = Company
+    form_class = PartnerInformationUpdateForm
+    template_name = "SharixAdmin/partner_information_form.html"
+
+    def get_context_data(self, **kwargs):
+        # Проверяем, был ли ранее создан объект Company текущим пользователем
+        if self.request.user.is_authenticated:
+            company = Company.objects.filter(repr_id=self.request.user).first()
+            if company:
+                context['object'] = company
+            
+        context = super().get_context_data(**kwargs)       
+        context.update(get_context(self.request, {
+            'title': _('Partner Information'),
+            'object': self.object,
+        }))
+        return context
+    
+    def form_valid(self, form):
+        # Получаем текущий объект Company
+        self.object = form.save()
+
+        # Проверяем, изменились ли поля inn, ogrn, kpp, ответственный, название
+        if (self.object.inn != form.initial['inn'] or
+            self.object.ogrn != form.initial['ogrn'] or
+            self.object.kpp != form.initial['kpp'] or
+            self.object.repr_id != form.initial['repr_id'] or
+            self.object.legal_name != form.initial['legal_name']):
+            new_ticket = {
+            "task_list": 1,
+            "created_by": self.request.user.pk,
+            "type": 1,
+            "title": "service_update",
+            "note": str(form.data),
+            }
+            resp = requests.post(f"{API_URL}/tickets/api/tickets/", data=new_ticket, headers=api.headers)
+            jso = resp.json()
+            form.instance.ticket_status = Task.objects.get(pk=int(jso['id']))
+            print(form.cleaned_data)
+            cli.send_message("open_tickets_backend@ej.sharix-app.org", "eb177b1c9f99a7a13798928318d7a72c", "open_strequest_new@ej.sharix-app.org", str(jso))
+            self.object.status = "deactivate"
+            responce = super().form_valid(form)
+            return responce
+        else:
+            return super().form_valid(form)
+
     def get_success_url(self):
         return reverse('test-page')