Skip to content

Commit

Permalink
Update HTML export
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenchrist committed Apr 16, 2024
1 parent 5ef47eb commit 4936e4c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
27 changes: 22 additions & 5 deletions datacontract/export/html_export.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import yaml
from jinja2 import Environment, PackageLoader, select_autoescape

from datacontract.model.data_contract_specification import \
Expand All @@ -7,15 +8,31 @@
def to_html(data_contract_spec: DataContractSpecification) -> str:
# Load templates from templates folder
file_loader = PackageLoader("datacontract", "templates")
env = Environment(loader=file_loader, autoescape=select_autoescape(
enabled_extensions=('html', 'xml'),
default_for_string=True,
))
env = Environment(
loader=file_loader,
autoescape=select_autoescape(
enabled_extensions=('html', 'xml'),
default_for_string=True,
)
)

# Load the required template
template = env.get_template('datacontract.html')

if data_contract_spec.quality is not None and isinstance(data_contract_spec.quality.specification, str):
quality_specification = data_contract_spec.quality.specification
elif data_contract_spec.quality is not None and isinstance(data_contract_spec.quality.specification, object):
if data_contract_spec.quality.type == "great-expectations":
quality_specification = yaml.dump(data_contract_spec.quality.specification, sort_keys=False, default_style = "|")
else:
quality_specification = yaml.dump(data_contract_spec.quality.specification, sort_keys=False)
else:
quality_specification = None

# Render the template with necessary data
html_string = template.render(datacontract=data_contract_spec)
html_string = template.render(
datacontract=data_contract_spec,
quality_specification=quality_specification
)

return html_string
4 changes: 2 additions & 2 deletions datacontract/templates/datacontract.html
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ <h1 class="text-base font-semibold leading-6 text-gray-900">

{# TODO add service levels #}

{% if datacontract.quality %}
{% if quality_specification %}
<section id="quality">
<div class="px-4 sm:px-0">
<h1 class="text-base font-semibold leading-6 text-gray-900">
Expand All @@ -421,7 +421,7 @@ <h1 class="text-base font-semibold leading-6 text-gray-900">
<div class="mt-2 overflow-hidden shadow sm:rounded-lg bg-white">
<div class="px-4 py-5 sm:px-6">
<div id="schema-specification">
<pre><code class="text-sm">{{ datacontract.quality.specification }}</code></pre>
<pre><code class="text-sm">{{ quality_specification }}</code></pre>
</div>
</div>
</div>
Expand Down

0 comments on commit 4936e4c

Please sign in to comment.