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'] }} + + + + + + + Inputs + + + Name + Description + + + + {% for input_ in data['inputs'] %} + + {{ input_['id'] }} + {{ input_['title'] }} + + {{ input_['description'] | striptags | truncate }} + + + {% endfor %} + + + + + Links + + {% for link in data['links'] %} + + + {{ link['title'] }} ({{ link['type'] }}) + + + {% endfor %} + + +{% 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 + + + + + Processes + + + Name + Description + + + + {% for p in data['processes'] %} + + + + {{ p['title'] | striptags | truncate }} + + + {{ p['description'] | striptags | truncate }} + + + {% endfor %} + + + + + +{% 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 + Links diff --git a/pygeoapi/util.py b/pygeoapi/util.py index 1ed638a..abeda93 100644 --- a/pygeoapi/util.py +++ b/pygeoapi/util.py @@ -47,3 +47,23 @@ def get_url(scheme, host, port, basepath): url = '{}{}'.format(url, basepath) return url + + +def str2bool(value): + """ + helper function to return Python boolean + type (source: https://stackoverflow.com/a/715468) + + :param value: value to be evaluated + + :returns: `bool` of whether the value is boolean-ish + """ + + value2 = False + + if isinstance(value, bool): + value2 = value + else: + value2 = value.lower() in ('yes', 'true', 't', '1', 'on') + + return value2