Skip to content

Commit

Permalink
Added first version of tutorial. Fixed errors in inst.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcohen02 committed Dec 3, 2018
1 parent 3be7fa6 commit cf16f87
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx-prompt',
]

# Add any paths that contain templates here, relative to this directory.
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ Welcome to django-drf-filepond's documentation!

introduction
installation
tutorial/tutorial
7 changes: 5 additions & 2 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ file (e.g. ``settings.py``)::
...

You will need to re-run ``python manage.py migrate`` to update the database
with the table(s) used by django-drf-filepond.

2. Set the temporary file upload location:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -37,7 +40,7 @@ variable to your settings file, e.g.::

import os
...
DJANGO_DRF_FILEPOND_UPLOAD_TMP = os.path.join(BASE_DIR, filepond-temp-uploads)
DJANGO_DRF_FILEPOND_UPLOAD_TMP = os.path.join(BASE_DIR, 'filepond-temp-uploads')
...

3. Include the app urls into your main url configuration
Expand All @@ -50,7 +53,7 @@ in ``urls.py``::
urlpatterns = [
...
url(r'^fp/', include('django_drf_filepond.urls'))
url(r'^fp/', include('django_drf_filepond.urls')),
]

On the client side, you need to set the endpoints of the ``process``,
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/filepond-jquery-example.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="Filepond jquery demo page for django-drf-filepond">

<title>Starter Template for Bootstrap</title>
<title>django-drf-filepond demo page</title>

<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
Expand Down
Binary file added docs/tutorial/images/filepond-demo-page.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
181 changes: 181 additions & 0 deletions docs/tutorial/tutorial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
Tutorial
========

This tutorial will walk you through the process of creating a basic
Django application that provides server-side functionality for
`filepond <https://pqina.nl/filepond/>`_ using the `django-drf-filepond <https://github.com/ImperialCollegeLondon/django-drf-filepond>`_ app.

A simple demo web page `filepond-jquery-example.html <https://github.com/ImperialCollegeLondon/django-drf-filepond/blob/master/docs/tutorial/filepond-jquery-example.html>`_ is provided for
you to use as a test front-end for the demo Django application built in
this tutorial. The web page uses filepond's jQuery adapter, loaded from a
CDN, and is based on the `Bootstrap <https://getbootstrap.com/>`_ library's
`starter template <https://getbootstrap.com/docs/4.1/examples/starter-template/>`_.

*NOTE: This tutorial assumes that you are using Python 3 and have `virtualenv <https://virtualenv.pypa.io/en/latest/>`_ installed*

The tutorial will walk you through the following steps:

1. Set up your environment - prepare an environment in which to undertake the tutorial
2. Creating the Django application - create a simple django application configured to include the django-drf-filepond app
3. Add the front-end demo web page
4. Test the service

1. Set up your environment
-------------------------

Create a directory in which to undertake this tutorial. For example, in
your home directory, create the directory ``drf-filepond-tutorial``

We'll refer to this directory as ``${TUTORIAL_DIR}`` throughout the rest
of the tutorial. If you're using a Linux or Mac OS platform with a bash
shell (or a Windows-based environment that provides a bash shell such as
`WSL <https://docs.microsoft.com/en-us/windows/wsl>`_) you can set the
environment variable ``TUTORIAL_DIR`` to point the tutorial directory, for
example:

.. prompt:: bash

export TUTORIAL_DIR=${HOME}/drf-filepond-tutorial

In ``${TUTORIAL_DIR}``, create a file named ``requirements.txt`` containing
the following content::

Django==2.1.3
django-drf-filepond==0.0.1


Now create a *virtualenv* in ``${TUTORIAL_DIR}``:

.. prompt:: bash

virtualenv --prompt=drf-filepond-tutorial env
source env/bin/activate

Your shell prompt should now have been modified to show
``[drf-filepond-tutorial]`` which shows that you're within the virtual
environment.

You can now install the dependencies:

.. prompt:: bash

pip install -r requirements.txt


