partner_info.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. class PartnerInformationCreate(UserPassesTestMixin, CreateView):
  10. model = Company
  11. form_class = PartnerInformationCreateForm
  12. template_name = "SharixAdmin/partner_information_form.html"
  13. def get_context_data(self, **kwargs):
  14. context = super().get_context_data(**kwargs)
  15. context.update(get_context(self.request, {
  16. 'title': 'Информация о партнере',
  17. 'object': self.object,
  18. }))
  19. return context
  20. def get_success_url(self):
  21. return reverse('test-page')
  22. def test_func(self) -> bool or None:
  23. group_names = ('PARTNER-ADMIN')
  24. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
  25. return True
  26. return False
  27. class PartnerInformationUpdateView(UserPassesTestMixin, UpdateView):
  28. model = Company
  29. form_class = PartnerInformationUpdateForm
  30. template_name = "SharixAdmin/partner_information_form.html"
  31. def get_context_data(self, **kwargs):
  32. context = super().get_context_data(**kwargs)
  33. context.update(get_context(self.request, {
  34. 'title': 'Информация о партнере',
  35. 'object': self.object,
  36. }))
  37. return context
  38. def get_success_url(self):
  39. return reverse('test-page')
  40. def test_func(self) -> bool or None:
  41. group_names = ('PARTNER-ADMIN')
  42. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
  43. return True
  44. return False
  45. def partner_information(request):
  46. context = get_context(request, {
  47. 'title':'Информация о партнере',
  48. })
  49. return render(request, 'SharixAdmin/partner_information.html', context)