django-downloadview/demo
2013-05-06 16:50:47 +02:00
..
demoproject Refs #32 - Respect 'attachment' argument in X-Accel optimization. 2013-05-06 16:50:47 +02:00
README Refs #16 - Improved documentation for Nginx optimizations (references to demo project). Refs #18 - Moved temporary_media_root utility from demoproject.download.tests to django_downloadview.test. 2012-12-10 11:05:28 +01:00
setup.py Improved testing. Fixed 'make documentation'. 2012-08-27 18:27:00 +02:00

############
Demo project
############

The :file:`demo/` folder holds a demo project to illustrate django-downloadview
usage.


***********************
Browse demo code online
***********************

See `demo folder in project's repository`_.


***************
Deploy the demo
***************

System requirements:

* `Python`_ version 2.6 or 2.7, available as ``python`` command.
  
  .. note::

     You may use `Virtualenv`_ to make sure the active ``python`` is the right
     one.

* ``make`` and ``wget`` to use the provided :file:`Makefile`.

Execute:

.. code-block:: sh

   git clone git@github.com:benoitbryon/django-downloadview.git
   cd django-downloadview/
   make demo

It installs and runs the demo server on localhost, port 8000. So have a look
at http://localhost:8000/

.. note::

   If you cannot execute the Makefile, read it and adapt the few commands it
   contains to your needs.

Browse and use :file:`demo/demoproject/` as a sandbox.


*********************************
Base example provided in the demo
*********************************

In the "demoproject" project, there is an application called "download".

:file:`demo/demoproject/settings.py`:

.. literalinclude:: ../demo/demoproject/settings.py
   :language: python
   :lines: 33-49
   :emphasize-lines: 44

This application holds a ``Document`` model.

:file:`demo/demoproject/download/models.py`:

.. literalinclude:: ../demo/demoproject/download/models.py
   :language: python 

.. note::

   The ``storage`` is the default one, i.e. it uses ``settings.MEDIA_ROOT``.
   Combined to this ``upload_to`` configuration, files for ``Document`` model
   live in :file:`var/media/document/` folder, relative to your
   django-downloadview clone root.

There is a download view named "download_document" for this model:

:file:`demo/demoproject/download/urls.py`:

.. literalinclude:: ../demo/demoproject/download/urls.py
   :language: python

As is, Django is to serve the files, i.e. load chunks into memory and stream
them.


**********
References
**********

.. target-notes::

.. _`demo folder in project's repository`:
   https://github.com/benoitbryon/django-downloadview/tree/master/demo/demoproject/

.. _`Python`: http://python.org
.. _`Virtualenv`: http://virtualenv.org