resource.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. from django_tables2 import SingleTableView
  2. from SharixAdmin.tables import ResourceTable
  3. from django.contrib.auth.decorators import login_required
  4. from metaservicesynced.models import Resource
  5. from SharixAdmin.views.context import get_context
  6. from django.http import JsonResponse
  7. class ResourceListView(SingleTableView):
  8. table_class = ResourceTable
  9. queryset = Resource.objects.all()
  10. template_name = 'SharixAdmin/resource.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_resource_status(request):
  20. if request.method == 'POST':
  21. resource_id = request.POST.get('resource_id')
  22. new_status = request.POST.get('new_status')
  23. resource = Resource.objects.get(pk=resource_id)
  24. resource.status = new_status
  25. resource.save()
  26. return JsonResponse({'status': 'success'})
  27. else:
  28. return JsonResponse({'status': 'error'})