diff --git a/base_directory_file_download/models/ir_filesystem_directory.py b/base_directory_file_download/models/ir_filesystem_directory.py index 4084cce58..cc8bcf75c 100644 --- a/base_directory_file_download/models/ir_filesystem_directory.py +++ b/base_directory_file_download/models/ir_filesystem_directory.py @@ -3,8 +3,9 @@ import logging -from os import listdir -from os.path import isfile, join, exists, normpath, realpath +from glob import glob +from os.path import basename, isfile, join, exists, normpath, realpath + from odoo import api, fields, models, _ from odoo.exceptions import UserError @@ -26,6 +27,7 @@ class IrFilesystemDirectory(models.Model): compute='_compute_file_count', string="# Files", ) + files_filter = fields.Char() @api.multi def get_dir(self): @@ -61,10 +63,11 @@ class IrFilesystemDirectory(models.Model): @api.multi def _get_directory_files(self): - def get_files(directory, files): - for file_name in listdir(directory): - full_path = join(directory, file_name) - + def get_files(directory, files_filter): + glob_path = join(directory, files_filter) + content = glob(glob_path) + for full_path in content: + file_name = basename(full_path) # Symbolic links and up-level references are not considered norm_path = normpath(realpath(full_path)) if norm_path in full_path: @@ -75,7 +78,7 @@ class IrFilesystemDirectory(models.Model): files = [] if self.get_dir() and exists(self.get_dir()): try: - get_files(self.get_dir(), files) + get_files(self.get_dir(), self.files_filter or '*') except (IOError, OSError): _logger.info( "_get_directory_files reading %s", diff --git a/base_directory_file_download/models/ir_filesystem_file.py b/base_directory_file_download/models/ir_filesystem_file.py index 501d1d23e..e31d30c80 100644 --- a/base_directory_file_download/models/ir_filesystem_file.py +++ b/base_directory_file_download/models/ir_filesystem_file.py @@ -14,6 +14,7 @@ _logger = logging.getLogger(__name__) class IrFilesystemDirectoryLine(models.TransientModel): _name = 'ir.filesystem.file' + _description = 'File in filesystem' name = fields.Char(required=True) filename = fields.Char() diff --git a/base_directory_file_download/views/ir_filesystem_directory.xml b/base_directory_file_download/views/ir_filesystem_directory.xml index ae3990feb..3b58983bb 100644 --- a/base_directory_file_download/views/ir_filesystem_directory.xml +++ b/base_directory_file_download/views/ir_filesystem_directory.xml @@ -18,6 +18,7 @@ +