django-url-renditions
django-url-renditions allows to define and render renditions from django url fields. This works also pretty well with django-s3direct fields.
It comes with a Graphene Query that enable renditions in your GraphQL schema.
Install
pip install django-url-renditions
Add url_renditions to your INSTALLED_APPS
Define your model
from django.db import models
from url_renditions.fields import FileUrlWithRenditions
# django-url-renditions comes with a simple image resizer method.
# Look at the implementation if you need something more specific
from url_renditions.resize_image import ResizeImage
class Track(models.Model):
original_artwork = models.URLField()
artwork = FileUrlWithRenditions(
source='original_artwork',
use_job_runner=True, # if we want to queue the job with django_rq
renditions={
'small': ResizeImage('80x80'),
'medium': ResizeImage('300x300'),
}
)
That way, when a Track model get created with an original_artwork, artwork will be automatically polulated with two renditions: small and medium.
To access them, use:
r = my_track.artwork.rendition_set.get(name='small')
print('url:', r.href, 'width:', r.width, 'height:', r.height)
Graphql with Graphene
Add url_renditions.graphql_schema.Query to your root query.
import graphene
import url_renditions.graphql_schema # noqa
class Query(
...
url_renditions.graphql_schema.Query,
graphene.ObjectType):
pass
schema = graphene.Schema(query=Query)
Then when you ask for
{
track(id: "VHJhY2s6OA==") {
artwork {
renditions {
medium {
href
width
height
}
}
}
}
}
You get
{
"data": {
"track": {
"artwork": {
"renditions": {
"medium": {
"href": "https://images.unsplash.com/photo-1474314170901-f351b68f544f",
"width": 300,
"height": 300
}
}
}
}
}
}
Metadata
Release files for django-url-renditions 1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-url-renditions-1.4.tar.gz | 6.7 kB | Without provenance | Details for django-url-renditions-1.4.tar.gz |
Release files / django-url-renditions-1.4.tar.gz
| Download URL | django-url-renditions-1.4.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
380ea49f004b11b0efed7a80cadbf600315d20850a89006a08cdd00d304658b9
|
|
BLAKE2b-256 checksum How to use checksums |
ba2962a30d5caf1fb599305846b682c72b52e0654fea0416866d3a9847991f2c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.5
|
Security for django-url-renditions 1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.