Skip to content

Commit

Permalink
Fix how starting canvas gets set.
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvarner committed Apr 24, 2024
1 parent 9712c32 commit 9b19ad5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 23 deletions.
11 changes: 0 additions & 11 deletions apps/iiif/canvases/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,9 @@ def before_save(self):
self.width = self.image_info['width']
self.height = self.image_info['height']

print("$$$$$$$$$$$$$$$$$$")
print(self.pid)
print("$$$$$$$$$$$$$$$$$$")

if self.resource is None:
self.resource = self.pid

print("################")
print(self.resource_id)
print("################")

if self.manifest and self.manifest.start_canvas is None:
Manifest.objects.filter(id=self.manifest.id).update(start_canvas=self)

def save(self, *args, **kwargs): # pylint: disable = signature-differs
"""
Override save to call the before_save function.
Expand Down
19 changes: 7 additions & 12 deletions apps/iiif/manifests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,25 +342,20 @@ def save(self, *args, **kwargs): # pylint: disable = arguments-differ
if not self._state.adding and 'pid' in self.get_dirty_fields() and self.image_server and self.image_server.storage_service == 's3':
self.__rename_s3_objects()

super().save(*args, **kwargs)

for collection in self.collections.all():
collection.modified_at = self.modified_at
collection.save()

Canvas = apps.get_model('canvases.canvas')
try:
Canvas = apps.get_model('canvases.canvas')
if self.start_canvas is None and hasattr(self, 'canvas_set') and self.canvas_set.exists():
self.start_canvas = self.canvas_set.all().order_by('position').first()
self.save()
Canvas.objects.filter(manifest=self).update(is_starting_page=False)
Canvas.objects.filter(pk=self.start_canvas.id).update(is_starting_page=True)
except Canvas.DoesNotExist:
self.start_canvas = None

# if 'update_fields' not in kwargs or 'search_vector' not in kwargs['update_fields']:
# instance = self._meta.default_manager.with_documents().get(pk=self.pk)
# instance.search_vector = instance.document
# instance.save(update_fields=['search_vector'])
super().save(*args, **kwargs)

for collection in self.collections.all():
collection.modified_at = self.modified_at
collection.save()

def delete(self, *args, **kwargs):
"""
Expand Down
1 change: 1 addition & 0 deletions apps/iiif/manifests/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def test_multiple_starting_canvases(self):
assert volume.canvas_set.exists() is False
for index, _ in enumerate(range(4)):
CanvasFactory.create(manifest=volume, is_starting_page=True, position=index+1)
volume.save()
volume.refresh_from_db()
manifest = json.loads(
serialize(
Expand Down
1 change: 1 addition & 0 deletions apps/iiif/manifests/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def test_default_start_canvas(self):
assert manifest.start_canvas is None
canvas = CanvasFactory.create(manifest=manifest)
canvas.save()
manifest.save()
manifest.refresh_from_db()
assert manifest.start_canvas == canvas

Expand Down

0 comments on commit 9b19ad5

Please sign in to comment.