Add Photo.normalize_override_filename.
This commit is contained in:
		
							parent
							
								
									2229a876e0
								
							
						
					
					
						commit
						c99f6858df
					
				
					 1 changed files with 13 additions and 6 deletions
				
			
		|  | @ -679,6 +679,18 @@ class Photo(ObjectBase): | ||||||
|     def __repr__(self): |     def __repr__(self): | ||||||
|         return f'Photo:{self.id}' |         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): |     def _uncache(self): | ||||||
|         self.photodb.caches['photo'].remove(self.id) |         self.photodb.caches['photo'].remove(self.id) | ||||||
| 
 | 
 | ||||||
|  | @ -1142,12 +1154,7 @@ class Photo(ObjectBase): | ||||||
|     @decorators.required_feature('photo.edit') |     @decorators.required_feature('photo.edit') | ||||||
|     @decorators.transaction |     @decorators.transaction | ||||||
|     def set_override_filename(self, new_filename): |     def set_override_filename(self, new_filename): | ||||||
|         if new_filename is not None: |         new_filename = self.normalize_override_filename(new_filename) | ||||||
|             cleaned = helpers.remove_path_badchars(new_filename) |  | ||||||
|             cleaned = cleaned.strip() |  | ||||||
|             if not cleaned: |  | ||||||
|                 raise ValueError(f'"{new_filename}" is not valid.') |  | ||||||
|             new_filename = cleaned |  | ||||||
| 
 | 
 | ||||||
|         data = { |         data = { | ||||||
|             'id': self.id, |             'id': self.id, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue