provider.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. from django_tables2 import SingleTableView
  2. from SharixAdmin.tables import ProviderTable
  3. from metaservicesynced.models import Provider
  4. from django.contrib.auth.decorators import login_required
  5. from SharixAdmin.views.context import get_context
  6. from django.http import JsonResponse
  7. class ProviderListView(SingleTableView):
  8. table_class = ProviderTable
  9. queryset = Provider.objects.all()
  10. template_name = 'SharixAdmin/provider.html'
  11. def get_context_data(self, **kwargs):
  12. context = super().get_context_data(**kwargs)
  13. context.update(get_context(self.request, {
  14. 'title': 'Исполнители',
  15. 'object_list': context['object_list'],
  16. }))
  17. return context
  18. @login_required
  19. def change_provider_status(request):
  20. if request.method == 'POST':
  21. provider_id = request.POST.get('provider_id')
  22. new_status = request.POST.get('new_status')
  23. provider = Provider.objects.get(pk=provider_id)
  24. provider.status = new_status
  25. provider.save()
  26. return JsonResponse({'status': 'success'})
  27. else:
  28. return JsonResponse({'status': 'error'})