Skip to content

Commit

Permalink
Add samples python code to integrate a WAVES form
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylvain Milanesi committed Nov 16, 2018
1 parent 7626bc5 commit f9b6efd
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions docs/dev_doc/sample_code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ Authenticate with token
Some WAVES API entries require to be authenticated (jobs list, job details, job submission). Token are given by the administrator.

.. code-block:: python
client = Client(decoders=decoders,
auth=auth.TokenAuthentication(
token="6241961ef45e4bbe7bb01a05f938ed9f0f2a3926",
Expand All @@ -65,6 +64,42 @@ Some WAVES API entries require to be authenticated (jobs list, job details, job
print(job_details['updated'])
Integrate a WAVES service form
------------------------------

You've got a website and you want your visitors could submit jobs? The better way for this is to add in your website using API.
Here, you're supposed to know there is a service named "sample_service" defined on demo WAVES instance (as you see in serviceList above).

.. code-block:: python
from coreapi import Client, auth
from coreapi.codecs import CoreJSONCodec, JSONCodec, TextCodec
decoders = [JSONCodec(), CoreJSONCodec(), TextCodec()]
client = Client(decoders=decoders)
document = client.get('http://waves.demo.atgc-montpellier.fr/waves/api/schema')
wavesform = client.action(document, ['services', 'form'], params={"service_app_name": 'sample_service'}, validate=False, encoding='multipart/form-data')
Now, you just render this form into your template (ex. in a django tpl).

.. warning::
Don't forget to add forms.css and services.js from your waves instance as in this sample.

.. code-block:: django
{% block head %}
{% addtoblock "waves_forms_css" %} <link rel="stylesheet" href="http://waves.demo.atgc-montpellier.fr/static/waves/css/forms.css">{% endaddtoblock %}
{% endblock %}
{% block main %}
<!-- Import the web form as is -->
{{ wavesform|safe }}
{% endblock main %}
{% block footer %}
{% addtoblock "js" %}
<script src="http://waves.demo.atgc-montpellier.fr/static/waves/js/services.js"></script>
{% endaddtoblock %}
{% endblock footer %}
Create a job
------------

Expand Down Expand Up @@ -92,4 +127,3 @@ Inputs are defined by expected inputs of the "sample_service". Be aware, "valida
job_list = client.action(document, ['jobs', 'list'])
print(job_list)

0 comments on commit f9b6efd

Please sign in to comment.