service.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from django_tables2 import SingleTableView
  2. from SharixAdmin.groups import group_required
  3. from SharixAdmin.tables import ServiceTable
  4. from metaservicesynced.models import Service
  5. from django.contrib.auth.decorators import login_required
  6. from SharixAdmin.views.context import get_context
  7. from django.contrib.auth.mixins import UserPassesTestMixin
  8. from django.utils.translation import gettext as _
  9. class ServiceListView(UserPassesTestMixin, SingleTableView):
  10. table_class = ServiceTable
  11. queryset = Service.objects.all()
  12. template_name = 'SharixAdmin/service.html'
  13. def get_context_data(self, **kwargs):
  14. context = super().get_context_data(**kwargs)
  15. context.update(get_context(self.request, {
  16. 'title': _('Rates'),
  17. 'object_list': context['object_list'],
  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.is_superuser:
  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()