From f1b0ad1e305d1dfea227a9ad84be636188b0f49a Mon Sep 17 00:00:00 2001 From: Luis Aleixo Date: Fri, 12 May 2023 16:12:28 +0200 Subject: [PATCH] base urls definition --- app-config/docker-compose.yml | 2 -- app-config/openshift/deploymentconfig.yaml | 4 ---- caimira/apps/calculator/__init__.py | 23 +++++++++++++++++----- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/app-config/docker-compose.yml b/app-config/docker-compose.yml index a8a0782e..d9ddb34a 100644 --- a/app-config/docker-compose.yml +++ b/app-config/docker-compose.yml @@ -20,7 +20,6 @@ services: - APPLICATION_ROOT=/ - CAIMIRA_CALCULATOR_PREFIX=/calculator-cern - CAIMIRA_THEME=caimira/apps/templates/cern - - EXTRA_PAGES=[{"url_path":"/about","filename":"about.html.j2"},{"url_path":"/calculator-cern/user-guide","filename":"userguide.html.j2"}] user: ${CURRENT_UID} calculator-open-app: @@ -30,7 +29,6 @@ services: - APP_NAME=calculator-app - APPLICATION_ROOT=/ - CAIMIRA_CALCULATOR_PREFIX=/calculator-open - - EXTRA_PAGES=[{"url_path":"/about","filename":"about.html.j2"},{"url_path":"/calculator-open/user-guide","filename":"userguide.html.j2"}] user: ${CURRENT_UID} auth-service: diff --git a/app-config/openshift/deploymentconfig.yaml b/app-config/openshift/deploymentconfig.yaml index cda24258..e96d65a1 100644 --- a/app-config/openshift/deploymentconfig.yaml +++ b/app-config/openshift/deploymentconfig.yaml @@ -283,8 +283,6 @@ secretKeyRef: key: ARVE_API_KEY name: arve-api - - name: EXTRA_PAGES - value: '[{"url_path":"/about","filename":"about.html.j2"},{"url_path":"/calculator-cern/user-guide","filename":"userguide.html.j2"}]' image: '${PROJECT_NAME}/calculator-app' ports: - containerPort: 8080 @@ -362,8 +360,6 @@ value: / - name: CAIMIRA_CALCULATOR_PREFIX value: /calculator-open - - name: EXTRA_PAGES - value: '[{"url_path":"/about","filename":"about.html.j2"},{"url_path":"/calculator-open/user-guide","filename":"userguide.html.j2"}]' image: '${PROJECT_NAME}/calculator-app' ports: - containerPort: 8080 diff --git a/caimira/apps/calculator/__init__.py b/caimira/apps/calculator/__init__.py index 5f4ef9bd..eae04be7 100644 --- a/caimira/apps/calculator/__init__.py +++ b/caimira/apps/calculator/__init__.py @@ -359,18 +359,31 @@ def make_app( get_root_url = functools.partial(get_url, APPLICATION_ROOT) get_root_calculator_url = functools.partial(get_calculator_url, APPLICATION_ROOT, calculator_prefix) - urls: typing.List = [ + base_urls: typing.List = [ (get_root_url(r'/?'), LandingPage), - (get_root_url(r'/_c/(.*)'), CompressedCalculatorFormInputs), - (get_root_url(r'/static/(.*)'), StaticFileHandler, {'path': static_dir}), (get_root_calculator_url(r'/?'), CalculatorForm), (get_root_calculator_url(r'/report'), ConcentrationModel), + (get_root_calculator_url(r'/static/(.*)'), StaticFileHandler, {'path': calculator_static_dir}), + ] + + urls: typing.List = base_urls + [ + (get_root_url(r'/_c/(.*)'), CompressedCalculatorFormInputs), + (get_root_url(r'/static/(.*)'), StaticFileHandler, {'path': static_dir}), (get_root_calculator_url(r'/report-json'), ConcentrationModelJsonResponse), (get_root_calculator_url(r'/baseline-model/result'), StaticModel), (get_root_calculator_url(r'/api/arve/v1/(.*)/(.*)'), ArveData), (get_root_calculator_url(r'/cases/(.*)'), CasesData), - (get_root_calculator_url(r'/static/(.*)'), StaticFileHandler, {'path': calculator_static_dir}), + # Generic Pages + (get_root_url(r'/about'), GenericExtraPage, { + 'active_page': 'about', + 'filename': 'about.html.j2'}), + (get_root_calculator_url(r'/user-guide'), GenericExtraPage, { + 'active_page': 'calculator/user-guide', + 'filename': 'userguide.html.j2'}), ] + + interface: str = os.environ.get('CAIMIRA_THEME', '') + if interface != '' and (interface != '' or 'cern' not in interface): urls = list(filter(lambda i: i in base_urls, urls)) # Any extra generic page must be declared in the env. variable "EXTRA_PAGES" extra_pages: typing.Union[str, typing.List] = os.environ.get('EXTRA_PAGES', []) @@ -378,7 +391,7 @@ def make_app( try: pages = ast.literal_eval(extra_pages) # type: ignore except (SyntaxError, ValueError): - LOG.warning('Warning: There was a problem with the extra pages. Is the "EXTRA_PAGES" environment variable correctly defined?') + LOG.warning('Warning: There was a problem with the extra pages. Is the "EXTRA_PAGES" environment variable defined?') pass for extra in pages: