From cf83fd95a64d2b669b2d1277663e1fcd0d143866 Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Sat, 11 May 2019 08:04:13 -0400 Subject: [PATCH] add HTML pages for processes, add raw mode option for process execution --- pygeoapi/api.py | 30 +++++++++++++++++- pygeoapi/templates/collection.html | 6 ++-- pygeoapi/templates/process.html | 50 ++++++++++++++++++++++++++++++ pygeoapi/templates/processes.html | 37 ++++++++++++++++++++++ pygeoapi/templates/root.html | 4 +++ pygeoapi/util.py | 20 ++++++++++++ 6 files changed, 143 insertions(+), 4 deletions(-) create mode 100644 pygeoapi/templates/process.html create mode 100644 pygeoapi/templates/processes.html diff --git a/pygeoapi/api.py b/pygeoapi/api.py index 5eacfbb..f373ce2 100644 --- a/pygeoapi/api.py +++ b/pygeoapi/api.py @@ -38,6 +38,7 @@ from pygeoapi import __version__ from pygeoapi.log import setup_logger from pygeoapi.plugin import load_plugin, PLUGINS from pygeoapi.provider.base import ProviderConnectionError, ProviderQueryError +from pygeoapi.util import str2bool LOGGER = logging.getLogger(__name__) @@ -586,6 +587,16 @@ class API(object): headers_ = HEADERS.copy() + format_ = check_format(args, headers) + + if format_ is not None and format_ not in FORMATS: + exception = { + 'code': 'InvalidParameterValue', + 'description': 'Invalid format' + } + LOGGER.error(exception) + return headers_, 400, json.dumps(exception) + processes_config = self.config['processes'] if process is not None: @@ -612,6 +623,17 @@ class API(object): 'processes': processes } + if format_ == 'html': # render + headers_['Content-Type'] = 'text/html' + if process is not None: + response = _render_j2_template(self.config, 'process.html', + p.metadata) + else: + response = _render_j2_template(self.config, 'processes.html', + {'processes': processes}) + + return headers_, 200, response + return headers_, 200, json.dumps(response) def execute_process(self, headers, args, data, process): @@ -656,7 +678,13 @@ class API(object): try: outputs = p.execute(data_dict) - response['outputs'] = outputs + m = p.metadata + if 'raw' in args and str2bool(args['raw']): + headers_['Content-Type'] = \ + m['outputs'][0]['output']['formats'][0]['mimeType'] + response = outputs + else: + response['outputs'] = outputs return headers_, 201, json.dumps(response) except Exception as err: exception = { diff --git a/pygeoapi/templates/collection.html b/pygeoapi/templates/collection.html index f7adc1f..c652fd8 100644 --- a/pygeoapi/templates/collection.html +++ b/pygeoapi/templates/collection.html @@ -6,11 +6,11 @@ {% endblock %} {% block body %}
- +

{{ data['title'] }}

{{ data['description'] }}
- + Browse through the items of collection {{ data['title'] }}

Links

@@ -18,7 +18,7 @@ {% for link in data['links'] %}
  • - {{ link['title'] }} ({{ link['type'] }}) + {{ link['title'] }} ({{ link['type'] }})
  • {% endfor %} diff --git a/pygeoapi/templates/process.html b/pygeoapi/templates/process.html new file mode 100644 index 0000000..bca4a01 --- /dev/null +++ b/pygeoapi/templates/process.html @@ -0,0 +1,50 @@ +{% extends "base.html" %} +{% block title %}{{ super() }} {{ data['title'] }} {% endblock %} +{% block crumbs %}{{ super() }} +/ Processes +/ {{ data['title'] }} +{% endblock %} +{% block body %} +
    + +

    {{ data['title'] }}

    +
    {{ data['description'] }}
    +
    + +
    +
    +
    + + + + + + + + + + {% for input_ in data['inputs'] %} + + + + + + {% endfor %} + +
    Inputs
    NameDescription
    {{ input_['id'] }}{{ input_['title'] }} + {{ input_['description'] | striptags | truncate }} +
    +
    +
    +

    Links

    + +
    +{% endblock %} diff --git a/pygeoapi/templates/processes.html b/pygeoapi/templates/processes.html new file mode 100644 index 0000000..c7a7d15 --- /dev/null +++ b/pygeoapi/templates/processes.html @@ -0,0 +1,37 @@ +{% extends "base.html" %} +{% block title %}{{ super() }} Processes {% endblock %} +{% block crumbs %}{{ super() }} +/ Processes +{% endblock %} +{% block body %} +
    +

    Processes in this service

    + +
    +
    + + + + + + + + + + {% for p in data['processes'] %} + + + + + {% endfor %} + +
    Processes
    NameDescription
    + + {{ p['title'] | striptags | truncate }} + + {{ p['description'] | striptags | truncate }} +
    +
    +
    +
    +{% endblock %} diff --git a/pygeoapi/templates/root.html b/pygeoapi/templates/root.html index b3ce77e..a180180 100644 --- a/pygeoapi/templates/root.html +++ b/pygeoapi/templates/root.html @@ -54,6 +54,10 @@

    Collections

    View the collections in this service
    +
    +

    Processes

    + View the processes in this service +