Coverage for portality / ui / debug_toolbar.py: 97%
31 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-05 00:09 +0100
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-05 00:09 +0100
1from flask_debugtoolbar import DebugToolbarExtension
2from flask_debugtoolbar.panels import DebugPanel
4from portality.lib import paths
7class BranchNamePanel(DebugPanel):
8 name = 'branch_name'
9 has_content = True
11 def get_branch_name(self):
12 _git_head_file = paths.get_project_root().joinpath('.git/HEAD')
13 if _git_head_file.is_file():
14 return (_git_head_file.read_text()
15 .strip().replace('ref: refs/heads/', '')
16 .replace('ref: ', ''))
17 return 'Unknown, git HEAD not found '
19 def nav_title(self):
20 return 'Branch name'
22 def title(self):
23 return 'Branch name'
25 def nav_subtitle(self):
26 return self.get_branch_name()
28 def url(self):
29 return ''
31 def content(self):
32 return f'<h1 style="font-size: 30px;">{self.get_branch_name()}</h1>'
35class DoajDebugToolbar(DebugToolbarExtension):
37 def _default_config(self, app):
38 config = super()._default_config(app)
40 # add branch name panel
41 config['DEBUG_TB_PANELS'] += (f'{BranchNamePanel.__module__}.{BranchNamePanel.__name__}',)
43 # remove env list panel if not enabled
44 key_env_list = 'flask_debugtoolbar.panels.config_vars.ConfigVarsDebugPanel'
45 panels = list(config['DEBUG_TB_PANELS'])
47 if not app.config.get('DEBUG_TB_ENV_LIST_ENABLED', False) and key_env_list in panels:
48 panels.remove(key_env_list)
49 config['DEBUG_TB_PANELS'] = tuple(panels)
51 return config