From ffec8936d2cf82a36a1129e3976a12817e9d739d Mon Sep 17 00:00:00 2001 From: Niaz Date: Sat, 11 May 2024 15:53:52 +0200 Subject: [PATCH] Fix issue with search captions --- api/directory_watcher.py | 8 ++++++++ api/models/photo.py | 42 +++++++++++++++++++++------------------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/api/directory_watcher.py b/api/directory_watcher.py index 90010d037c..2689fd7345 100644 --- a/api/directory_watcher.py +++ b/api/directory_watcher.py @@ -221,6 +221,14 @@ def handle_new_image(user, path, job_id, photo=None): util.logger.info( "job {}: image processed: {}, elapsed: {}".format(job_id, path, elapsed) ) + photo._recreate_search_captions() + elapsed = (datetime.datetime.now() - start).total_seconds() + util.logger.info( + "job {}: seach caption recreated: {}, elapsed: {}".format( + job_id, path, elapsed + ) + ) + except Exception as e: try: util.logger.exception( diff --git a/api/models/photo.py b/api/models/photo.py index 4832469c3f..8a886d1c30 100644 --- a/api/models/photo.py +++ b/api/models/photo.py @@ -285,8 +285,10 @@ def _recreate_search_captions(self): if self.video: search_captions += "type: video " - search_captions += self.camera + " " - search_captions += self.lens + " " + if self.camera: + search_captions += self.camera + " " + if self.lens: + search_captions += self.lens + " " self.search_captions = search_captions.strip() # Remove trailing space util.logger.debug( @@ -319,24 +321,24 @@ def _generate_captions(self, commit): ).all(): album_thing.photos.remove(self) album_thing.save() - - for attribute in res_places365["attributes"]: - album_thing = api.models.album_thing.get_album_thing( - title=attribute, - owner=self.owner, - thing_type="places365_attribute", - ) - album_thing.photos.add(self) - album_thing.save() - - for category in res_places365["categories"]: - album_thing = api.models.album_thing.get_album_thing( - title=category, - owner=self.owner, - thing_type="places365_category", - ) - album_thing.photos.add(self) - album_thing.save() + if "attributes" in res_places365: + for attribute in res_places365["attributes"]: + album_thing = api.models.album_thing.get_album_thing( + title=attribute, + owner=self.owner, + thing_type="places365_attribute", + ) + album_thing.photos.add(self) + album_thing.save() + if "categories" in res_places365: + for category in res_places365["categories"]: + album_thing = api.models.album_thing.get_album_thing( + title=category, + owner=self.owner, + thing_type="places365_category", + ) + album_thing.photos.add(self) + album_thing.save() if commit: self.save()