Skip to content

Commit

Permalink
Address review comments by @danielquinn
Browse files Browse the repository at this point in the history
  • Loading branch information
grembo committed Sep 8, 2019
1 parent f0320fb commit 3b88d67
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/documents/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,11 +484,15 @@ def from_path(cls, path):
"""

filename = os.path.basename(path)

# Mutate filename in-place before parsing its components
# by applying at most one of the configured transformations.
for (pattern, repl) in settings.FILENAME_PARSE_TRANSFORMS:
(filename, count) = pattern.subn(repl, filename)
if count:
break

# Parse filename components.
for regex in cls.REGEXES.values():
m = regex.match(filename)
if m:
Expand Down
8 changes: 2 additions & 6 deletions src/paperless/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,8 @@ def __get_boolean(key, default="NO"):

# Transformations applied before filename parsing
FILENAME_PARSE_TRANSFORMS = []
_filename_parse_transforms = os.getenv("PAPERLESS_FILENAME_PARSE_TRANSFORMS")
if _filename_parse_transforms:
FILENAME_PARSE_TRANSFORMS = [(
re.compile(t["pattern"]), t["repl"])
for t in json.loads(_filename_parse_transforms)
]
for t in json.loads(os.getenv("PAPERLESS_FILENAME_PARSE_TRANSFORMS", "[]")):
FILENAME_PARSE_TRANSFORMS.append((re.compile(t["pattern"]), t["repl"]))

# Specify for how many years a correspondent is considered recent. Recent
# correspondents will be shown in a separate "Recent correspondents" filter as
Expand Down

0 comments on commit 3b88d67

Please sign in to comment.