Skip to content

Commit 3eeefbb

Browse files
committed
Fix another issue with album things
1 parent ffec893 commit 3eeefbb

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

api/models/album_thing.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ class Meta:
3636
]
3737

3838
def save(self, *args, **kwargs):
39-
# Update default cover photos whenever the AlbumThing is saved
40-
self.update_default_cover_photo()
4139
super().save(*args, **kwargs)
4240

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

5756

5857
def get_album_thing(title, owner, thing_type=None):

api/models/photo.py

+15-10
Original file line numberDiff line numberDiff line change
@@ -262,19 +262,21 @@ def _save_captions(self, commit=True, caption=None):
262262

263263
def _recreate_search_captions(self):
264264
search_captions = ""
265-
places365_captions = self.captions_json.get("places365", {})
266265

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

270-
categories = places365_captions.get("categories", [])
271-
search_captions += " ".join(categories) + " "
269+
attributes = places365_captions.get("attributes", [])
270+
search_captions += " ".join(attributes) + " "
272271

273-
environment = places365_captions.get("environment", "")
274-
search_captions += environment + " "
272+
categories = places365_captions.get("categories", [])
273+
search_captions += " ".join(categories) + " "
275274

276-
user_caption = self.captions_json.get("user_caption", "")
277-
search_captions += user_caption + " "
275+
environment = places365_captions.get("environment", "")
276+
search_captions += environment + " "
277+
278+
user_caption = self.captions_json.get("user_caption", "")
279+
search_captions += user_caption + " "
278280

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

288290
if self.camera:
289291
search_captions += self.camera + " "
292+
290293
if self.lens:
291294
search_captions += self.lens + " "
292295

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

311314
self.captions_json["places365"] = res_places365
312315
self._recreate_search_captions()
313-
# Remove from all places365_attribute and places365_category albums
316+
314317
for album_thing in api.models.album_thing.AlbumThing.objects.filter(
315318
Q(photos__in=[self.image_hash])
316319
& (
@@ -321,6 +324,7 @@ def _generate_captions(self, commit):
321324
).all():
322325
album_thing.photos.remove(self)
323326
album_thing.save()
327+
324328
if "attributes" in res_places365:
325329
for attribute in res_places365["attributes"]:
326330
album_thing = api.models.album_thing.get_album_thing(
@@ -330,6 +334,7 @@ def _generate_captions(self, commit):
330334
)
331335
album_thing.photos.add(self)
332336
album_thing.save()
337+
333338
if "categories" in res_places365:
334339
for category in res_places365["categories"]:
335340
album_thing = api.models.album_thing.get_album_thing(

0 commit comments

Comments
 (0)