1
0

tech_support.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from django_tables2 import SingleTableView
  2. from django.views.generic.edit import UpdateView, CreateView, DeleteView
  3. from SharixAdmin.tables import TechSupTable
  4. from django.contrib.auth.mixins import UserPassesTestMixin
  5. from SharixAdmin.forms import CommentsCreateForm, ServiceTypeUpdateForm
  6. from webservice_running.models import Comments
  7. from django.urls import reverse
  8. from django.utils.translation import gettext as _
  9. class TechListView(UserPassesTestMixin, SingleTableView):
  10. table_class = TechSupTable
  11. queryset = Comments.objects.all()
  12. template_name = 'SharixAdmin/tech_support.html'
  13. def get_context_data(self, **kwargs):
  14. context = super().get_context_data(**kwargs)
  15. context.update({
  16. 'title': 'Техническая поддержка',
  17. 'object_list': context['object_list'],
  18. "current_page": "tech_support"
  19. })
  20. return context
  21. def testing(self, queryset, is_descending):
  22. queryset = queryset.annotate.order_by("-" if is_descending else "")
  23. return (queryset, True)
  24. def test_func(self) -> bool or None:
  25. group_names = ('METASERVICE-ADMIN')
  26. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user:
  27. return True
  28. return False
  29. class TechSupDelete(UserPassesTestMixin, DeleteView):
  30. model = Comments
  31. template_name = "SharixAdmin/tech_support_delete.html"
  32. def get_context_data(self, **kwargs):
  33. context = super().get_context_data(**kwargs)
  34. context.update({
  35. 'title': 'Техническая поддержка',
  36. 'object': self.object,
  37. "current_page": "tech_support"
  38. })
  39. return context
  40. def get_success_url(self):
  41. return reverse('tech_support')
  42. def test_func(self) -> bool or None:
  43. group_names = ('METASERVICE-ADMIN')
  44. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user:
  45. return True
  46. return False