Initial commit
This commit is contained in:
0
env/lib/python3.10/site-packages/wagtail/images/api/__init__.py
vendored
Normal file
0
env/lib/python3.10/site-packages/wagtail/images/api/__init__.py
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/images/api/__pycache__/__init__.cpython-310.pyc
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/images/api/__pycache__/__init__.cpython-310.pyc
vendored
Normal file
Binary file not shown.
BIN
env/lib/python3.10/site-packages/wagtail/images/api/__pycache__/fields.cpython-310.pyc
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/images/api/__pycache__/fields.cpython-310.pyc
vendored
Normal file
Binary file not shown.
0
env/lib/python3.10/site-packages/wagtail/images/api/admin/__init__.py
vendored
Normal file
0
env/lib/python3.10/site-packages/wagtail/images/api/admin/__init__.py
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/images/api/admin/__pycache__/__init__.cpython-310.pyc
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/images/api/admin/__pycache__/__init__.cpython-310.pyc
vendored
Normal file
Binary file not shown.
BIN
env/lib/python3.10/site-packages/wagtail/images/api/admin/__pycache__/serializers.cpython-310.pyc
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/images/api/admin/__pycache__/serializers.cpython-310.pyc
vendored
Normal file
Binary file not shown.
BIN
env/lib/python3.10/site-packages/wagtail/images/api/admin/__pycache__/views.cpython-310.pyc
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/images/api/admin/__pycache__/views.cpython-310.pyc
vendored
Normal file
Binary file not shown.
6
env/lib/python3.10/site-packages/wagtail/images/api/admin/serializers.py
vendored
Normal file
6
env/lib/python3.10/site-packages/wagtail/images/api/admin/serializers.py
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
from ..fields import ImageRenditionField
|
||||
from ..v2.serializers import ImageSerializer
|
||||
|
||||
|
||||
class AdminImageSerializer(ImageSerializer):
|
||||
thumbnail = ImageRenditionField("max-165x165", source="*", read_only=True)
|
||||
16
env/lib/python3.10/site-packages/wagtail/images/api/admin/views.py
vendored
Normal file
16
env/lib/python3.10/site-packages/wagtail/images/api/admin/views.py
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
from ..v2.views import ImagesAPIViewSet
|
||||
from .serializers import AdminImageSerializer
|
||||
|
||||
|
||||
class ImagesAdminAPIViewSet(ImagesAPIViewSet):
|
||||
base_serializer_class = AdminImageSerializer
|
||||
|
||||
body_fields = ImagesAPIViewSet.body_fields + [
|
||||
"thumbnail",
|
||||
]
|
||||
|
||||
listing_default_fields = ImagesAPIViewSet.listing_default_fields + [
|
||||
"width",
|
||||
"height",
|
||||
"thumbnail",
|
||||
]
|
||||
59
env/lib/python3.10/site-packages/wagtail/images/api/fields.py
vendored
Normal file
59
env/lib/python3.10/site-packages/wagtail/images/api/fields.py
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
from collections import OrderedDict
|
||||
|
||||
from rest_framework.fields import Field
|
||||
|
||||
from ..models import SourceImageIOError
|
||||
from ..utils import to_svg_safe_spec
|
||||
|
||||
|
||||
class ImageRenditionField(Field):
|
||||
"""
|
||||
A field that generates a rendition with the specified filter spec, and serialises
|
||||
details of that rendition.
|
||||
|
||||
Example:
|
||||
"thumbnail": {
|
||||
"url": "/media/images/myimage.max-165x165.jpg",
|
||||
"full_url": "https://media.example.com/media/images/myimage.max-165x165.jpg",
|
||||
"width": 165,
|
||||
"height": 100,
|
||||
"alt": "Image alt text"
|
||||
}
|
||||
|
||||
If there is an error with the source image. The dict will only contain a single
|
||||
key, "error", indicating this error:
|
||||
|
||||
"thumbnail": {
|
||||
"error": "SourceImageIOError"
|
||||
}
|
||||
"""
|
||||
|
||||
def __init__(self, filter_spec, preserve_svg=False, *args, **kwargs):
|
||||
self.filter_spec = filter_spec
|
||||
self.preserve_svg = preserve_svg
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def to_representation(self, image):
|
||||
try:
|
||||
if image.is_svg() and self.preserve_svg:
|
||||
filter_spec = to_svg_safe_spec(self.filter_spec)
|
||||
else:
|
||||
filter_spec = self.filter_spec
|
||||
|
||||
thumbnail = image.get_rendition(filter_spec)
|
||||
|
||||
return OrderedDict(
|
||||
[
|
||||
("url", thumbnail.url),
|
||||
("full_url", thumbnail.full_url),
|
||||
("width", thumbnail.width),
|
||||
("height", thumbnail.height),
|
||||
("alt", thumbnail.alt),
|
||||
]
|
||||
)
|
||||
except SourceImageIOError:
|
||||
return OrderedDict(
|
||||
[
|
||||
("error", "SourceImageIOError"),
|
||||
]
|
||||
)
|
||||
0
env/lib/python3.10/site-packages/wagtail/images/api/v2/__init__.py
vendored
Normal file
0
env/lib/python3.10/site-packages/wagtail/images/api/v2/__init__.py
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/images/api/v2/__pycache__/__init__.cpython-310.pyc
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/images/api/v2/__pycache__/__init__.cpython-310.pyc
vendored
Normal file
Binary file not shown.
BIN
env/lib/python3.10/site-packages/wagtail/images/api/v2/__pycache__/serializers.cpython-310.pyc
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/images/api/v2/__pycache__/serializers.cpython-310.pyc
vendored
Normal file
Binary file not shown.
BIN
env/lib/python3.10/site-packages/wagtail/images/api/v2/__pycache__/views.cpython-310.pyc
vendored
Normal file
BIN
env/lib/python3.10/site-packages/wagtail/images/api/v2/__pycache__/views.cpython-310.pyc
vendored
Normal file
Binary file not shown.
22
env/lib/python3.10/site-packages/wagtail/images/api/v2/serializers.py
vendored
Normal file
22
env/lib/python3.10/site-packages/wagtail/images/api/v2/serializers.py
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
from rest_framework.fields import Field
|
||||
|
||||
from wagtail.api.v2.serializers import BaseSerializer
|
||||
|
||||
|
||||
class ImageDownloadUrlField(Field):
|
||||
"""
|
||||
Serializes the "download_url" field for images.
|
||||
|
||||
Example:
|
||||
"download_url": "/media/images/a_test_image.jpg"
|
||||
"""
|
||||
|
||||
def get_attribute(self, instance):
|
||||
return instance
|
||||
|
||||
def to_representation(self, image):
|
||||
return image.file.url
|
||||
|
||||
|
||||
class ImageSerializer(BaseSerializer):
|
||||
download_url = ImageDownloadUrlField(read_only=True)
|
||||
23
env/lib/python3.10/site-packages/wagtail/images/api/v2/views.py
vendored
Normal file
23
env/lib/python3.10/site-packages/wagtail/images/api/v2/views.py
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
from wagtail.api.v2.filters import FieldsFilter, OrderingFilter, SearchFilter
|
||||
from wagtail.api.v2.views import BaseAPIViewSet
|
||||
|
||||
from ... import get_image_model
|
||||
from .serializers import ImageSerializer
|
||||
|
||||
|
||||
class ImagesAPIViewSet(BaseAPIViewSet):
|
||||
base_serializer_class = ImageSerializer
|
||||
filter_backends = [FieldsFilter, OrderingFilter, SearchFilter]
|
||||
body_fields = BaseAPIViewSet.body_fields + ["title", "width", "height"]
|
||||
meta_fields = BaseAPIViewSet.meta_fields + ["tags", "download_url"]
|
||||
listing_default_fields = BaseAPIViewSet.listing_default_fields + [
|
||||
"title",
|
||||
"tags",
|
||||
"download_url",
|
||||
]
|
||||
nested_default_fields = BaseAPIViewSet.nested_default_fields + [
|
||||
"title",
|
||||
"download_url",
|
||||
]
|
||||
name = "images"
|
||||
model = get_image_model()
|
||||
Reference in New Issue
Block a user