22# -*- coding: utf8 -*-
33
44# ============================================================================
5- # Copyright (c) 2013-2019 nexB Inc. http://www.nexb.com/ - All rights reserved.
5+ # Copyright (c) 2013-2020 nexB Inc. http://www.nexb.com/ - All rights reserved.
66# Licensed under the Apache License, Version 2.0 (the "License");
77# you may not use this file except in compliance with the License.
88# You may obtain a copy of the License at
3232from attributecode .licenses import COMMON_LICENSES
3333from attributecode .model import parse_license_expression
3434from attributecode .util import add_unc
35+ from attributecode .attrib_util import multi_sort
3536
3637
3738DEFAULT_TEMPLATE_FILE = os .path .join (
3839 os .path .dirname (os .path .realpath (__file__ )), '../../templates' , 'default_html.template' )
3940
4041
41- def generate (abouts , template = None , vartext_dict = None ):
42+ def generate (abouts , template = None , variables = None ):
4243 """
4344 Generate an attribution text from an `abouts` list of About objects, a
4445 `template` template text and a `variables` optional dict of extra
@@ -125,7 +126,7 @@ def generate(abouts, template=None, vartext_dict=None):
125126 license_name_to_license_key = license_name_to_license_key ,
126127 utcnow = utcnow ,
127128 tkversion = __version__ ,
128- vartext_dict = vartext_dict
129+ variables = variables
129130 )
130131 except Exception as e :
131132 lineno = getattr (e , 'lineno' , '' ) or ''
@@ -145,12 +146,13 @@ def check_template(template_string):
145146 message) if the template is invalid or None if it is valid.
146147 """
147148 try :
149+ jinja2 .filters .FILTERS ['multi_sort' ] = multi_sort
148150 jinja2 .Template (template_string )
149151 except (jinja2 .TemplateSyntaxError , jinja2 .TemplateAssertionError ) as e :
150152 return e .lineno , e .message
151153
152154
153- def generate_from_file (abouts , template_loc = DEFAULT_TEMPLATE_FILE , vartext_dict = None ):
155+ def generate_from_file (abouts , template_loc = DEFAULT_TEMPLATE_FILE , variables = None ):
154156 """
155157 Generate an attribution text from an `abouts` list of About objects, a
156158 `template_loc` template file location and a `variables` optional
@@ -163,7 +165,7 @@ def generate_from_file(abouts, template_loc=DEFAULT_TEMPLATE_FILE, vartext_dict=
163165 template_loc = add_unc (template_loc )
164166 with io .open (template_loc , encoding = 'utf-8' ) as tplf :
165167 tpls = tplf .read ()
166- return generate (abouts , template = tpls , vartext_dict = vartext_dict )
168+ return generate (abouts , template = tpls , variables = variables )
167169
168170
169171def generate_and_save (abouts , output_location , template_loc = None , variables = None ):
@@ -186,16 +188,10 @@ def generate_and_save(abouts, output_location, template_loc=None, variables=None
186188 str (special_char_in_expression ))
187189 errors .append (Error (ERROR , msg ))
188190
189- vartext_dict = {}
190- if variables :
191- keys = variables .keys ()
192- for k in keys :
193- vartext_dict [k ] = (variables [k ])[0 ]
194-
195191 rendering_error , rendered = generate_from_file (
196192 abouts ,
197193 template_loc = template_loc ,
198- vartext_dict = vartext_dict
194+ variables = variables
199195 )
200196
201197 if rendering_error :
0 commit comments