from django_tables2 import SingleTableView from django.views.generic.edit import UpdateView, CreateView, DeleteView from SharixAdmin.tables import TechSupTable from django.contrib.auth.mixins import UserPassesTestMixin from SharixAdmin.forms import CommentsCreateForm, ServiceTypeUpdateForm from webservice_running.models import Comments from django.urls import reverse from django.utils.translation import gettext as _ class TechListView(UserPassesTestMixin, SingleTableView): table_class = TechSupTable queryset = Comments.objects.all() template_name = 'SharixAdmin/tech_support.html' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context.update({ 'title': 'Техническая поддержка', 'object_list': context['object_list'], "current_page": "tech_support" }) 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: return True return False class TechSupDelete(UserPassesTestMixin, DeleteView): model = Comments template_name = "SharixAdmin/tech_support_delete.html" def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context.update({ 'title': 'Техническая поддержка', 'object': self.object, "current_page": "tech_support" }) return context def get_success_url(self): return reverse('tech_support') 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: return True return False