Creating the Django application
-------------------------------

In ``${TUTORIAL_DIR}`` with the virtualenv created in step 1 activated,
use the *django-admin* command to create a new django project:

.. prompt:: bash

django-admin startproject drf_filepond_tutorial .

You should now see a ``manage.py`` file in your current directory as well as
a ``drf_filepond_tutorial`` directory containing some Python source files.

As described in the Configuration section of the django-drf-filepond
documentation, we'll now add the django-drf-filepond app to our Django
project and then create the database to support this app and other default
functionality within the Django project.

Open the file ``${TUTORIAL_DIR}/drf_filepond_tutorial/settings.py`` in an
editor.

At the end of the ``INSTALLED_APPS`` section, add ``'django_drf_filepond'``::

INSTALLED_APPS = [
...
'django.contrib.staticfiles',
'django_drf_filepond',
]

At the end of the file add a new configuration parameter::

DJANGO_DRF_FILEPOND_UPLOAD_TMP = os.path.join(BASE_DIR, 'filepond-temp-uploads')

Save and close the ``settings.py`` file.

Now open the ``${TUTORIAL_DIR}/drf_filepond_tutorial/urls.py`` file.

After the two existing import statements, add a new import statement so
that there are now three import statements as follows::

from django.contrib import admin
from django.urls import path
from django.conf.urls import url, include

To the ``urlpatterns`` list, add an additional entry to link in the filepond
server URLs such that the ``urlpatterns`` now look as follows::

urlpatterns = [
path('admin/', admin.site.urls),
url(r'^fp/', include('django_drf_filepond.urls')),
]

You can now create the database by running:

.. prompt:: bash

python manage.py migrate


3. Add the front-end demo web page
----------------------------------

We now have a very basic, but fully-configured Django project that will act
as a server for filepond. In order to test this, we need a filepond client.

The `filepond-jquery-example.html <https://github.com/ImperialCollegeLondon/django-drf-filepond/blob/master/docs/tutorial/filepond-jquery-example.html>`_
file in the ``docs/tutorial/`` directory of the `django-drf-filepond GitHub repository <https://github.com/ImperialCollegeLondon/django-drf-filepond>`_
provides a simple single-page filepond client using filepond's `jQuery adapter <https://github.com/pqina/jquery-filepond>`_.

We can now set up our Django project to serve this HTML file as a static
file and use it to test the server-side filepond support.

**NOTE: This approach uses Django's** `static file serving support <https://docs.djangoproject.com/en/2.1/howto/static-files/#serving-static-files-during-development>`_ **and it should not be used for production deployment.**

Create a directory called ``static`` in ${TUTORIAL_DIR}.

Place the ``filepond-jquery-example.html`` file in this directory.

Now open the ``${TUTORIAL_DIR}/drf_filepond_tutorial/urls.py`` file for
editing. We'll add a new URL mapping to allow access to static files placed
into the ``${TUTORIAL_DIR}/static/``. Add the following entry to the
``urlpatterns`` list::


url(r'^demo/(?P<path>.*)$', serve, {'document_root': os.path.join(settings.BASE_DIR,'static')}),

You will also need to add 3 new import statements to the set of existing
import statements::

import os
from django.views.static import serve
from django.conf import settings

4. Test the service
-------------------

You are now in a position to test the project that you've set up.

In the ``${TUTORIAL_DIR}`` directory, with the virtualenv that was created
in step 1 activated, start the Django development server:

.. prompt:: bash

python manage.py runserver


If there are any errors with your configuration, these will be shown in the
terminal when you attempt to start the development server.

You should now be able to open the demo page in your browser. Point the
browser to http://localhost:8000/demo/filepond-jquery-example.html and you
should see the demo page shown in the figure below:

.. image:: images/filepond-demo-page.png



2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ httpretty==0.9.6
shortuuid==0.5.0
sphinx==1.8.2
sphinx_rtd_theme==0.4.2
sphinx-prompt==1.0.0

0 comments on commit cf16f87

Please sign in to comment.