Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
change thumbnails behavior to be conformant with docx package (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts authored Sep 6, 2019
1 parent 7137754 commit 7b4bcc6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 13 deletions.
9 changes: 1 addition & 8 deletions modules/threads/export_word.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ def run(self):
"""Export each metadata from a search results into a Word document."""
# vars
language = current_locale.name()[:2]
thumbnail_default = ("", path.realpath(r"resources/favicon.png"))

# word generator
to_docx = Isogeo2docx(
lang=language,
thumbnails=self.thumbnails,
url_base_edit=self.url_base_edit,
url_base_view=self.url_base_view,
)
Expand All @@ -109,13 +109,6 @@ def run(self):
metadata=metadata, shares=self.shares
)

# thumbnails
thumbnail_abs_path = self.thumbnails.get(metadata._id, thumbnail_default)[1]
if not thumbnail_abs_path or not path.isfile(thumbnail_abs_path):
thumbnail_abs_path = path.realpath(r"resources/favicon.png")
logger.debug("Thumbnail used: {}".format(thumbnail_abs_path))
metadata.thumbnail = thumbnail_abs_path

# templating
tpl = DocxTemplate(self.tpl_path)
# fill template
Expand Down
4 changes: 2 additions & 2 deletions modules/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ def thumbnails_mngr(

# parse worksheet and populate final dict
for row in ws.iter_rows(min_row=2):
if len(row) == 3 and row[0].value:
thumbnails_dict[row[0].value] = (row[1].value, row[2].value)
if len(row) == 3 and row[0].value and row[2].value:
thumbnails_dict[row[0].value] = row[2].value
else:
logger.debug("Thumbnails reader: empty cell spotted. Quit reading.")
break
Expand Down
4 changes: 1 addition & 3 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ def test_clean_xml(self):
# -- Thumbnails ----------------------------------------------------------
def test_thumbnails_loader_complete(self):
"""Test filenames errors"""
expected_dict = {
"1234569732454beca1ab3ec1958ffa50": ("title-slugged", "resources/table.svg")
}
expected_dict = {"1234569732454beca1ab3ec1958ffa50": "resources/table.svg"}
self.assertDictEqual(
self.utils.thumbnails_mngr(self.thumbs_complete), expected_dict
)
Expand Down

0 comments on commit 7b4bcc6

Please sign in to comment.