|
@@ -11,7 +11,7 @@ from django.utils.translation import gettext as _
|
|
from core.utils.AuthAPI import AuthAPI
|
|
from core.utils.AuthAPI import AuthAPI
|
|
from tickets.models import Task
|
|
from tickets.models import Task
|
|
from core.config import API_URL
|
|
from core.config import API_URL
|
|
-api = AuthAPI("89855703300", "12345")
|
|
|
|
|
|
+api = AuthAPI("79999999999", "Pa$$w0rd1")
|
|
import requests
|
|
import requests
|
|
from django.urls import reverse_lazy
|
|
from django.urls import reverse_lazy
|
|
from django.contrib.auth.hashers import check_password
|
|
from django.contrib.auth.hashers import check_password
|
|
@@ -65,13 +65,97 @@ class PartnerInformationUpdateView(UserPassesTestMixin, UpdateView):
|
|
template_name = "SharixAdmin/partner_information_form.html"
|
|
template_name = "SharixAdmin/partner_information_form.html"
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
def get_context_data(self, **kwargs):
|
|
- context = super().get_context_data(**kwargs)
|
|
|
|
|
|
+ context = super().get_context_data(**kwargs)
|
|
context.update(get_context(self.request, {
|
|
context.update(get_context(self.request, {
|
|
'title': _('Partner Information'),
|
|
'title': _('Partner Information'),
|
|
'object': self.object,
|
|
'object': self.object,
|
|
}))
|
|
}))
|
|
return context
|
|
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):
|
|
def get_success_url(self):
|
|
return reverse('test-page')
|
|
return reverse('test-page')
|
|
|
|
|