Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 0 additions & 45 deletions docs/examples/integrations/dmr/model_file.py

This file was deleted.

1 change: 0 additions & 1 deletion docs/examples/integrations/fastapi/multiple_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
_SOURCE_URL: Final = 'https://originals.example.com/photo.jpg'

app = FastAPI()

get_signed_imgproxy = add_imgproxy( # (1)!
app,
Client(
Expand Down
4 changes: 1 addition & 3 deletions docs/examples/integrations/fastapi/variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
from imgproxykit.integrations.fastapi import add_imgproxy

_SOURCE_URL: Final = 'https://originals.example.com/photo.jpg'
_BASE: Final = Transform(format='webp')

app = FastAPI()

get_imgproxy = add_imgproxy(app, Client('https://imgproxy.example.com'))

_BASE: Final = Transform(format='webp')


@dataclass(frozen=True, slots=True)
class ProductImages:
Expand Down
27 changes: 1 addition & 26 deletions docs/pages/integrations/dmr.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,10 @@ for request parsing and handler definitions.
Return variants
---------------

For several image sizes, use ``imgproxy_variants`` and a nested response model.
Keep the imports and ``_SOURCE_URL`` from the previous example,
replacing the shortcut import with
``from imgproxykit.integrations.django import imgproxy_variants``:
For several image sizes, use ``imgproxy_variants`` and a nested response model:

.. literalinclude:: /examples/integrations/dmr/variants.py
:language: python
:start-at: class ProductImages

.. code-annotations::

Expand All @@ -110,27 +106,6 @@ See DMR's `OpenAPI guide
<https://django-modern-rest.readthedocs.io/en/latest/pages/openapi/openapi.html>`__
to publish the schema and interactive API documentation.

Model file fields
-----------------

For a product loaded from your database, pass ``product.image`` directly to
``imgproxy_url`` in the controller. Here, ``Product`` is your Django model
with an optional image field. ``ProductPath`` declares a ``product_id: int``
path parameter using a Pydantic model. Imports, the Django model, path model,
and the route are omitted from this snippet:

.. literalinclude:: /examples/integrations/dmr/model_file.py
:language: python
:start-at: class ProductResponse

.. code-annotations::

1. Generate a URL only when the file field has an associated file;
otherwise return ``None``, serialized as JSON ``null``.

Without the empty-field check, the default source
resolver raises ``ValueError`` for a field without an associated file.

Source resolution
-----------------

Expand Down
7 changes: 7 additions & 0 deletions docs/pages/integrations/drf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ fields used in the response:

.. code-block:: python

from rest_framework import serializers

from imgproxykit.integrations.drf import (
ImgproxyURLField,
ImgproxyVariantsField,
)

image = serializers.ImageField(write_only=True, required=False) # (1)!
thumbnail = ImgproxyURLField(source='image', transform='thumbnail')
images = ImgproxyVariantsField(source='image', variants='product')
Expand Down
Loading