partner_info.py 3.2 KB

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