mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-15 07:34:27 -04:00
show CONSTANTS in separate section of django admin config
This commit is contained in:
parent
ea81f2fc14
commit
aa282daadf
1 changed files with 32 additions and 6 deletions
|
@ -39,6 +39,7 @@ from ..config import (
|
||||||
USER_CONFIG,
|
USER_CONFIG,
|
||||||
SAVE_ARCHIVE_DOT_ORG,
|
SAVE_ARCHIVE_DOT_ORG,
|
||||||
PREVIEW_ORIGINALS,
|
PREVIEW_ORIGINALS,
|
||||||
|
CONSTANTS,
|
||||||
)
|
)
|
||||||
from ..logging_util import printable_filesize
|
from ..logging_util import printable_filesize
|
||||||
from ..main import add
|
from ..main import add
|
||||||
|
@ -502,6 +503,8 @@ class HealthCheckView(View):
|
||||||
|
|
||||||
|
|
||||||
def find_config_section(key: str) -> str:
|
def find_config_section(key: str) -> str:
|
||||||
|
if key in CONSTANTS:
|
||||||
|
return 'CONSTANT'
|
||||||
matching_sections = [
|
matching_sections = [
|
||||||
name for name, opts in CONFIG_SCHEMA.items() if key in opts
|
name for name, opts in CONFIG_SCHEMA.items() if key in opts
|
||||||
]
|
]
|
||||||
|
@ -550,20 +553,33 @@ def live_config_list_view(request: HttpRequest, **kwargs) -> TableContext:
|
||||||
rows['Key'].append(ItemLink(key, key=key))
|
rows['Key'].append(ItemLink(key, key=key))
|
||||||
rows['Type'].append(mark_safe(f'<code>{find_config_type(key)}</code>'))
|
rows['Type'].append(mark_safe(f'<code>{find_config_type(key)}</code>'))
|
||||||
rows['Value'].append(mark_safe(f'<code>{CONFIG[key]}</code>') if key_is_safe(key) else '******** (redacted)')
|
rows['Value'].append(mark_safe(f'<code>{CONFIG[key]}</code>') if key_is_safe(key) else '******** (redacted)')
|
||||||
rows['Default'].append(mark_safe(f'<a href="https://github.com/search?q=repo%3AArchiveBox%2FArchiveBox+path%3Aconfig.py+%27{key}%27&type=code"><code style="text-decoration: underline">{find_config_default(key) or "See here..."}</code></a>'))
|
rows['Default'].append(mark_safe(f'<a href="https://github.com/search?q=repo%3AArchiveBox%2FArchiveBox+path%3Aconfig.py+{key}&type=code"><code style="text-decoration: underline">{find_config_default(key) or "See here..."}</code></a>'))
|
||||||
# rows['Documentation'].append(mark_safe(f'Wiki: <a href="https://github.com/ArchiveBox/ArchiveBox/wiki/Configuration#{key.lower()}">{key}</a>'))
|
# rows['Documentation'].append(mark_safe(f'Wiki: <a href="https://github.com/ArchiveBox/ArchiveBox/wiki/Configuration#{key.lower()}">{key}</a>'))
|
||||||
rows['Aliases'].append(', '.join(CONFIG_SCHEMA[section][key].get('aliases', [])))
|
rows['Aliases'].append(', '.join(CONFIG_SCHEMA[section][key].get('aliases', [])))
|
||||||
|
|
||||||
section = 'DYNAMIC'
|
section = 'DYNAMIC'
|
||||||
for key in DYNAMIC_CONFIG_SCHEMA.keys():
|
for key in DYNAMIC_CONFIG_SCHEMA.keys():
|
||||||
|
if key in CONSTANTS:
|
||||||
|
continue
|
||||||
rows['Section'].append(section) # section.replace('_', ' ').title().replace(' Config', '')
|
rows['Section'].append(section) # section.replace('_', ' ').title().replace(' Config', '')
|
||||||
rows['Key'].append(ItemLink(key, key=key))
|
rows['Key'].append(ItemLink(key, key=key))
|
||||||
rows['Type'].append(mark_safe(f'<code>{find_config_type(key)}</code>'))
|
rows['Type'].append(mark_safe(f'<code>{find_config_type(key)}</code>'))
|
||||||
rows['Value'].append(mark_safe(f'<code>{CONFIG[key]}</code>') if key_is_safe(key) else '******** (redacted)')
|
rows['Value'].append(mark_safe(f'<code>{CONFIG[key]}</code>') if key_is_safe(key) else '******** (redacted)')
|
||||||
rows['Default'].append(mark_safe(f'<a href="https://github.com/search?q=repo%3AArchiveBox%2FArchiveBox+path%3Aconfig.py+%27{key}%27&type=code"><code style="text-decoration: underline">{find_config_default(key) or "See here..."}</code></a>'))
|
rows['Default'].append(mark_safe(f'<a href="https://github.com/search?q=repo%3AArchiveBox%2FArchiveBox+path%3Aconfig.py+{key}&type=code"><code style="text-decoration: underline">{find_config_default(key) or "See here..."}</code></a>'))
|
||||||
# rows['Documentation'].append(mark_safe(f'Wiki: <a href="https://github.com/ArchiveBox/ArchiveBox/wiki/Configuration#{key.lower()}">{key}</a>'))
|
# rows['Documentation'].append(mark_safe(f'Wiki: <a href="https://github.com/ArchiveBox/ArchiveBox/wiki/Configuration#{key.lower()}">{key}</a>'))
|
||||||
rows['Aliases'].append(ItemLink(key, key=key) if key in USER_CONFIG else '')
|
rows['Aliases'].append(ItemLink(key, key=key) if key in USER_CONFIG else '')
|
||||||
|
|
||||||
|
section = 'CONSTANT'
|
||||||
|
for key in CONSTANTS.keys():
|
||||||
|
rows['Section'].append(section) # section.replace('_', ' ').title().replace(' Config', '')
|
||||||
|
rows['Key'].append(ItemLink(key, key=key))
|
||||||
|
rows['Type'].append(mark_safe(f'<code>{find_config_type(key)}</code>'))
|
||||||
|
rows['Value'].append(mark_safe(f'<code>{CONFIG[key]}</code>') if key_is_safe(key) else '******** (redacted)')
|
||||||
|
rows['Default'].append(mark_safe(f'<a href="https://github.com/search?q=repo%3AArchiveBox%2FArchiveBox+path%3Aconfig.py+{key}&type=code"><code style="text-decoration: underline">{find_config_default(key) or "See here..."}</code></a>'))
|
||||||
|
# rows['Documentation'].append(mark_safe(f'Wiki: <a href="https://github.com/ArchiveBox/ArchiveBox/wiki/Configuration#{key.lower()}">{key}</a>'))
|
||||||
|
rows['Aliases'].append(ItemLink(key, key=key) if key in USER_CONFIG else '')
|
||||||
|
|
||||||
|
|
||||||
return TableContext(
|
return TableContext(
|
||||||
title="Computed Configuration Values",
|
title="Computed Configuration Values",
|
||||||
table=rows,
|
table=rows,
|
||||||
|
@ -576,12 +592,20 @@ def live_config_value_view(request: HttpRequest, key: str, **kwargs) -> ItemCont
|
||||||
|
|
||||||
aliases = USER_CONFIG.get(key, {}).get("aliases", [])
|
aliases = USER_CONFIG.get(key, {}).get("aliases", [])
|
||||||
|
|
||||||
|
if key in CONSTANTS:
|
||||||
|
section_header = mark_safe(f'[CONSTANTS] <b><code style="color: lightgray">{key}</code></b> <small>(read-only, hardcoded by ArchiveBox)</small>')
|
||||||
|
elif key in USER_CONFIG:
|
||||||
|
section_header = mark_safe(f'data / ArchiveBox.conf [{find_config_section(key)}] <b><code style="color: lightgray">{key}</code></b>')
|
||||||
|
else:
|
||||||
|
section_header = mark_safe(f'[DYNAMIC CONFIG] <b><code style="color: lightgray">{key}</code></b> <small>(read-only, calculated at runtime)</small>')
|
||||||
|
|
||||||
|
|
||||||
return ItemContext(
|
return ItemContext(
|
||||||
slug=key,
|
slug=key,
|
||||||
title=key,
|
title=key,
|
||||||
data=[
|
data=[
|
||||||
{
|
{
|
||||||
"name": mark_safe(f'data / ArchiveBox.conf [{find_config_section(key)}] <b><code style="color: lightgray">{key}</code></b>' if key in USER_CONFIG else f'[DYNAMIC CONFIG] <b><code style="color: lightgray">{key}</code></b> <small>(calculated at runtime)</small>'),
|
"name": section_header,
|
||||||
"description": None,
|
"description": None,
|
||||||
"fields": {
|
"fields": {
|
||||||
'Key': key,
|
'Key': key,
|
||||||
|
@ -596,14 +620,16 @@ def live_config_value_view(request: HttpRequest, key: str, **kwargs) -> ItemCont
|
||||||
</span>
|
</span>
|
||||||
'''),
|
'''),
|
||||||
'Type': mark_safe(f'''
|
'Type': mark_safe(f'''
|
||||||
<a href="https://github.com/search?q=repo%3AArchiveBox%2FArchiveBox+path%3Aconfig.py+%27{key}%27&type=code">
|
<a href="https://github.com/search?q=repo%3AArchiveBox%2FArchiveBox+path%3Aconfig.py+{key}&type=code">
|
||||||
See full definition in <code>archivebox/config.py</code>...
|
See full definition in <code>archivebox/config.py</code>...
|
||||||
</a>
|
</a>
|
||||||
'''),
|
'''),
|
||||||
'Value': mark_safe(f'''
|
'Value': mark_safe(f'''
|
||||||
{'<b style="color: red">Value is redacted for your security. (Passwords, secrets, API tokens, etc. cannot be viewed in the Web UI)</b><br/><br/>' if not key_is_safe(key) else ''}
|
{'<b style="color: red">Value is redacted for your security. (Passwords, secrets, API tokens, etc. cannot be viewed in the Web UI)</b><br/><br/>' if not key_is_safe(key) else ''}
|
||||||
Default: <a href="https://github.com/search?q=repo%3AArchiveBox%2FArchiveBox+path%3Aconfig.py+%27{key}%27&type=code">
|
<br/><hr/><br/>
|
||||||
<code>{find_config_default(key) or 'See 1here...'}</code>
|
Default:
|
||||||
|
<a href="https://github.com/search?q=repo%3AArchiveBox%2FArchiveBox+path%3Aconfig.py+{key}&type=code">
|
||||||
|
<code>{find_config_default(key) or '↗️ See in ArchiveBox source code...'}</code>
|
||||||
</a>
|
</a>
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
<p style="display: {"block" if key in USER_CONFIG else "none"}">
|
<p style="display: {"block" if key in USER_CONFIG else "none"}">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue