#########
Configure
#########

Here is the list of Django settings for `django-downloadview`.


**************
INSTALLED_APPS
**************

There is no need to register this application in ``INSTALLED_APPS``.


******************
MIDDLEWARE
******************

If you plan to setup :doc:`reverse-proxy optimizations </optimizations/index>`,
add ``django_downloadview.SmartDownloadMiddleware`` to ``MIDDLEWARE``.
It is a response middleware. Move it after middlewares that compute the
response content such as gzip middleware.

Example:

.. literalinclude:: /../demo/demoproject/settings.py
   :language: python
   :start-after: BEGIN middlewares
   :end-before: END middlewares


********************
DEFAULT_FILE_STORAGE
********************

django-downloadview offers a built-in signed file storage, which cryptographically
signs requested file URLs with the Django's built-in TimeStampSigner.

To utilize the signed storage views you can configure

.. code:: python

   DEFAULT_FILE_STORAGE='django_downloadview.storage.SignedStorage'

The signed file storage system inserts a ``X-Signature`` header to the requested file
URLs, and they can then be verified with the supplied ``signature_required`` wrapper function:

.. code:: python

   from django.conf.urls import url, url_patterns

   from django_downloadview import ObjectDownloadView
   from django_downloadview.decorators import signature_required

   from demoproject.download.models import Document  # A model with a FileField

   # ObjectDownloadView inherits from django.views.generic.BaseDetailView.
   download = ObjectDownloadView.as_view(model=Document, file_field='file')

    urlpatterns = [
        path('download/<str:slug>/', signature_required(download)),
    ]

Make sure to test the desired functionality after configuration.

***************************
DOWNLOADVIEW_URL_EXPIRATION
***************************

Number of seconds signed download URLs are valid before expiring.

Default value for this flag is None and URLs never expire.

********************
DOWNLOADVIEW_BACKEND
********************

This setting is used by
:class:`~django_downloadview.middlewares.SmartDownloadMiddleware`.
It is the import string of a callable (typically a class) of an optimization
backend (typically a :class:`~django_downloadview.BaseDownloadMiddleware`
subclass).

Example:

.. literalinclude:: /../demo/demoproject/settings.py
   :language: python
   :start-after: BEGIN backend
   :end-before: END backend

See :doc:`/optimizations/index` for a list of available backends (middlewares).

When ``django_downloadview.SmartDownloadMiddleware`` is in your
``MIDDLEWARE``, this setting must be explicitely configured (no default
value). Else, you can ignore this setting.


******************
DOWNLOADVIEW_RULES
******************

This setting is used by
:class:`~django_downloadview.middlewares.SmartDownloadMiddleware`.
It is a list of positional arguments or keyword arguments that will be used to
instanciate class mentioned as ``DOWNLOADVIEW_BACKEND``.

Each item in the list can be either a list of positional arguments, or a
dictionary of keyword arguments. One item cannot contain both positional and
keyword arguments.

Here is an example containing one rule using keyword arguments:

.. literalinclude:: /../demo/demoproject/settings.py
   :language: python
   :start-after: BEGIN rules
   :end-before: END rules

See :doc:`/optimizations/index` for details about builtin backends
(middlewares) and their options.

When ``django_downloadview.SmartDownloadMiddleware`` is in your
``MIDDLEWARE``, this setting must be explicitely configured (no default
value). Else, you can ignore this setting.
