Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.15.0 - default template according to business #56

4 changes: 4 additions & 0 deletions lyrebird_bugit/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def template():
cache.update_all_draft_file(templates)

last_selected_template = cache.get_selected_template()
if len(templates) == 1 and last_selected_template != templates[0]['path']:
last_selected_template = templates[0]['path']
cache.selected_template(last_selected_template, None)

selected_template_index = None
for index, template in enumerate(templates):
if template['path'] == last_selected_template:
Expand Down
12 changes: 12 additions & 0 deletions lyrebird_bugit/template_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,23 @@
return metadata_dir


def get_default_template():
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
bugit_workspace = application.config.get('bugit.workspace', '')
bugit_default_template = application.config.get('bugit.default_template', '')
Copy link
Member

@yumiguan yumiguan Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bugit_default_template = application.config.get('bugit.default_template')
if not bugit_default_template:
    return

bugit_workspace = application.config.get('bugit.workspace')
if not bugit_workspace:
    return

return Path(bugit_workspace) / Path(bugit_default_template)

template_path = Path(bugit_workspace + bugit_default_template)
if bugit_workspace and bugit_default_template and template_path.exists():
return template_path
return


def template_list():
template_list = []
default_template = get_default_template()
for template_file in get_workspace().iterdir():
if not template_file.name.endswith('.py'):
continue
if default_template and template_file != default_template:
continue
try:
logger.debug(f'Load template {template_file}')
template = imp.load_source(template_file.stem, str(template_file))
Expand Down
Loading