Skip to content

Commit 9f0c956

Browse files
committed
Enable swapping the image processor via a setting
To simplify customizations the image processort can be swapped. Previously, it was necessary to override the PictureFieldFile. Now, all that needs to be done is setting a custom value for the `PICTURES["PROCESSOR"]` setting.
1 parent ecce607 commit 9f0c956

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ PICTURES = {
8585
"CONTAINER_WIDTH": 1200,
8686
"FILE_TYPES": ["WEBP"],
8787
"PIXEL_DENSITIES": [1, 2],
88-
"USE_PLACEHOLDERS": True
88+
"USE_PLACEHOLDERS": True,
89+
"QUEUE_NAME": "pictures",
90+
"PROCESSOR": "pictures.tasks.process_picture",
91+
8992
}
9093
```
9194

@@ -207,6 +210,11 @@ If you have either Dramatiq or Celery installed, we will default to async
207210
image processing. You will need workers to listen to the `pictures` queue.
208211
You can override the queue name, via the `PICTURES["QUEUE_NAME"]` setting.
209212

213+
You can also override the processor, via the `PICTURES["PROCESSOR"]` setting.
214+
The default processor is `pictures.tasks.process_picture`. It takes a single
215+
argument, the `PictureFileFile` instance. You can use this to override the
216+
processor, should you need to do some custom processing.
217+
210218
## Migrations
211219

212220
Django doesn't support file field migrations, but we do.

pictures/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def get_settings():
2121
"PIXEL_DENSITIES": [1, 2],
2222
"USE_PLACEHOLDERS": settings.DEBUG,
2323
"QUEUE_NAME": "pictures",
24+
"PROCESSOR": "pictures.tasks.process_picture",
2425
**getattr(settings, "PICTURES", {}),
2526
},
2627
)

pictures/models.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
__all__ = ["PictureField", "PictureFieldFile"]
1818

19+
from django.utils.module_loading import import_string
1920

2021
from pictures import conf, utils
2122

@@ -98,9 +99,7 @@ def save(self, name, content, save=True):
9899

99100
def save_all(self):
100101
if self:
101-
from . import tasks
102-
103-
tasks.process_picture(self)
102+
import_string(conf.get_settings().PROCESSOR)(self)
104103

105104
def delete(self, save=True):
106105
self.delete_all()

0 commit comments

Comments
 (0)