@@ -228,13 +228,14 @@ def clean_notes(pod_template):
228228 return bool (cleaned )
229229
230230
231- def convert_odt (afile , output_name , fmt = 'pdf' , ** kwargs ):
231+ def convert_odt (afile , output_name , fmt = 'pdf' , gen_context = None , ** kwargs ):
232232 """
233233 Convert an odt file to another format using appy.pod.
234234
235235 :param afile: file field content like NamedBlobFile
236236 :param output_name: output name
237237 :param fmt: output format, default to 'pdf'
238+ :param gen_context: generation context dict passed to renderer
238239 :param kwargs: other parameters passed to Renderer, i.e pdfOptions='ExportNotes=True;SelectPdfVersion=1'
239240 """
240241 lo_pool = LoPool .get (
@@ -250,7 +251,7 @@ def convert_odt(afile, output_name, fmt='pdf', **kwargs):
250251 try :
251252 renderer = Renderer (
252253 temp_file .name ,
253- afile ,
254+ gen_context or {} ,
254255 temporary_file_name (suffix = ".{extension}" .format (extension = fmt )),
255256 ** kwargs
256257 )
@@ -274,20 +275,21 @@ def convert_odt(afile, output_name, fmt='pdf', **kwargs):
274275 return output_name , converted_file
275276
276277
277- def convert_file (afile , output_name , fmt = "pdf" , renderer = False ):
278+ def convert_file (afile , output_name , fmt = "pdf" , renderer = False , gen_context = None ):
278279 """
279280 Convert a file to another libreoffice readable format using appy.pod
280281
281282 :param afile: file field content like NamedBlobFile
282283 :param output_name: output name
283284 :param fmt: output format, default to "pdf"
284285 :param renderer: whether to use appy.pod Renderer or converter script. Default to False.
286+ :param gen_context: generation context dict passed to renderer
285287 """
286288 if renderer :
287289 if not afile .filename .endswith ('.odt' ):
288290 message = _ (u"Conversion with renderer only works from odt files." )
289291 raise Invalid (message )
290- return convert_odt (afile , output_name , fmt = fmt )
292+ return convert_odt (afile , output_name , fmt = fmt , gen_context = gen_context )
291293 from appy .pod import converter
292294 converter_path = converter .__file__ .endswith (".pyc" ) and converter .__file__ [:- 1 ] or converter .__file__
293295 file_ext = afile .filename .split ('.' )[- 1 ].lower ()
@@ -316,7 +318,8 @@ def convert_file(afile, output_name, fmt="pdf", renderer=False):
316318 return output_name , converted_file
317319
318320
319- def convert_and_save_file (afile , container , portal_type , output_name , fmt = 'pdf' , from_uid = None , attributes = None , renderer = False ):
321+ def convert_and_save_file (afile , container , portal_type , output_name , fmt = 'pdf' , from_uid = None , attributes = None ,
322+ renderer = False , gen_context = None ):
320323 """
321324 Convert a file to another libreoffice readable format using appy.pod and save it in a NamedBlobFile.
322325
@@ -328,8 +331,12 @@ def convert_and_save_file(afile, container, portal_type, output_name, fmt='pdf',
328331 :param from_uid: uid from original file object
329332 :param attributes: dict of other attributes to set on created content
330333 :param renderer: whether to use appy.pod Renderer or converter script. Default to False.
334+ :param gen_context: generation context dict passed to renderer
331335 """
332- converted_filename , converted_file = convert_file (afile , output_name , fmt = fmt , renderer = renderer )
336+ if gen_context is None :
337+ gen_context = {}
338+ converted_filename , converted_file = convert_file (afile , output_name , fmt = fmt , gen_context = gen_context ,
339+ renderer = renderer )
333340 file_object = NamedBlobFile (converted_file , filename = safe_unicode (converted_filename ))
334341 if attributes is None :
335342 attributes = {}
0 commit comments