{#
   SPDX-FileCopyrightText: 2020 Mintlab B.V.

   SPDX-License-Identifier: EUPL-1.2
#}

{% extends "base_template.j2" %}
{% block template %}

def add_routes(config):
    """Add routes to pyramid application.

    :param config: pyramid config file
    :type config: Configurator
    """
    handlers = [{% for route in routes %}
        {
            "route": "{{ route.route }}",
            "handler": "{{ route.handler  }}",
            "method": "{{ route.method }}",
            "view": "{{ route.view }}",
            {%- if route.viewclass %}
            "viewclass": "{{ route.viewclass }}"
            {% endif %}
        },{% endfor %}
    ]

    for h in handlers:
        config.add_route(name=h["handler"], pattern=h["route"], request_method=h["method"])
        config.add_view(
            view=h["view"],
            route_name=h["handler"],
            request_method=h["method"],
        )
{% endblock %}
