1
0
mirror of synced 2024-11-24 06:20:12 +01:00

Add config option for theme directory for easier overrides of CSS/favicon.

This commit is contained in:
Jennifer Taylor 2021-08-31 21:40:30 +00:00
parent 6ebc8de311
commit 83cf8fc9cb
10 changed files with 29 additions and 15 deletions

View File

@ -193,6 +193,10 @@ class Config(dict):
def cache_dir(self) -> str:
return os.path.abspath(str(self.get('cache_dir', '/tmp')))
@property
def theme(self) -> str:
return str(self.get('theme', 'default'))
@property
def event_log_duration(self) -> Optional[int]:
duration = self.get('event_log_duration')

View File

@ -235,6 +235,20 @@ def valid_pin(pin: str, type: str) -> bool:
return False
# Define useful functions for jnija2
def jinja2_any(lval: Optional[List[Any]], pull: str, equals: str) -> bool:
if lval is None:
return False
for entry in lval:
if entry[pull] == equals:
return True
return False
def jinja2_theme(filename: str) -> str:
return url_for('static', filename=f"{config.theme}/{filename}")
@app.context_processor
def navigation() -> Dict[str, Any]:
# Look up JSX components we should provide for every page load
@ -244,15 +258,6 @@ def navigation() -> Dict[str, Any]:
if re.search(r'\.react\.js$', f)
]
# Define useful functions for jnija2
def jinja2_any(lval: Optional[List[Any]], pull: str, equals: str) -> bool:
if lval is None:
return False
for entry in lval:
if entry[pull] == equals:
return True
return False
# Look up the logged in user ID.
try:
if g.userID is not None:
@ -262,6 +267,7 @@ def navigation() -> Dict[str, Any]:
return {
'components': components,
'any': jinja2_any,
'theme_url': jinja2_theme,
}
except AttributeError:
# If we are trying to render a 500 error and we couldn't even run the
@ -270,6 +276,7 @@ def navigation() -> Dict[str, Any]:
return {
'components': components,
'any': jinja2_any,
'theme_url': jinja2_theme,
}
pages: List[Dict[str, Any]] = []
@ -747,4 +754,5 @@ def navigation() -> Dict[str, Any]:
'navigation': pages,
'components': components,
'any': jinja2_any,
'theme_url': jinja2_theme,
}

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -3,12 +3,12 @@
{% if title %}
<title>{{ title }}</title>
{% endif %}
<link rel="icon" type="image/png" href="{{ url_for('static', filename='favicon.png') }}" />
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='site.css') }}" />
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='color.css') }}" />
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='form.css') }}" />
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='section.css') }}" />
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='table.css') }}" />
<link rel="icon" type="image/png" href="{{ theme_url('favicon.png') }}" />
<link rel="stylesheet" type="text/css" href="{{ theme_url('site.css') }}" />
<link rel="stylesheet" type="text/css" href="{{ theme_url('color.css') }}" />
<link rel="stylesheet" type="text/css" href="{{ theme_url('form.css') }}" />
<link rel="stylesheet" type="text/css" href="{{ theme_url('section.css') }}" />
<link rel="stylesheet" type="text/css" href="{{ theme_url('table.css') }}" />
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='jquery-confirm.css') }}" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="{{ url_for('static', filename='chart.bundle.min.js') }}"></script>

View File

@ -76,3 +76,5 @@ cache_dir: '/tmp'
# Number of seconds to preserve event logs before deleting them.
# Set to zero or delete to disable deleting logs.
event_log_duration: 2592000
# Frontend theme directory where sitewide CSS and favicon should be found.
theme: "default"