service_type.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. from django_tables2 import SingleTableView
  2. from django.views.generic.edit import UpdateView, CreateView, DeleteView
  3. from SharixAdmin.tables import ServiceTypeTable
  4. from django.contrib.auth.mixins import UserPassesTestMixin
  5. from SharixAdmin.forms import ServiceTypeCreateForm, ServiceTypeUpdateForm
  6. from dbsynce.models import ServiceType
  7. from django.urls import reverse
  8. from SharixAdmin.views.context import get_context
  9. from django.utils.translation import gettext as _
  10. class ServiceTypeCreate(UserPassesTestMixin, CreateView):
  11. model = ServiceType
  12. form_class = ServiceTypeCreateForm
  13. template_name = "SharixAdmin/service_type_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': _('Service services'),
  18. 'object': self.object,
  19. }))
  20. return context
  21. def get_success_url(self):
  22. return reverse('service_type')
  23. def test_func(self) -> bool or None:
  24. group_names = ('METASERVICE-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 ServiceTypeListView(UserPassesTestMixin, SingleTableView):
  29. table_class = ServiceTypeTable
  30. queryset = ServiceType.objects.all()
  31. template_name = 'SharixAdmin/service_type.html'
  32. def get_context_data(self, **kwargs):
  33. context = super().get_context_data(**kwargs)
  34. context.update(get_context(self.request, {
  35. 'title': 'Service services',
  36. 'object_list': context['object_list'],
  37. }))
  38. return context
  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
  44. class ServiceTypeUpdateView(UserPassesTestMixin, UpdateView):
  45. model = ServiceType
  46. form_class = ServiceTypeUpdateForm
  47. template_name = "SharixAdmin/service_type_form.html"
  48. def get_context_data(self, **kwargs):
  49. context = super().get_context_data(**kwargs)
  50. context.update(get_context(self.request, {
  51. 'title': 'Service services',
  52. 'object_list': context['object_list'],
  53. }))
  54. return context
  55. def test_func(self) -> bool or None:
  56. group_names = ('METASERVICE-ADMIN')
  57. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
  58. return True
  59. return False
  60. class ServiceTypeDelete(UserPassesTestMixin, DeleteView):
  61. model = ServiceType
  62. template_name = "SharixAdmin/service_type_delete.html"
  63. def get_context_data(self, **kwargs):
  64. context = super().get_context_data(**kwargs)
  65. context.update(get_context(self.request, {
  66. 'title': 'Service services',
  67. 'object': self.object,
  68. }))
  69. return context
  70. def get_success_url(self):
  71. return reverse('service_type')
  72. def test_func(self) -> bool or None:
  73. group_names = ('METASERVICE-ADMIN')
  74. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
  75. return True
  76. return False