sayapinavalentina 1 жил өмнө
parent
commit
011c1d3109

+ 19 - 4
SharixAdmin/forms.py

@@ -123,8 +123,13 @@ class ServiceInformationCreateForm(forms.ModelForm):
 
     class Meta:
         model = Service
-        fields = ["servicetype_id", "id_provider"]
-        exclude = ["resource_id"]
+        fields = "__all__"
+        exclude = ["id", 
+                   "is_global", 
+                   "is_visible", 
+                   "ticket_status",
+                   "id_metaservice",
+                   "resource_id"]
 
         widgets = {
             #'servicetype_id': forms.CharField(max_length=255)
@@ -145,7 +150,12 @@ class PartnerInformationUpdateForm(forms.ModelForm):
 
     class Meta:
         model = Company
-        fields = ['legal_name', 'address', 'repr_id' ]
+        fields = "__all__"
+        exclude = ["id", "ticket_status",
+                   "is_global", 
+                   "is_visible", 
+                   "id_metaservice",
+                   ]
         widgets = {
             'description': forms.Select(attrs={'class': 'form-select'}),
             'repr_id': forms.Select(attrs={'class': 'form-select'}),
@@ -161,7 +171,12 @@ class PartnerInformationCreateForm(forms.ModelForm):
     # legal_name = forms.Fi()
     class Meta:
         model = Company
-        fields = ['legal_name', 'address', 'repr_id']
+        fields = "__all__"
+        exclude = ["id", "ticket_status",
+                   "is_global", 
+                   "is_visible", 
+                   "id_metaservice",
+                   ]
 
         widgets = {
             'description': forms.Select(attrs={'class': 'form-select'}),

+ 0 - 8
SharixAdmin/views/partner_info.py

@@ -1,5 +1,3 @@
-from datetime import timezone
-import datetime
 from django.shortcuts import render
 from SharixAdmin.forms import PartnerInformationCreateForm, PartnerInformationUpdateForm
 from SharixAdmin.groups import group_required
@@ -25,9 +23,6 @@ class PartnerInformationCreate(UserPassesTestMixin, CreateView):
 
     def form_valid(self, form):
         form.instance.representative_id = self.request.user
-        #responce = super().form_valid(form)
-        
-        #print(responce)
         new_ticket = {
             "task_list": 1,
             "created_by": self.request.user.pk,
@@ -36,14 +31,11 @@ class PartnerInformationCreate(UserPassesTestMixin, CreateView):
             "note": str(form.data),
         }
         
-        
         resp = requests.post(f"{API_URL}/tickets/api/tickets/", data=new_ticket, headers=api.headers)
-        #print(resp.json())
         jso = resp.json()
         print(resp.content)
         print(resp.json())
         print(resp)
-        #form.cleaned_data['ticket_status'] = Task.objects.get(pk=int(jso['id']))
         form.instance.ticket_status = Task.objects.get(pk=int(jso['id']))
         print(form.cleaned_data)
         responce = super().form_valid(form)

+ 27 - 1
SharixAdmin/views/service_info.py

@@ -6,10 +6,35 @@ from SharixAdmin.views.context import get_context
 from django.urls import reverse
 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")
+import requests
+from django.urls import reverse_lazy
+from datetime import timezone
+
 class ServiceInformationCreate(UserPassesTestMixin, CreateView):
     model = Service
     form_class = ServiceInformationCreateForm
     template_name = "SharixAdmin/service_information_form.html"
+    success_url = reverse_lazy("SharixAdmin:service_tariff")
+
+    def form_valid(self, form):
+        new_ticket = {
+            "task_list": 1,
+            "created_by": self.request.user.pk,
+            "type": 1,
+            "title": "service_create",
+            "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)
+        responce = super().form_valid(form)
+        return responce
+
 
     def get_context_data(self, **kwargs):
         context = super().get_context_data(**kwargs)
@@ -21,7 +46,8 @@ class ServiceInformationCreate(UserPassesTestMixin, CreateView):
         return context
     
     def get_success_url(self):
-        return reverse('test-page')
+        return reverse('service_tariff')
+    
     
     def test_func(self) -> bool or None:
         group_names = ('METASERVICE-ADMIN')