Commit fd76d546 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update helper to use Path in get_file_paths.

parent b5eeed51
......@@ -294,33 +294,37 @@ def get_file_paths(path, ext=None, alpha=True):
alpha (bool): sort the paths in alphabetic order
Returns:
list:
local paths for all selected files.
list or string:
* paths for all selected files,
* absolute path with respect to application
* for example: /myapp/static/myapp-min.js
"""
li = []
if path is None:
return li
return []
server_path, client_path = get_reference_paths()
lst = []
application = current.request.application
app_path = Path("applications", application)
for el in as_list(path):
p = os.path.join(server_path, el)
p = app_path / el
if os.path.isfile(p):
if ext and (not el.endswith(ext)):
if p.is_file():
if (ext is not None) and (p.suffix != ext):
continue
li.append(os.path.join(client_path, el))
lst.append(Path("/", application, el))
elif os.path.isdir(p):
for filename in os.listdir(p):
pfile = os.path.join(el, filename)
li.extend(get_file_paths(pfile, ext, alpha))
elif p.is_dir():
for pfile in p.iterdir():
new_path = str(pfile.relative_to(app_path))
lst.extend(get_file_paths(new_path, ext, alpha))
lst = [str(el) for el in lst]
if alpha:
li.sort()
lst.sort()
return li
return lst
def get_foreign_field(field):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment