service.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from django_tables2 import SingleTableView
  2. from SharixAdmin.groups import group_required
  3. from SharixAdmin.tables import ServiceTable
  4. from dbsynce.models import Service
  5. from django.contrib.auth.decorators import login_required
  6. from django.contrib.auth.mixins import UserPassesTestMixin
  7. from django.utils.translation import gettext as _
  8. class ServiceListView(UserPassesTestMixin, SingleTableView):
  9. table_class = ServiceTable
  10. queryset = Service.objects.all()
  11. template_name = 'SharixAdmin/service.html'
  12. def get_context_data(self, **kwargs):
  13. context = super().get_context_data(**kwargs)
  14. context.update({
  15. 'title': 'Экскурсии',
  16. 'object_list': context['object_list'],
  17. "current_page": "service"
  18. })
  19. return context
  20. def test_func(self) -> bool or None:
  21. group_names = ('PROVIDER')
  22. if bool(self.request.user.groups.filter(name=group_names)) or self.request.user:
  23. return True
  24. return False
  25. @login_required
  26. @group_required('PROVIDER')
  27. def change_service_status(request):
  28. if request.method == 'POST':
  29. service_id = request.POST.get('service_id')
  30. new_status = request.POST.get('new_status')
  31. service = Service.objects.get(pk=service_id)
  32. service.status = new_status
  33. service.save()