views.py¶
Module containing a baseclass for all formviews and a function for serving files via the X-Sendfile directive.
Class and function definitions:
-
class
core.views.FormView(**kwargs)[source]¶ Bases:
django.views.generic.edit.FormViewBaseclass formview which automatically adds a ‘changed_by_user’ property to the form instance which is the logged in user.
Used for getting the logged in user from the view to model instance via a form.
-
get_form_kwargs()[source]¶ Automatically add the changed_by_user to the form kwargs. This is picked up in the baseclass form and set on the form itselves and later in the save method of the form to the model.
This way the self.request.user is pushed via a form to the model to be used in the audit trail.
-
-
core.views.xsendfileserve(request, *args, **kwargs)[source]¶ Serve static files below a given point in the directory structure.
Uses X-Sendfile to sent the file to the client via the webserver, allowing authentication for media files.
To use, put a URL pattern such as:
(r'^(?P<path>.*)$', 'apps.core.views.xsendfileserve', {'document_root' : '/path/to/my/files/'})
in your URLconf. You must provide the
document_rootparam. You may also setshow_indexestoTrueif you’d like to serve a basic index of the directory. This index view will use the template hardcoded below, but if you’d like to override it, you can create a template calledstatic/directory_index.html.Nginx default setup (include in sites-available config file(s)):
location /xsendmedia { internal; alias /full/path/to/remotecare/media; }