service_category.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. from dbsynce.models import ServiceCategory
  2. from django.urls import reverse
  3. from django.utils.translation import gettext as _
  4. from django.views.generic.edit import UpdateView, CreateView, DeleteView
  5. from django_tables2 import SingleTableView
  6. from sharix_admin.forms import ServiceCategoryCreateForm, ServiceCategoryUpdateForm
  7. from sharix_admin.tables import ServiceCategoryTable
  8. from .base import BaseView
  9. class ServiceCategoryCreate(BaseView, CreateView):
  10. page_title = _('Услуги сервиса')
  11. page_name = 'service_category'
  12. model = ServiceCategory
  13. form_class = ServiceCategoryCreateForm
  14. template_name = "sharix_admin/service_category_form.html"
  15. def get_context_data(self, **kwargs):
  16. context = super().get_context_data(**kwargs)
  17. context.update({
  18. 'object': self.object,
  19. })
  20. return context
  21. def get_success_url(self):
  22. return reverse('service_category')
  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 ServiceCategoryListView(BaseView, SingleTableView):
  29. page_title = _('Услуги сервиса')
  30. page_name = 'service_category'
  31. table_class = ServiceCategoryTable
  32. queryset = ServiceCategory.objects.all()
  33. template_name = 'sharix_admin/service_category.html'
  34. def get_context_data(self, **kwargs):
  35. context = super().get_context_data(**kwargs)
  36. context.update({
  37. 'object_list': context['object_list'],
  38. })
  39. return context
  40. def testing(self, queryset, is_descending):
  41. queryset = queryset.annotate.order_by("-" if is_descending else "")
  42. return (queryset, True)
  43. def test_func(self) -> bool or None:
  44. group_names = ('METASERVICE-ADMIN')
  45. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
  46. return True
  47. return False
  48. class ServiceCategoryUpdateView(BaseView, UpdateView):
  49. model = ServiceCategory
  50. form_class = ServiceCategoryCreateForm
  51. template_name = "sharix_admin/service_category_form.html"
  52. def get_context_data(self, **kwargs):
  53. context = super().get_context_data(**kwargs)
  54. context.update({
  55. 'title': _('Услуги сервиса'),
  56. 'object': self.object,
  57. "current_page": "service_category"
  58. })
  59. return context
  60. def test_func(self) -> bool or None:
  61. group_names = ('METASERVICE-ADMIN')
  62. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
  63. return True
  64. return False
  65. def get_success_url(self):
  66. return reverse('service_category')
  67. class ServiceCategoryDelete(BaseView, DeleteView):
  68. model = ServiceCategory
  69. template_name = "sharix_admin/service_category_delete.html"
  70. def get_context_data(self, **kwargs):
  71. context = super().get_context_data(**kwargs)
  72. context.update({
  73. 'title': 'Услуги сервиса',
  74. 'object': self.object,
  75. "current_page": "service_category"
  76. })
  77. return context
  78. def get_success_url(self):
  79. return reverse('service_category')
  80. def test_func(self) -> bool or None:
  81. group_names = ('METASERVICE-ADMIN')
  82. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
  83. return True
  84. return False