djangofloor.views

DjangoFloor utility views

Also define two functions:

  • read_file_in_chunks(): generate an iterator that reads a file object in chunks
  • send_file(): return an efficient django.http.response.HttpResponse for reading files
class djangofloor.views.IndexView(**kwargs)[source]

index view using the default bootstrap3 view. You can only override the default template or populate the context.

get(request, *args, **kwargs)[source]

single defined method

get_context(request)[source]

provide the template context

template_name = 'djangofloor/bootstrap3/index.html'
djangofloor.views.favicon(request)[source]

Redirect “/favicon.ico” to the favicon in the static files

djangofloor.views.index(request)[source]

Deprecated since version 1.0.

djangofloor.views.read_file_in_chunks(fileobj, chunk_size=32768)[source]

read a file object in chunks of the given size.

Return an iterator of data

Parameters:
  • fileobj
  • chunk_size (int) – max size of each chunk
djangofloor.views.robots(request)[source]

Basic robots file

djangofloor.views.send_file(filepath, mimetype=None, force_download=False)[source]

Send a local file. This is not a Django view, but a function that is called at the end of a view.

If settings.USE_X_SEND_FILE (mod_xsendfile is a mod of Apache), then return an empty HttpResponse with the correct header. The file is directly handled by Apache instead of Python. If settings.X_ACCEL_REDIRECT_ARCHIVE is defined (as a list of tuple (directory, alias_url)) and filepath is in one of the directories, return an empty HttpResponse with the correct header. This is only available with Nginx.

Otherwise, return a StreamingHttpResponse to avoid loading the whole file in memory.

Parameters:
  • filepath – absolute path of the file to send to the client.
  • mimetype – MIME type of the file (returned in the response header)
  • force_download – always force the client to download the file.
Return type:

django.http.response.StreamingHttpResponse or django.http.response.HttpResponse

djangofloor.views.signals(request)[source]

Generate a JS file with the list of signals. Also configure jQuery with a CSRF header for AJAX requests.