def ajax_upload(self, request, pk): """ Handle drag-n-drop uploads. Call original 'ajax_upload' Filer view, parse response and update plugin instance file_id from it. Send original response back. """ if not callable(filer_ajax_upload): # Do not try to handle request if we were unable to # import Filer view. raise ImproperlyConfigured( "Please, use django-filer>=1.1.1 to get drag-n-drop support") filer_response = filer_ajax_upload(request, folder_id=None) if filer_response.status_code != 200: return filer_response try: file_id = json.loads(filer_response.content)['file_id'] except ValueError: return HttpResponse(json.dumps( {'error': 'received non-JSON response from Filer'}), status=500, content_type='application/json') instance = self.model.objects.get(pk=pk) instance.file_id = file_id instance.save() return filer_response
def ajax_upload(request, folder_id=None): """Disallow unsorted uploads.""" if folder_id is None: return JsonResponse({"error": _("Unsorted uploads are not allowed.")}, status=403) return filer_ajax_upload(request, folder_id=folder_id)
def ajax_upload(self, request, pk): """ Handle drag-n-drop uploads. Call original 'ajax_upload' Filer view, parse response and update plugin instance file_id from it. Send original response back. """ if not callable(filer_ajax_upload): # Do not try to handle request if we were unable to # import Filer view. raise ImproperlyConfigured( 'Please use django-filer>=1.1.1 to get drag & drop support.' ) filer_response = filer_ajax_upload(request, folder_id=None) if filer_response.status_code != 200: return filer_response try: file_id = json.loads(filer_response.content)['file_id'] except ValueError: return HttpResponse( json.dumps( {'error': 'Received non-JSON response from django Filer.'} ), status=500, content_type='application/json') instance = self.model.objects.get(pk=pk) instance.file_id = file_id instance.save() return filer_response