64
64
65
65
from pygeoapi .util import (
66
66
CrsTransformSpec , TEMPLATES , UrlPrefetcher , dategetter ,
67
- filter_dict_by_key_value , get_api_rules , get_base_url ,
68
- get_provider_by_type , get_provider_default , get_typed_value ,
67
+ filter_dict_by_key_value , filter_providers_by_type , get_api_rules ,
68
+ get_base_url , get_provider_by_type , get_provider_default , get_typed_value ,
69
69
get_crs_from_uri , get_supported_crs_list , render_j2_template , to_json
70
70
)
71
71
@@ -686,7 +686,8 @@ def get_exception(self, status, headers, format_, code,
686
686
if format_ == F_HTML :
687
687
headers ['Content-Type' ] = FORMAT_TYPES [F_HTML ]
688
688
content = render_j2_template (
689
- self .config , 'exception.html' , exception , SYSTEM_LOCALE )
689
+ self .tpl_config , self .config ['server' ]['templates' ],
690
+ 'exception.html' , exception , SYSTEM_LOCALE )
690
691
else :
691
692
content = to_json (exception , self .pretty_print )
692
693
@@ -710,12 +711,13 @@ def get_format_exception(self, request) -> Tuple[dict, int, str]:
710
711
HTTPStatus .BAD_REQUEST , headers ,
711
712
request .format , 'InvalidParameterValue' , msg )
712
713
713
- def get_collections_url (self ):
714
+ def get_collections_url (self ) -> str :
714
715
return f"{ self .base_url } /collections"
715
716
716
- def set_dataset_templates (self , dataset ):
717
- if 'templates' in self .config ['resources' ][dataset ]:
718
- self .tpl_config ['server' ]['templates' ] = self .config ['resources' ][dataset ]['templates' ] # noqa
717
+ def get_dataset_templates (self , dataset ) -> dict :
718
+ templates = self .config ['resources' ][dataset ].get ('templates' )
719
+
720
+ return templates or self .tpl_config ['server' ]['templates' ]
719
721
720
722
@staticmethod
721
723
def _create_crs_transform_spec (
@@ -904,24 +906,23 @@ def landing_page(api: API,
904
906
headers = request .get_response_headers (** api .api_headers )
905
907
if request .format == F_HTML : # render
906
908
907
- fcm ['processes' ] = False
908
- fcm ['stac' ] = False
909
- fcm ['collection' ] = False
910
-
911
- if filter_dict_by_key_value (api .config ['resources' ],
912
- 'type' , 'process' ):
913
- fcm ['processes' ] = True
909
+ for resource_type in ['collection' , 'process' , 'stac-collection' ]:
910
+ fcm [resource_type ] = False
914
911
915
- if filter_dict_by_key_value (api .config ['resources' ],
916
- 'type' , 'stac-collection' ):
917
- fcm ['stac' ] = True
912
+ found = filter_dict_by_key_value (api .config ['resources' ],
913
+ 'type' , resource_type )
914
+ if found :
915
+ fcm [resource_type ] = True
916
+ if resource_type == 'collection' : # check for tiles
917
+ for key , value in found .items ():
918
+ if filter_providers_by_type (value ['providers' ],
919
+ 'tile' ):
920
+ fcm ['tile' ] = True
918
921
919
- if filter_dict_by_key_value ( api . config [ 'resources' ],
920
- 'type' , 'collection' ):
921
- fcm [ 'collection' ] = True
922
+ content = render_j2_template (
923
+ api . tpl_config , api . config [ 'server' ][ 'templates' ],
924
+ 'landing_page.html' , fcm , request . locale )
922
925
923
- content = render_j2_template (api .tpl_config , 'landing_page.html' ,
924
- fcm , request .locale )
925
926
return headers , HTTPStatus .OK , content
926
927
927
928
if request .format == F_JSONLD :
@@ -951,8 +952,10 @@ def openapi_(api: API, request: APIRequest) -> Tuple[dict, int, str]:
951
952
data = {
952
953
'openapi-document-path' : path
953
954
}
954
- content = render_j2_template (api .tpl_config , template , data ,
955
- request .locale )
955
+ content = render_j2_template (
956
+ api .tpl_config , api .config ['server' ]['templates' ], template , data ,
957
+ request .locale )
958
+
956
959
return headers , HTTPStatus .OK , content
957
960
958
961
headers ['Content-Type' ] = 'application/vnd.oai.openapi+json;version=3.0' # noqa
@@ -999,8 +1002,10 @@ def conformance(api, request: APIRequest) -> Tuple[dict, int, str]:
999
1002
1000
1003
headers = request .get_response_headers (** api .api_headers )
1001
1004
if request .format == F_HTML : # render
1002
- content = render_j2_template (api .tpl_config , 'conformance.html' ,
1003
- conformance , request .locale )
1005
+ content = render_j2_template (
1006
+ api .tpl_config , api .config ['server' ]['templates' ],
1007
+ 'conformance.html' , conformance , request .locale )
1008
+
1004
1009
return headers , HTTPStatus .OK , content
1005
1010
1006
1011
return headers , HTTPStatus .OK , to_json (conformance , api .pretty_print )
@@ -1428,14 +1433,14 @@ def describe_collections(api: API, request: APIRequest,
1428
1433
if request .format == F_HTML : # render
1429
1434
fcm ['collections_path' ] = api .get_collections_url ()
1430
1435
if dataset is not None :
1431
- api .set_dataset_templates (dataset )
1432
- content = render_j2_template (api .tpl_config ,
1436
+ tpl_config = api .get_dataset_templates (dataset )
1437
+ content = render_j2_template (api .tpl_config , tpl_config ,
1433
1438
'collections/collection.html' ,
1434
1439
fcm , request .locale )
1435
1440
else :
1436
- content = render_j2_template (api . tpl_config ,
1437
- 'collections/index.html' ,
1438
- fcm , request .locale )
1441
+ content = render_j2_template (
1442
+ api . tpl_config , api . config [ 'server' ][ 'templates' ] ,
1443
+ 'collections/index.html' , fcm , request .locale )
1439
1444
1440
1445
return headers , HTTPStatus .OK , content
1441
1446
@@ -1520,14 +1525,14 @@ def get_collection_schema(api: API, request: Union[APIRequest, Any],
1520
1525
schema ['properties' ][k ]['x-ogc-role' ] = 'primary-instant'
1521
1526
1522
1527
if request .format == F_HTML : # render
1523
- api .set_dataset_templates (dataset )
1528
+ tpl_config = api .get_dataset_templates (dataset )
1524
1529
schema ['title' ] = l10n .translate (
1525
1530
api .config ['resources' ][dataset ]['title' ], request .locale )
1526
1531
1527
1532
schema ['collections_path' ] = api .get_collections_url ()
1528
1533
schema ['dataset_path' ] = f'{ api .get_collections_url ()} /{ dataset } '
1529
1534
1530
- content = render_j2_template (api .tpl_config ,
1535
+ content = render_j2_template (api .tpl_config , tpl_config ,
1531
1536
'collections/schema.html' ,
1532
1537
schema , request .locale )
1533
1538
0 commit comments