Comments (3)
For the record, I ended up with monkey patching the resizing method, catching
exception when a speific setting is toggled.
This is because I wanted to have thumbnails on development when possible,
and nothing when the media files don't exists.
# myproject/apps.py
from versatileimagefield.datastructures import sizedimage
def monkeypatch_versatile_image_field():
"""
To bypass
https://github.com/respondcreate/django-versatileimagefield/issues/59
we monkey patch versatile image field to silent error when
a specific setting is toggled
"""
def dec(func):
def wrapper(self, *args, **kwargs):
try:
return func(self, *args, **kwargs)
except FileNotFoundError:
if settings.ALLOW_MISSING_MEDIA:
return
raise
return wrapper
kls = sizedimage.SizedImage
kls.create_resized_image = dec(kls.create_resized_image)
class ProjecyConfig(AppConfig):
name = "myproject"
def ready(self):
monkeypatch_versatile_image_field()
This way, the monkey patching is only triggered when apps are fully loaded.
If you set ALLOW_MISSING_MEDIA
to True
in your settings, you won't have any
error due to FileNotFound. However, you will still have thumbnails when a media file exists.
from django-versatileimagefield.
Hey @EliotBerriot–
This is a common request (your the third person so far to what this kind of functionality)! Though I absolutely understand why you'd want that to be included the IOError-raising that you described is the expected behavior (i.e. VersatileImageField
functions identically to how Django's FileField
and ImageField
would in the same situation). For more info, check out this comment I wrote in response to a similar issue.
from django-versatileimagefield.
Ok, thank you for the explanation, I totally understand why you're reluctant to implement a different behaviour than django's one. I'll explore the alternative you explore with create_on_demand
in the issue you linked :)
from django-versatileimagefield.
Related Issues (20)
- Unclear docs on using VersatileImageFieldWarmer with rendition sets HOT 1
- python-magic 0.4.20 incompatible
- Fails to work with django-cacheops HOT 2
- How to store filename returned by storage for sized images? HOT 1
- Test with Python3.9
- Test with Django 3.1 and 3.2
- Add Django 3.2 Compatibility HOT 1
- Test with djangorestframework 3.11 and 3.12
- error to upload images using django-rest and angular HOT 1
- versatileimagefield How to use Django Graphql
- Deleting all created images for the image without extension fails
- VersatileImageFieldWarmer regenerate images for delete rendition key set
- Question: is it possible to use this app with static files?
- AttributeError: module 'magic' has no attribute 'from_buffer' HOT 1
- Django 4 HOT 3
- Question: Crop as circle
- Extra queries when warming with VersatileImageFieldWarmer
- django-versatileimagefield doesn't work on Pillow >= 10.0.0 released 1 July HOT 5
- Created images not deleted when using image_key_post_processor
- Configurable exception handling
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-versatileimagefield.