added full_url field for image rendition field api

- resolves #7558
pull/8395/head
Paarth Agarwal 2022-04-16 16:36:53 +05:30 zatwierdzone przez LB (Ben Johnston)
rodzic fec647d8aa
commit da78e0f449
4 zmienionych plików z 9 dodań i 1 usunięć

Wyświetl plik

@ -7,6 +7,7 @@ unreleased (xx.xx.xxxx) - IN DEVELOPMENT
* Add clarity to confirmation when being asked to convert an external link to an internal one (Thijs Kramer)
* Convert various pages in the documentation to Markdown (Daniel Kirkham)
* Add `base_url_path` to `ModelAdmin` so that the default URL structure of app_label/model_name can be overridden, sub-classes of `AdminURLHelper` overriding `__init__` will need to accept a new kwarg of `base_url_path` (Vu Pham, Khanh Hoang)
* Add `full_url` to the API output of `ImageRenditionField` (Paarth Agarwal)
3.0 (xx.xx.xxxx) - IN DEVELOPMENT

Wyświetl plik

@ -206,6 +206,7 @@ For example:
.. code-block:: python
from wagtail.api import APIField
from wagtail.images.api.fields import ImageRenditionField
class BlogPage(Page):
@ -239,6 +240,7 @@ This would add the following to the JSON:
},
"feed_image_thumbnail": {
"url": "/media/images/a_test_image.fill-100x100.jpg",
"full_url": "http://www.example.com/media/images/a_test_image.fill-100x100.jpg",
"width": 100,
"height": 100,
"alt": "image alt text"

Wyświetl plik

@ -13,6 +13,7 @@ class ImageRenditionField(Field):
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"
@ -37,6 +38,7 @@ class ImageRenditionField(Field):
return OrderedDict(
[
("url", thumbnail.url),
("full_url", thumbnail.full_url),
("width", thumbnail.width),
("height", thumbnail.height),
("alt", thumbnail.alt),

Wyświetl plik

@ -15,8 +15,11 @@ class TestImageRenditionField(TestCase):
def test_api_representation(self):
rendition = self.image.get_rendition("width-400")
representation = ImageRenditionField("width-400").to_representation(self.image)
self.assertEqual(set(representation.keys()), {"url", "width", "height", "alt"})
self.assertEqual(
set(representation.keys()), {"url", "full_url", "width", "height", "alt"}
)
self.assertEqual(representation["url"], rendition.url)
self.assertEqual(representation["full_url"], rendition.full_url)
self.assertEqual(representation["width"], rendition.width)
self.assertEqual(representation["height"], rendition.height)
self.assertEqual(representation["alt"], rendition.alt)