Skip to content

Commit 2770e61

Browse files
committed
Fixed #446
* Correct type * Provide information about the dictionaries that passed to jinja2 in the default template
1 parent f3d17e0 commit 2770e61

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

src/attributecode/attrib.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,21 @@ def generate(abouts, template=None, variables=None):
7272
license_file_key_and_license_key = {}
7373
# FIXME: This need to be simplified
7474
for about in abouts:
75-
# about.license_file.value is a OrderDict with license_text_name as
75+
# about.license_file.value is a OrderDict with license_file_name as
7676
# the key and the license text as the value
7777
if about.license_file:
78-
# We want to create a dictionary which have the license name as
78+
# We want to create a dictionary which have the license file name as
7979
# the key and license text as the value
8080
# The reason we want to use license file name as the key instead of the
8181
# license key is because there is a scenario such that the input only provide
8282
# license_file but not license_key
83-
for license_text_name in about.license_file.value:
84-
if not license_text_name in captured_license:
85-
captured_license.append(license_text_name)
86-
license_file_key = get_license_file_key(license_text_name)
87-
license_file_key_and_context[license_file_key] = about.license_file.value[license_text_name]
83+
for license_file_name in about.license_file.value:
84+
if not license_file_name in captured_license:
85+
captured_license.append(license_file_name)
86+
license_file_key = get_license_file_key(license_file_name)
87+
license_file_key_and_context[license_file_key] = about.license_file.value[license_file_name]
8888
sorted_license_file_key_and_context = collections.OrderedDict(sorted(license_file_key_and_context.items()))
89-
license_file_name_and_license_file_key[license_text_name] = license_file_key
89+
license_file_name_and_license_file_key[license_file_name] = license_file_key
9090

9191
lic_list = []
9292
lic_name_list = []
@@ -114,12 +114,12 @@ def generate(abouts, template=None, variables=None):
114114
# linking feature in the jinja2 template
115115
about.license_key.value = about.license_file.value.keys()
116116
lic_list = about.license_file.value.keys()
117-
117+
118118
lic_name_list = about.license_name.value
119119

120120
# The order of the license_name and key should be the same
121121
# The length for both list should be the same
122-
assert len(lic_name_list) == len(lic_list)
122+
assert len(lic_name_list) == len(lic_list)
123123

124124
# Map the license key to license name
125125
index_for_license_name_list = 0
@@ -142,18 +142,18 @@ def generate(abouts, template=None, variables=None):
142142
lic_name_expression = ' '.join(lic_name_expression_list)
143143

144144
# Add the license name expression string into the about object
145-
about.license_name_expression = lic_name_expression
145+
about.license_name_expression = lic_name_expression
146146

147147
# Get the current UTC time
148148
utcnow = datetime.datetime.utcnow()
149149
rendered = template.render(
150150
abouts=abouts, common_licenses=COMMON_LICENSES,
151151
license_file_key_and_context=sorted_license_file_key_and_context,
152+
license_file_key_and_license_key=license_file_key_and_license_key,
152153
license_file_name_and_license_file_key=license_file_name_and_license_file_key,
154+
license_key_and_license_file_name=license_key_and_license_file_name,
153155
license_key_and_license_name=license_key_and_license_name,
154156
license_name_and_license_key=license_name_and_license_key,
155-
license_key_and_license_file_name=license_key_and_license_file_name,
156-
license_file_key_and_license_key=license_file_key_and_license_key,
157157
utcnow=utcnow,
158158
tkversion=__version__,
159159
variables=variables

templates/default_html.template

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1-
<!doctype html>
1+
{#
2+
Some dictionary are provided for flexible usage. Those are
3+
4+
license_file_key_and_context
5+
license_file_key_and_license_key
6+
license_key_and_license_name
7+
license_key_and_license_file_name
8+
license_file_name_and_license_file_key
9+
license_name_and_license_key
10+
11+
The dictionary format consist of 2 variable parts.
12+
The first variable as a key, and the second variable as value.
13+
For instance,
14+
license_key_and_license_name looks like:
15+
{'gpl-2.0': 'GPL 2.0', 'apache-2.0': 'Apache 2.0'}
16+
license_key_and_license_file_name
17+
{'gpl-2.0': 'gpl-2.0.LICENSE', 'apache-2.0': 'apache-2.0.LICENSE'}
18+
19+
Note that the license_file_key is usually the same as the license_key (for non-custom license)
20+
See "get_license_file_key" in `attrib.py` for more information
21+
22+
#}<!doctype html>
223
<html>
324
<head>
425
<style type="text/css">
@@ -54,7 +75,7 @@
5475
{% endfor %}
5576
{% if about_object.license_file.value %}
5677
{% for lic_file_name in about_object.license_file.value %}
57-
{% if not license_file_name_and_key[lic_file_name] in common_licenses %}
78+
{% if not license_file_key_and_license_key[license_file_name_and_license_file_key[lic_file_name]] in common_licenses %}
5879
<pre>{{ about_object.license_file.value[lic_file_name] | e}}</pre>
5980
{% endif %}
6081
{% endfor %}

0 commit comments

Comments
 (0)