Skip to content

Commit

Permalink
Fix another issue with album things
Browse files Browse the repository at this point in the history
  • Loading branch information
derneuere committed May 11, 2024
1 parent ffec893 commit 3eeefbb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
3 changes: 1 addition & 2 deletions api/models/album_thing.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ class Meta:
]

def save(self, *args, **kwargs):
# Update default cover photos whenever the AlbumThing is saved
self.update_default_cover_photo()
super().save(*args, **kwargs)

def update_default_cover_photo(self):
Expand All @@ -53,6 +51,7 @@ def update_photo_count(sender, instance, action, reverse, model, pk_set, **kwarg
count = instance.photos.filter(hidden=False).count()
instance.photo_count = count
instance.save(update_fields=["photo_count"])
instance.update_default_cover_photo()


def get_album_thing(title, owner, thing_type=None):
Expand Down
25 changes: 15 additions & 10 deletions api/models/photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,19 +262,21 @@ def _save_captions(self, commit=True, caption=None):

def _recreate_search_captions(self):
search_captions = ""
places365_captions = self.captions_json.get("places365", {})

attributes = places365_captions.get("attributes", [])
search_captions += " ".join(attributes) + " "
if self.captions_json:
places365_captions = self.captions_json.get("places365", {})

categories = places365_captions.get("categories", [])
search_captions += " ".join(categories) + " "
attributes = places365_captions.get("attributes", [])
search_captions += " ".join(attributes) + " "

environment = places365_captions.get("environment", "")
search_captions += environment + " "
categories = places365_captions.get("categories", [])
search_captions += " ".join(categories) + " "

user_caption = self.captions_json.get("user_caption", "")
search_captions += user_caption + " "
environment = places365_captions.get("environment", "")
search_captions += environment + " "

user_caption = self.captions_json.get("user_caption", "")
search_captions += user_caption + " "

for face in api.models.face.Face.objects.filter(photo=self).all():
search_captions += face.person.name + " "
Expand All @@ -287,6 +289,7 @@ def _recreate_search_captions(self):

if self.camera:
search_captions += self.camera + " "

if self.lens:
search_captions += self.lens + " "

Expand All @@ -310,7 +313,7 @@ def _generate_captions(self, commit):

self.captions_json["places365"] = res_places365
self._recreate_search_captions()
# Remove from all places365_attribute and places365_category albums

for album_thing in api.models.album_thing.AlbumThing.objects.filter(
Q(photos__in=[self.image_hash])
& (
Expand All @@ -321,6 +324,7 @@ def _generate_captions(self, commit):
).all():
album_thing.photos.remove(self)
album_thing.save()

if "attributes" in res_places365:
for attribute in res_places365["attributes"]:
album_thing = api.models.album_thing.get_album_thing(
Expand All @@ -330,6 +334,7 @@ def _generate_captions(self, commit):
)
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(
Expand Down

0 comments on commit 3eeefbb

Please sign in to comment.