Skip to content

Commit 3436baf

Browse files
committed
Fixed #78
Using a dictionary, license_dict{} , to replace the 2 lists: unique_license[] license_text[]
1 parent a9d8720 commit 3436baf

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

about_code_tool/about.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,20 +1093,18 @@ def generate_attribution(self, template_path='templates/default.html',
10931093

10941094
# We only need the fields names and values to render the template
10951095
validated_fields = []
1096-
license_text = []
10971096
notice_text = []
1098-
unique_license = []
1097+
license_dict = {}
10991098
for about_object in self:
11001099
if not limit_to or about_object.about_resource_path in limit_to:
11011100
validated_fields.append(about_object.validated_fields)
11021101
notice_text.append(about_object.notice_text())
11031102
dje_license_name = about_object.get_dje_license_name()
11041103
if dje_license_name:
1105-
if not dje_license_name in unique_license \
1104+
if not dje_license_name in license_dict \
11061105
and not dje_license_name == None:
11071106
if about_object.license_text():
1108-
unique_license.append(about_object.get_dje_license_name())
1109-
license_text.append(about_object.license_text())
1107+
license_dict[about_object.get_dje_license_name()] = about_object.license_text()
11101108
else:
11111109
msg = 'About resource: %s - license_text does not exist.'\
11121110
' License generation is skipped.'\
@@ -1115,10 +1113,9 @@ def generate_attribution(self, template_path='templates/default.html',
11151113
'dje_license',\
11161114
dje_license_name, msg))
11171115
elif about_object.get_license_text_file_name():
1118-
if not about_object.get_license_text_file_name() in unique_license:
1116+
if not about_object.get_license_text_file_name() in license_dict:
11191117
if about_object.license_text():
1120-
unique_license.append(about_object.get_license_text_file_name())
1121-
license_text.append(about_object.license_text())
1118+
license_dict[about_object.get_license_text_file_name()] = about_object.license_text()
11221119
else:
11231120
msg = 'About resource: %s - license_text does not exist.'\
11241121
' License generation is skipped.'\
@@ -1133,9 +1130,9 @@ def generate_attribution(self, template_path='templates/default.html',
11331130
msg))
11341131

11351132
return template.render(about_objects=validated_fields,
1136-
license_texts=license_text,
1137-
notice_texts=notice_text,
1138-
unique_licenses=unique_license)
1133+
license_keys=list(license_dict.keys()),
1134+
license_texts = list(license_dict.values()),
1135+
notice_texts=notice_text)
11391136

11401137
def get_genattrib_errors(self):
11411138
return self.genattrib_errors

about_code_tool/templates/default.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ <h3 class="component-name">{{ about_object.name }}{% if about_object.version %}
5353
{% elif about_object.notice_file %}
5454
<pre class="component-notice">{{ notice_texts[loop.index0] }}</pre>
5555
{% endif %}
56-
{% if about_object.dje_license in unique_licenses %}
56+
{% if about_object.dje_license in license_keys %}
5757
<p>Full text of
5858
<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>
62-
{% elif about_object.license_text_file in unique_licenses %}
62+
{% elif about_object.license_text_file in license_keys %}
6363
<p>Full text of
6464
<a class="{{ about_object.license_text_file }}" href="#component-license-{{ about_object.license_text_file }}">
6565
{{ about_object.license_text_file }}
@@ -71,8 +71,8 @@ <h3 class="component-name">{{ about_object.name }}{% if about_object.version %}
7171
<hr>
7272

7373
<h3>Licenses Used in This Product</h3>
74-
{% for index in range(unique_licenses | count) %}
75-
<h3 id="component-license-{{ unique_licenses[index] }}">{{ unique_licenses[index] }}</h3>
74+
{% for index in range(license_keys | count) %}
75+
<h3 id="component-license-{{ license_keys[index] }}">{{ license_keys[index] }}</h3>
7676
<pre>{{ license_texts[index] }}</pre>
7777
{% endfor %}
7878
<h3><a id="End">End</a></h3>

0 commit comments

Comments
 (0)