service_info.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. class ServiceInformationCreate(UserPassesTestMixin, CreateView):
  8. model = Service
  9. form_class = ServiceInformationCreateForm
  10. template_name = "SharixAdmin/service_information_form.html"
  11. def get_context_data(self, **kwargs):
  12. context = super().get_context_data(**kwargs)
  13. context.update(get_context(self.request, {
  14. 'title': 'Информация о сервисе',
  15. 'object': self.object,
  16. }))
  17. return context
  18. def get_success_url(self):
  19. return reverse('test-page')
  20. def test_func(self) -> bool or None:
  21. group_names = ('METASERVICE-ADMIN')
  22. if bool(self.request.user.groups.filter(name__in=group_names)) or self.request.user.is_superuser:
  23. return True
  24. return False
  25. class ServiceInformationUpdateView(UserPassesTestMixin, UpdateView):
  26. model = Service
  27. form_class = ServiceInformationUpdateForm
  28. template_name = "SharixAdmin/service_information_form.html"
  29. def get_context_data(self, **kwargs):
  30. context = super().get_context_data(**kwargs)
  31. context.update(get_context(self.request, {
  32. 'title': 'Информация о сервисе',
  33. 'object': self.object,
  34. }))
  35. return context
  36. def get_success_url(self):
  37. return reverse('test-page')
  38. def test_func(self) -> bool or None:
  39. group_names = ('METASERVICE-ADMIN')
  40. if bool(self.request.user.groups.filter(name__in=group_names)) or self.request.user.is_superuser:
  41. return True
  42. return False