Coverage for portality/ui/debug_toolbar.py: 96%
26 statements
« prev ^ index » next coverage.py v6.4.2, created at 2022-07-22 15:59 +0100
« prev ^ index » next coverage.py v6.4.2, created at 2022-07-22 15:59 +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)
39 config['DEBUG_TB_PANELS'] += (f'{BranchNamePanel.__module__}.{BranchNamePanel.__name__}',)
40 return config