From 2636d37b97c37bba69dbe6b3e5119e7c54c319b1 Mon Sep 17 00:00:00 2001 From: Castro0o Date: Thu, 26 Mar 2020 21:13:54 +0100 Subject: [PATCH] remove document parts leftovers; saving document template rendering to disk --- query2html.py | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/query2html.py b/query2html.py index 81a8add..8ef0332 100644 --- a/query2html.py +++ b/query2html.py @@ -74,9 +74,6 @@ with open(os.path.join(wd, 'templates/index.html')) as document_html: with open(os.path.join(wd, 'templates/document.html')) as document_html: document_template = Template(document_html.read()) -with open(os.path.join(wd, 'templates/document_part.html')) as document_html: - document_part_template = Template(document_html.read()) - all_document_parts = '' # to append all content documentslist = [] document_images = [] @@ -95,7 +92,6 @@ for answer in site.ask(query): img_local = os.path.join(imgdir, img_info.get('filename')) - # TODO: join document_part + document # TODO: look into the template structure of images : columns and rows document_images.append(img_local) @@ -113,28 +109,27 @@ for answer in site.ask(query): content=all_document_parts) # render document template # print(document_html) - # htmlpage_fn = "{}.html".format( - # remove_nonwords(printout_dict.get('Title')[0]) - # ) - # with open(os.path.join(static_html, htmlpage_fn), 'w') as htmlfile: - # htmlfile.write(document_html) - # all_document_parts = '' # Reset all_document_parts + htmlpage_fn = "{}.html".format( + remove_nonwords(printout_dict.get('Title')[0]) + ) + with open(os.path.join(static_html, htmlpage_fn), 'w') as htmlfile: + htmlfile.write(document_html) - # # add info to documentslist for index creation - # documentslist.append({'file': htmlpage_fn, - # 'title': printout_dict.get('Title'), - # 'date': printout_dict.get('Date'), - # 'creator': printout_dict.get('Creator') - # }) + # add info to documentslist for index creation + documentslist.append({'file': htmlpage_fn, + 'title': printout_dict.get('Title'), + 'date': printout_dict.get('Date'), + 'creator': printout_dict.get('Creator') + }) # reset document_images list document_images = [] -# # RENDER index.html from documentslist -# index_html = index_template.render(index='Index', -# query=query, -# documentslist=documentslist) -# with open(os.path.join(static_html, 'index.html'), 'w') as htmlfile: -# htmlfile.write(index_html) +# RENDER index.html from documentslist +index_html = index_template.render(index='Index', + query=query, + documentslist=documentslist) +with open(os.path.join(static_html, 'index.html'), 'w') as htmlfile: + htmlfile.write(index_html)