123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- from dbsynce.models import ServiceCategory
- from django.urls import reverse
- from django.utils.translation import gettext as _
- from django.views.generic.edit import UpdateView, CreateView, DeleteView
- from django_tables2 import SingleTableView
- from sharix_admin.forms import ServiceCategoryCreateForm, ServiceCategoryUpdateForm
- from sharix_admin.tables import ServiceCategoryTable
- from .base import BaseView
- class ServiceCategoryCreate(BaseView, CreateView):
- page_title = _('Услуги сервиса')
- page_name = 'service_category'
- model = ServiceCategory
- form_class = ServiceCategoryCreateForm
- template_name = "sharix_admin/service_category_form.html"
- def get_context_data(self, **kwargs):
- context = super().get_context_data(**kwargs)
- context.update({
- 'object': self.object,
- })
- return context
- def get_success_url(self):
- return reverse('service_category')
- def test_func(self) -> bool or None:
- group_names = ('METASERVICE-ADMIN')
- if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
- return True
- return False
- class ServiceCategoryListView(BaseView, SingleTableView):
- page_title = _('Услуги сервиса')
- page_name = 'service_category'
- table_class = ServiceCategoryTable
- queryset = ServiceCategory.objects.all()
- template_name = 'sharix_admin/service_category.html'
- def get_context_data(self, **kwargs):
- context = super().get_context_data(**kwargs)
- context.update({
- 'object_list': context['object_list'],
- })
- return context
- def testing(self, queryset, is_descending):
- queryset = queryset.annotate.order_by("-" if is_descending else "")
- return (queryset, True)
- def test_func(self) -> bool or None:
- group_names = ('METASERVICE-ADMIN')
- if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
- return True
- return False
- class ServiceCategoryUpdateView(BaseView, UpdateView):
- model = ServiceCategory
- form_class = ServiceCategoryCreateForm
- template_name = "sharix_admin/service_category_form.html"
- def get_context_data(self, **kwargs):
- context = super().get_context_data(**kwargs)
- context.update({
- 'title': _('Услуги сервиса'),
- 'object': self.object,
- "current_page": "service_category"
- })
- return context
- def test_func(self) -> bool or None:
- group_names = ('METASERVICE-ADMIN')
- if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
- return True
- return False
- def get_success_url(self):
- return reverse('service_category')
- class ServiceCategoryDelete(BaseView, DeleteView):
- model = ServiceCategory
- template_name = "sharix_admin/service_category_delete.html"
- def get_context_data(self, **kwargs):
- context = super().get_context_data(**kwargs)
- context.update({
- 'title': 'Услуги сервиса',
- 'object': self.object,
- "current_page": "service_category"
- })
- return context
- def get_success_url(self):
- return reverse('service_category')
- def test_func(self) -> bool or None:
- group_names = ('METASERVICE-ADMIN')
- if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
- return True
- return False
|