service_create.py 939 B

12345678910111213141516171819202122232425262728293031
  1. from django.views.generic.edit import CreateView
  2. from django.urls import reverse_lazy
  3. from SharixAdmin.models import Metaservice
  4. from tickets.models import Task
  5. from core.config import API_URL
  6. from ..forms.service_create import Service_Create__form
  7. from ..apps import api
  8. import requests
  9. class Service_Create__view(CreateView):
  10. form_class = Service_Create__form
  11. template_name = 'service_create.html'
  12. success_url = reverse_lazy('platformrunning:home')
  13. def form_valid(self, form):
  14. form.instance.representative_id = self.request.user
  15. response = super().form_valid(form)
  16. new_ticket = {
  17. "task_list": 1,
  18. "created_by": self.request.user.pk,
  19. "type": 1,
  20. "title": "service_create",
  21. "note": str(form.data),
  22. }
  23. requests.post(f"{API_URL}/tickets/api/tickets/", data=new_ticket, headers=api.headers)
  24. return response