Skip to content

Commit

Permalink
Fix issue with search captions
Browse files Browse the repository at this point in the history
  • Loading branch information
derneuere committed May 11, 2024
1 parent 36cb086 commit ffec893
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
8 changes: 8 additions & 0 deletions api/directory_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
42 changes: 22 additions & 20 deletions api/models/photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit ffec893

Please sign in to comment.