diff --git a/.github/workflows/dev-test.yml b/.github/workflows/dev-test.yml index 4f2b9ca3..3f255be1 100644 --- a/.github/workflows/dev-test.yml +++ b/.github/workflows/dev-test.yml @@ -60,9 +60,9 @@ jobs: ruby-version: "2.7.2" - name: Setup Node - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: - node-version: "18.12" + node-version: "20" - name: Install system requirements run: | diff --git a/apps/iiif/annotations/models.py b/apps/iiif/annotations/models.py index 367a6deb..52ef7ee0 100644 --- a/apps/iiif/annotations/models.py +++ b/apps/iiif/annotations/models.py @@ -90,7 +90,7 @@ def save(self, *args, **kwargs): # if not self.content or self.content.isspace(): # raise ValidationError('Content cannot be empty') # self.content = ' ' - super(Annotation, self).save(*args, **kwargs) + super().save(*args, **kwargs) class Meta: # pylint: disable=too-few-public-methods, missing-class-docstring ordering = ['order'] diff --git a/apps/iiif/canvases/tests/test_model.py b/apps/iiif/canvases/tests/test_model.py index c241efef..c84b887a 100644 --- a/apps/iiif/canvases/tests/test_model.py +++ b/apps/iiif/canvases/tests/test_model.py @@ -120,3 +120,9 @@ def test_setting_height_and_width(self): canvas.save() assert canvas.height == 3000 assert canvas.width == 3000 + + def test_setting_resource(self): + canvas = CanvasNoDimensionsFactory.build(manifest=ManifestFactory.create()) + assert canvas.resource is None + canvas.before_save() + assert canvas.resource == canvas.pid \ No newline at end of file diff --git a/apps/iiif/manifests/admin.py b/apps/iiif/manifests/admin.py index d0ec3aef..98e544cc 100644 --- a/apps/iiif/manifests/admin.py +++ b/apps/iiif/manifests/admin.py @@ -9,6 +9,7 @@ from import_export.widgets import ManyToManyWidget, ForeignKeyWidget from django_summernote.admin import SummernoteModelAdmin from .models import Manifest, Note, ImageServer, RelatedLink +from .documents import ManifestDocument from .forms import ManifestAdminForm from .views import AddToCollectionsView, MetadataImportView from ..kollections.models import Collection @@ -84,6 +85,12 @@ def get_urls(self): ] return my_urls + urls + def save_model(self, request, obj, form, change): + # Add/update Volume in the Elasticsearch index. + index = ManifestDocument() + index.update(obj, True, 'index') + super().save_model(request, obj, form, change) + class NoteAdmin(admin.ModelAdmin): """Django admin configuration for a note.""" class Meta: # pylint: disable=too-few-public-methods, missing-class-docstring diff --git a/apps/iiif/manifests/models.py b/apps/iiif/manifests/models.py index 2123ce8b..33aa37bd 100644 --- a/apps/iiif/manifests/models.py +++ b/apps/iiif/manifests/models.py @@ -367,8 +367,14 @@ def delete(self, *args, **kwargs): for canvas in self.canvas_set.all(): canvas.delete() + # Delete from Elasticsearch index + from .documents import ManifestDocument + index = ManifestDocument() + index.update(self, True, 'delete') + super().delete(*args, **kwargs) + def __rename_s3_objects(self): original_pid = self.get_dirty_fields()['pid'] keys = [f.key for f in self.image_server.bucket.objects.filter(Prefix=f'{original_pid}/')] diff --git a/apps/readux/models.py b/apps/readux/models.py index 90560fab..4e503e7f 100644 --- a/apps/readux/models.py +++ b/apps/readux/models.py @@ -8,7 +8,7 @@ from django.dispatch import receiver from apps.iiif.annotations.models import AbstractAnnotation, Annotation from apps.iiif.canvases.models import Canvas - +from apps.iiif.manifests.documents import ManifestDocument class TaggedUserAnnotations(TaggedItemBase): """Model for tagging :class:`UserAnnotation`s using Django Taggit.""" content_object = models.ForeignKey('UserAnnotation', on_delete=models.CASCADE) @@ -60,6 +60,18 @@ def tag_list(self): else: return [] + def save(self, *args, **kwargs): + if self.canvas: + index = ManifestDocument() + index.update(self.canvas.manifest, True, 'index') + super().save(*args, **kwargs) + + def delete(self, *args, **kwargs): + if self.canvas: + index = ManifestDocument() + index.update(self.canvas.manifest, True, 'delete') + super().delete(*args, **kwargs) + def update(self, attrs=None, tags=None): """Method to update an annotation object with a dict of attributes and a list of tags