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

Fix Jinja2 undefined variables #417

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Run Integration Tests

on:
push:

pull_request:
types: [opened, reopened]

Expand Down
17 changes: 11 additions & 6 deletions CRISPResso2/CRISPRessoReports/CRISPRessoReport.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@
'''

import os
from jinja2 import Environment, FileSystemLoader, PackageLoader, ChoiceLoader
from jinja2 import Environment, FileSystemLoader, ChoiceLoader
from jinja_partials import generate_render_partial, render_partial
from CRISPResso2 import CRISPRessoShared

if CRISPRessoShared.is_C2Pro_installed():
from CRISPRessoPro import __version__ as CRISPRessoProVersion
import CRISPRessoPro
C2PRO_INSTALLED = True
else:
C2PRO_INSTALLED = False


def get_jinja_loader(_ROOT):
if CRISPRessoShared.is_C2Pro_installed():
return Environment(loader=ChoiceLoader([FileSystemLoader(os.path.join(_ROOT, 'CRISPRessoReports', 'templates')), PackageLoader('CRISPRessoPro', 'templates')]))
def get_jinja_loader(root):
if C2PRO_INSTALLED:
return Environment(
loader=ChoiceLoader([
FileSystemLoader(os.path.join(root, 'CRISPRessoReports', 'templates')),
FileSystemLoader(os.path.join(os.path.dirname(CRISPRessoPro.__file__), 'templates')),
]),
)
else:
return Environment(loader=FileSystemLoader(os.path.join(_ROOT, 'CRISPRessoReports', 'templates')))
return Environment(loader=FileSystemLoader(os.path.join(root, 'CRISPRessoReports', 'templates')))


def render_template(template_name, jinja2_env, **data):
Expand Down
8 changes: 2 additions & 6 deletions CRISPResso2/CRISPRessoReports/templates/report.html
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ <h5>Global splicing analysis</h5>
{# end of global coding sequence analysis #}

{# start hdr summary #}
{% if report_data['figures']['locs'][report_data.amplicons[0]]['plot_4g'] or 'plot_4g' in report_data['figures']['htmls'][amplicon_name] %}
{% if report_data['figures']['locs'][report_data.amplicons[0]]['plot_4g'] or 'plot_4g' in report_data['figures']['htmls'][report_data.amplicons[0]] %}
<div class='card text-center mb-2 breakinpage'>
<div class='card-header'>
{% if report_data.amplicons|length == 1 %} {# if only one amplicon #}
Expand All @@ -189,11 +189,7 @@ <h5>HDR summary report (all reads aligned to {{report_data.amplicons[0]}})</h5>
{% endif %}
</div>
<div class='card-body'>
{% if 'plot_4g' in report_data['figures']['htmls'][amplicon_name] %}
{{ report_data['figures']['htmls'][amplicon_name]['plot_4g']|safe }}
{% else %}
{{ render_partial('shared/partials/fig_reports.html', report_data=report_data, fig_name='plot_4g', amplicon_name=report_data.amplicons[0])}}
{% endif %}
{{ render_partial('shared/partials/fig_reports.html', report_data=report_data, fig_name='plot_4g', amplicon_name=report_data.amplicons[0])}}
</div>
</div>
{% endif %}
Expand Down
Loading