Skip to content

Commit 1f7f01a

Browse files
committed
Fixed #76 to print license text once in the attribrition output.
1 parent 78330e9 commit 1f7f01a

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

about_code_tool/about.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,16 @@ def notice_text(self):
929929

930930
return "" # Returns empty string if the notice file does not exist
931931

932+
def dje_license(self):
933+
"""
934+
Return the dje_license value if the dje_license field exists
935+
"""
936+
try:
937+
return self.parsed['dje_license']
938+
except Exception as e:
939+
pass
940+
941+
return "" # Returns empty string if the dje_license key does not exist
932942

933943
class AboutCollector(object):
934944
"""
@@ -1071,15 +1081,20 @@ def generate_attribution(self, template_path='templates/default.html',
10711081
validated_fields = []
10721082
license_text = []
10731083
notice_text = []
1084+
unique_license = []
10741085
for about_object in self:
10751086
if not limit_to or about_object.about_resource_path in limit_to:
10761087
validated_fields.append(about_object.validated_fields)
1077-
license_text.append(about_object.license_text())
10781088
notice_text.append(about_object.notice_text())
1089+
if not about_object.dje_license() in unique_license \
1090+
and not about_object.dje_license() == None:
1091+
unique_license.append(about_object.dje_license())
1092+
license_text.append(about_object.license_text())
10791093

10801094
return template.render(about_objects=validated_fields,
10811095
license_texts=license_text,
1082-
notice_texts=notice_text)
1096+
notice_texts=notice_text,
1097+
unique_licenses=unique_license)
10831098

10841099

10851100
USAGE_SYNTAX = """\

about_code_tool/templates/default.html

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ <h3 class="component-name">{{ about_object.name }}{% if about_object.version %}
5555
{% endif %}
5656
{% if about_object.dje_license %}
5757
<p>Full text of
58-
<a class="{{ about_object.dje_license }}" href="#component-license-{{ loop.index0 }}">
58+
<a class="{{ about_object.dje_license }}" href="#component-license-{{ about_object.dje_license }}">
5959
{{ about_object.dje_license }}
6060
</a>
6161
is available at the end of this document.</p>
@@ -65,12 +65,10 @@ <h3 class="component-name">{{ about_object.name }}{% if about_object.version %}
6565
<hr>
6666

6767
<h3>Licenses Used in This Product</h3>
68-
{% for index in range(about_objects | count) %}
69-
{% if about_objects[index].dje_license %}
70-
<h3 id="component-license-{{ index }}">{{ about_objects[index].dje_license }}</h3>
71-
<pre>{{ license_texts[index] }}</pre>
72-
{% endif %}
73-
{% endfor %}
68+
{% for index in range(unique_licenses | count) %}
69+
<h3 id="component-license-{{ unique_licenses[index] }}">{{ unique_licenses[index] }}</h3>
70+
<pre>{{ license_texts[index] }}</pre>
71+
{% endfor %}
7472
<h3><a id="End">End</a></h3>
7573
</body>
7674
</html>

0 commit comments

Comments
 (0)