Skip to content

Commit

Permalink
Use same code for short logo as desktop logo
Browse files Browse the repository at this point in the history
  • Loading branch information
nonprofittechy committed Nov 15, 2023
1 parent dca6959 commit 8db8100
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 20 deletions.
27 changes: 7 additions & 20 deletions docassemble/AssemblyLine/data/questions/interview_list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ metadata:
In progress forms
short title: |
In progress forms
temporary session: True
temporary session: True
---
modules:
- .sessions
Expand Down Expand Up @@ -216,14 +216,16 @@ default screen parts:
% endif
</span>
<span class="al-title">
% if PAGE_TITLE:
<span class="title-row-1">${ PAGE_TITLE }</span>
% if LOGO_TITLE_ROW_1:
<span class="title-row-1">${ LOGO_TITLE_ROW_1 }</span>
% elif showifdef("AL_ORGANIZATION_TITLE"):
<span class="title-row-1">${ AL_ORGANIZATION_TITLE }</span>
% else:
<span class="title-row-1">${ get_config("app name", "CourtFormsOnline") }</span>
<span class="title-row-1">${ get_config("app name", "CourtFormsOnline") }</span>
% endif
% if PAGE_QUESTION:
% if LOGO_TITLE_ROW_2:
<span class="title-row-2">${ LOGO_TITLE_ROW_2 }</span>
% elif PAGE_QUESTION:
<span class="title-row-2">${ PAGE_QUESTION }</span>
% else:
<span class="title-row-2">${ all_variables(special='metadata').get('title','').rstrip() }</span>
Expand Down Expand Up @@ -390,20 +392,6 @@ code: |
---
########### Get customized text values from configuration file ###################################33
---
code: |
def config_with_language_fallback(config_key, top_level_config_key=None):
interview_list_config = get_config("assembly line",{}).get("interview list",{})
if interview_list_config.get(config_key):
if isinstance(interview_list_config.get(config_key), dict):
if get_language() in interview_list_config.get(config_key):
return interview_list_config.get(config_key)[get_language()]
else:
return next(iter(interview_list_config.get(config_key).values()), None)
else:
return interview_list_config.get(config_key)
else:
return get_config(top_level_config_key or config_key)
---
code: |
PAGE_TITLE = config_with_language_fallback("page title", "interview page title")
---
Expand Down Expand Up @@ -436,6 +424,5 @@ code: |
---
code: |
LOGO_TITLE_ROW_2 = config_with_language_fallback("logo title row 2")
---
code: al_sessions_to_exclude_from_interview_list = get_config("assembly line",{}).get("interview list",{}).get("exclude from interview list", get_config("assembly line",{}).get("exclude from interview list"))
37 changes: 37 additions & 0 deletions docassemble/AssemblyLine/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
DASet,
format_time,
get_config,
get_language,
get_default_timezone,
get_session_variables,
interview_menu,
Expand Down Expand Up @@ -52,6 +53,7 @@

__all__ = [
"al_session_store_default_filename",
"config_with_language_fallback",
"delete_interview_sessions",
"export_interview_variables",
"get_filtered_session_variables_string",
Expand Down Expand Up @@ -1270,3 +1272,38 @@ def is_valid_json(json_string: str) -> bool:
validation_error("Enter a valid JSON-formatted string")
return False
return True

def config_with_language_fallback(config_key:str, top_level_config_key:Optional[str]=None) -> Optional[str]:
"""Returns the value of a config key under `assembly line` `interview list` with options to fallback
to an alternative key at the top level of the global configuration.
Used in interview_list.yml to allow overriding some of the labels in the interview list
with options specified in the global configuration. top_level_config should be reserved
to handle backwards compatibility (e.g., changed location of some configuration keys)
Example configuration, showing both the single-string and language-specific string options:
assembly line:
interview list:
title:
en: In progress forms
es: Formularios en progreso
short title: My forms
Args:
config_key (str): The config key to look up. The config can be a single string or a dictionary with language keys.
top_level_config_key (str, optional): Optional, alternative top-level config key to look up. Defaults to None.
Returns:
str: The value of the config key, or the alternative key, or None.
"""
interview_list_config = get_config("assembly line",{}).get("interview list",{})
if interview_list_config.get(config_key):
if isinstance(interview_list_config.get(config_key), dict):
if get_language() in interview_list_config.get(config_key):
return interview_list_config.get(config_key)[get_language()]
else:
return next(iter(interview_list_config.get(config_key).values()), None)
else:
return interview_list_config.get(config_key)
else:
return get_config(top_level_config_key or config_key)

0 comments on commit 8db8100

Please sign in to comment.