service_info.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from SharixAdmin.forms import ServiceInformationCreateForm, ServiceInformationUpdateForm
  2. from django.contrib.auth.mixins import UserPassesTestMixin
  3. from django.views.generic.edit import CreateView, UpdateView
  4. from metaservicesynced.models import Service
  5. from SharixAdmin.views.context import get_context
  6. from django.urls import reverse
  7. from django.utils.translation import gettext as _
  8. class ServiceInformationCreate(UserPassesTestMixin, CreateView):
  9. model = Service
  10. form_class = ServiceInformationCreateForm
  11. template_name = "SharixAdmin/service_information_form.html"
  12. def get_context_data(self, **kwargs):
  13. context = super().get_context_data(**kwargs)
  14. context.update(get_context(self.request, {
  15. 'title': _('Information about the service'),
  16. 'object': self.object,
  17. }))
  18. return context
  19. def get_success_url(self):
  20. return reverse('test-page')
  21. def test_func(self) -> bool or None:
  22. group_names = ('METASERVICE-ADMIN')
  23. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
  24. return True
  25. return False
  26. class ServiceInformationUpdateView(UserPassesTestMixin, UpdateView):
  27. model = Service
  28. form_class = ServiceInformationUpdateForm
  29. template_name = "SharixAdmin/service_information_form.html"
  30. def get_context_data(self, **kwargs):
  31. context = super().get_context_data(**kwargs)
  32. context.update(get_context(self.request, {
  33. 'title': 'Information about the service',
  34. 'object': self.object,
  35. }))
  36. return context
  37. def get_success_url(self):
  38. return reverse('test-page')
  39. def test_func(self) -> bool or None:
  40. group_names = ('METASERVICE-ADMIN')
  41. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
  42. return True
  43. return False