1
0

provider.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from django_tables2 import SingleTableView
  2. from SharixAdmin.utils import group_required
  3. from SharixAdmin.tables import ProviderTable
  4. from dbsynce.models import Provider
  5. from django.contrib.auth.decorators import login_required
  6. from django.http import JsonResponse
  7. from django.contrib.auth.mixins import UserPassesTestMixin
  8. from django.utils.translation import gettext as _
  9. class ProviderListView(UserPassesTestMixin, SingleTableView):
  10. table_class = ProviderTable
  11. queryset = Provider.objects.all()
  12. template_name = 'SharixAdmin/provider.html'
  13. def get_context_data(self, **kwargs):
  14. context = super().get_context_data(**kwargs)
  15. context.update({
  16. 'title': _('Performers'),
  17. 'object_list': context['object_list'],
  18. })
  19. return context
  20. def test_func(self) -> bool or None:
  21. group_names = ('PARTNER-ADMIN')
  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('PARTNER-ADMIN')
  27. def change_provider_status(request):
  28. if request.method == 'POST':
  29. provider_id = request.POST.get('provider_id')
  30. new_status = request.POST.get('new_status')
  31. provider = Provider.objects.get(pk=provider_id)
  32. provider.status = new_status
  33. provider.save()
  34. return JsonResponse({'status': 'success'})
  35. else:
  36. return JsonResponse({'status': 'error'})