partner_info.py 2.2 KB

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