Loading src/rpc/methods.py +7 −62 Original line number Diff line number Diff line Loading @@ -54,6 +54,13 @@ from resources.management.commands.newjamaproject import ( from annotations.models import Annotation from rpc import serializers from rpc.serializers import ( COLLECTION_PARENT_SERIALIZATION_FIELDS, COLLECTION_REPRESENTATIVE_SERIALIZATION_FIELDS, COLLECTION_SERIALIZATION_FIELDS, FILE_SERIALIZATION_FIELDS, RESOURCE_SERIALIZATION_FIELDS, ) from rpc.errors import ServiceException from rpc.cache import SerializerCache from rpc.const import ( Loading Loading @@ -88,68 +95,6 @@ from django.db.models import BinaryField, Count, Q logger = logging.getLogger(__name__) RESOURCE_SERIALIZATION_FIELDS = ( "id", "title", "created_at", "updated_at", "deleted_at", "ptr_project_id", "ark", ) FILE_SERIALIZATION_FIELDS = ( "file__id", "file__title", "file__created_at", "file__updated_at", "file__deleted_at", "file__ptr_project_id", "file__ark", "file__original_name", "file__project_id", "file__project__id", "file__project__use_exiftool", "file__hash", "file__file_type_id", "file__file_type__id", "file__file_type__title", "file__file_type__mime", "file__file_type__serve_with_iiif", "file__file_type__serve_with_hls", "file__denormalized_image_width", "file__denormalized_image_height", ) COLLECTION_SERIALIZATION_FIELDS = ( "id", "title", "parent_id", "project_id", "public_access", "published_at", "created_at", "updated_at", "deleted_at", "representative_id", "ark", ) COLLECTION_PARENT_SERIALIZATION_FIELDS = ( "parent__id", "parent__title", "parent__parent_id", "parent__project_id", "parent__public_access", "parent__published_at", "parent__created_at", "parent__updated_at", "parent__deleted_at", "parent__representative_id", "parent__ark", ) COLLECTION_REPRESENTATIVE_SERIALIZATION_FIELDS = tuple( f"representative__{field}" for field in RESOURCE_SERIALIZATION_FIELDS ) + tuple(f"representative__{field}" for field in FILE_SERIALIZATION_FIELDS) def _deskew( image_path: str, max_skew: int = 10, fast: bool = True, scale_max: int = 1000 ) -> float: Loading src/rpc/serializers.py +62 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,68 @@ import os from rpc.cache import SerializerCache RESOURCE_SERIALIZATION_FIELDS = ( "id", "title", "created_at", "updated_at", "deleted_at", "ptr_project_id", "ark", ) FILE_SERIALIZATION_FIELDS = ( "file__id", "file__title", "file__created_at", "file__updated_at", "file__deleted_at", "file__ptr_project_id", "file__ark", "file__original_name", "file__project_id", "file__project__id", "file__project__use_exiftool", "file__hash", "file__file_type_id", "file__file_type__id", "file__file_type__title", "file__file_type__mime", "file__file_type__serve_with_iiif", "file__file_type__serve_with_hls", "file__denormalized_image_width", "file__denormalized_image_height", ) COLLECTION_SERIALIZATION_FIELDS = ( "id", "title", "parent_id", "project_id", "public_access", "published_at", "created_at", "updated_at", "deleted_at", "representative_id", "ark", ) COLLECTION_PARENT_SERIALIZATION_FIELDS = ( "parent__id", "parent__title", "parent__parent_id", "parent__project_id", "parent__public_access", "parent__published_at", "parent__created_at", "parent__updated_at", "parent__deleted_at", "parent__representative_id", "parent__ark", ) COLLECTION_REPRESENTATIVE_SERIALIZATION_FIELDS = tuple( f"representative__{field}" for field in RESOURCE_SERIALIZATION_FIELDS ) + tuple(f"representative__{field}" for field in FILE_SERIALIZATION_FIELDS) def _related_field_is_cached(instance, field_name: str) -> bool: return field_name in getattr(instance._state, "fields_cache", {}) Loading Loading
src/rpc/methods.py +7 −62 Original line number Diff line number Diff line Loading @@ -54,6 +54,13 @@ from resources.management.commands.newjamaproject import ( from annotations.models import Annotation from rpc import serializers from rpc.serializers import ( COLLECTION_PARENT_SERIALIZATION_FIELDS, COLLECTION_REPRESENTATIVE_SERIALIZATION_FIELDS, COLLECTION_SERIALIZATION_FIELDS, FILE_SERIALIZATION_FIELDS, RESOURCE_SERIALIZATION_FIELDS, ) from rpc.errors import ServiceException from rpc.cache import SerializerCache from rpc.const import ( Loading Loading @@ -88,68 +95,6 @@ from django.db.models import BinaryField, Count, Q logger = logging.getLogger(__name__) RESOURCE_SERIALIZATION_FIELDS = ( "id", "title", "created_at", "updated_at", "deleted_at", "ptr_project_id", "ark", ) FILE_SERIALIZATION_FIELDS = ( "file__id", "file__title", "file__created_at", "file__updated_at", "file__deleted_at", "file__ptr_project_id", "file__ark", "file__original_name", "file__project_id", "file__project__id", "file__project__use_exiftool", "file__hash", "file__file_type_id", "file__file_type__id", "file__file_type__title", "file__file_type__mime", "file__file_type__serve_with_iiif", "file__file_type__serve_with_hls", "file__denormalized_image_width", "file__denormalized_image_height", ) COLLECTION_SERIALIZATION_FIELDS = ( "id", "title", "parent_id", "project_id", "public_access", "published_at", "created_at", "updated_at", "deleted_at", "representative_id", "ark", ) COLLECTION_PARENT_SERIALIZATION_FIELDS = ( "parent__id", "parent__title", "parent__parent_id", "parent__project_id", "parent__public_access", "parent__published_at", "parent__created_at", "parent__updated_at", "parent__deleted_at", "parent__representative_id", "parent__ark", ) COLLECTION_REPRESENTATIVE_SERIALIZATION_FIELDS = tuple( f"representative__{field}" for field in RESOURCE_SERIALIZATION_FIELDS ) + tuple(f"representative__{field}" for field in FILE_SERIALIZATION_FIELDS) def _deskew( image_path: str, max_skew: int = 10, fast: bool = True, scale_max: int = 1000 ) -> float: Loading
src/rpc/serializers.py +62 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,68 @@ import os from rpc.cache import SerializerCache RESOURCE_SERIALIZATION_FIELDS = ( "id", "title", "created_at", "updated_at", "deleted_at", "ptr_project_id", "ark", ) FILE_SERIALIZATION_FIELDS = ( "file__id", "file__title", "file__created_at", "file__updated_at", "file__deleted_at", "file__ptr_project_id", "file__ark", "file__original_name", "file__project_id", "file__project__id", "file__project__use_exiftool", "file__hash", "file__file_type_id", "file__file_type__id", "file__file_type__title", "file__file_type__mime", "file__file_type__serve_with_iiif", "file__file_type__serve_with_hls", "file__denormalized_image_width", "file__denormalized_image_height", ) COLLECTION_SERIALIZATION_FIELDS = ( "id", "title", "parent_id", "project_id", "public_access", "published_at", "created_at", "updated_at", "deleted_at", "representative_id", "ark", ) COLLECTION_PARENT_SERIALIZATION_FIELDS = ( "parent__id", "parent__title", "parent__parent_id", "parent__project_id", "parent__public_access", "parent__published_at", "parent__created_at", "parent__updated_at", "parent__deleted_at", "parent__representative_id", "parent__ark", ) COLLECTION_REPRESENTATIVE_SERIALIZATION_FIELDS = tuple( f"representative__{field}" for field in RESOURCE_SERIALIZATION_FIELDS ) + tuple(f"representative__{field}" for field in FILE_SERIALIZATION_FIELDS) def _related_field_is_cached(instance, field_name: str) -> bool: return field_name in getattr(instance._state, "fields_cache", {}) Loading