Sfoglia il codice sorgente

Merge pull request #601 from if1live/better-figures-os-path-join-bug

better_figures_and_images: bug fix: broken path by os.path.join()
Justin Mayer 9 anni fa
parent
commit
0b7dadd7b8
1 ha cambiato i file con 8 aggiunte e 0 eliminazioni
  1. 8 0
      better_figures_and_images/better_figures_and_images.py

+ 8 - 0
better_figures_and_images/better_figures_and_images.py

@@ -55,9 +55,17 @@ def content_object_init(instance):
                 # search src path list
                 # 1. Build the source image filename from PATH
                 # 2. Build the source image filename from STATIC_PATHS
+
+                # if img_path start with '/', remove it.
+                img_path = os.path.sep.join([el for el in img_path.split("/") if len(el) > 0])
+
+                # style: {filename}/static/foo/bar.png
                 src = os.path.join(instance.settings['PATH'], img_path, img_filename)
                 src_candidates = [src]
+
+                # style: {filename}../static/foo/bar.png
                 src_candidates += [os.path.join(instance.settings['PATH'], static_path, img_path, img_filename) for static_path in instance.settings['STATIC_PATHS']]
+
                 src_candidates = [f for f in src_candidates if path.isfile(f) and access(f, R_OK)]
 
                 if not src_candidates: