From c99f6858df4e2219ac83960ebc00f6c1dd9afdb1 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Thu, 17 Sep 2020 17:46:52 -0700 Subject: [PATCH] Add Photo.normalize_override_filename. --- etiquette/objects.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/etiquette/objects.py b/etiquette/objects.py index 57b997c..affa071 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -679,6 +679,18 @@ class Photo(ObjectBase): def __repr__(self): return f'Photo:{self.id}' + @staticmethod + def normalize_override_filename(override_filename): + if override_filename is None: + return None + + cleaned = helpers.remove_path_badchars(override_filename) + cleaned = cleaned.strip() + if not cleaned: + raise ValueError(f'"{override_filename}" is not valid.') + + return cleaned + def _uncache(self): self.photodb.caches['photo'].remove(self.id) @@ -1142,12 +1154,7 @@ class Photo(ObjectBase): @decorators.required_feature('photo.edit') @decorators.transaction def set_override_filename(self, new_filename): - if new_filename is not None: - cleaned = helpers.remove_path_badchars(new_filename) - cleaned = cleaned.strip() - if not cleaned: - raise ValueError(f'"{new_filename}" is not valid.') - new_filename = cleaned + new_filename = self.normalize_override_filename(new_filename) data = { 'id': self.id,