partner_info.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. from datetime import timezone
  2. import datetime
  3. from django.shortcuts import render
  4. from SharixAdmin.forms import PartnerInformationCreateForm, PartnerInformationUpdateForm
  5. from SharixAdmin.groups import group_required
  6. from metaservicesynced.models import Company
  7. from django.contrib.auth.mixins import UserPassesTestMixin
  8. from django.views.generic.edit import UpdateView, CreateView
  9. from SharixAdmin.views.context import get_context
  10. from django.urls import reverse
  11. from django.utils.translation import gettext as _
  12. from core.utils.AuthAPI import AuthAPI
  13. from tickets.models import Task
  14. from core.config import API_URL
  15. api = AuthAPI("89855703300", "12345")
  16. import requests
  17. from django.urls import reverse_lazy
  18. class PartnerInformationCreate(UserPassesTestMixin, CreateView):
  19. model = Company
  20. form_class = PartnerInformationCreateForm
  21. template_name = "SharixAdmin/partner_information_form.html"
  22. success_url = reverse_lazy("SharixAdmin:partners")
  23. def form_valid(self, form):
  24. form.instance.representative_id = self.request.user
  25. #responce = super().form_valid(form)
  26. #print(responce)
  27. new_ticket = {
  28. "task_list": 1,
  29. "created_by": self.request.user.pk,
  30. "type": 1,
  31. "title": "service_create",
  32. "note": str(form.data),
  33. }
  34. resp = requests.post(f"{API_URL}/tickets/api/tickets/", data=new_ticket, headers=api.headers)
  35. #print(resp.json())
  36. jso = resp.json()
  37. print(resp.content)
  38. print(resp.json())
  39. print(resp)
  40. #form.cleaned_data['ticket_status'] = Task.objects.get(pk=int(jso['id']))
  41. form.instance.ticket_status = Task.objects.get(pk=int(jso['id']))
  42. print(form.cleaned_data)
  43. responce = super().form_valid(form)
  44. return responce
  45. def get_context_data(self, **kwargs):
  46. context = super().get_context_data(**kwargs)
  47. context.update(get_context(self.request, {
  48. 'title': _('Partner Information'),
  49. 'object': self.object,
  50. }))
  51. return context
  52. def get_success_url(self):
  53. return reverse('partners')
  54. def test_func(self) -> bool or None:
  55. group_names = ('PARTNER-ADMIN')
  56. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
  57. return True
  58. return False
  59. class PartnerInformationUpdateView(UserPassesTestMixin, UpdateView):
  60. model = Company
  61. form_class = PartnerInformationUpdateForm
  62. template_name = "SharixAdmin/partner_information_form.html"
  63. def get_context_data(self, **kwargs):
  64. context = super().get_context_data(**kwargs)
  65. context.update(get_context(self.request, {
  66. 'title': _('Partner Information'),
  67. 'object': self.object,
  68. }))
  69. return context
  70. def get_success_url(self):
  71. return reverse('test-page')
  72. def test_func(self) -> bool or None:
  73. group_names = ('PARTNER-ADMIN')
  74. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
  75. return True
  76. return False
  77. def partner_information(request):
  78. context = get_context(request, {
  79. 'title':_('Partner Information'),
  80. })
  81. return render(request, 'SharixAdmin/partner_information.html', context)