Skip to content

Enable swapping the image processor via a setting #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 24, 2023
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
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ PICTURES = {
"CONTAINER_WIDTH": 1200,
"FILE_TYPES": ["WEBP"],
"PIXEL_DENSITIES": [1, 2],
"USE_PLACEHOLDERS": True
"USE_PLACEHOLDERS": True,
"QUEUE_NAME": "pictures",
"PROCESSOR": "pictures.tasks.process_picture",

}
```

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

You can also override the processor, via the `PICTURES["PROCESSOR"]` setting.
The default processor is `pictures.tasks.process_picture`. It takes a single
argument, the `PictureFileFile` instance. You can use this to override the
processor, should you need to do some custom processing.

## Migrations

Django doesn't support file field migrations, but we do.
Expand Down
1 change: 1 addition & 0 deletions pictures/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def get_settings():
"PIXEL_DENSITIES": [1, 2],
"USE_PLACEHOLDERS": settings.DEBUG,
"QUEUE_NAME": "pictures",
"PROCESSOR": "pictures.tasks.process_picture",
**getattr(settings, "PICTURES", {}),
},
)
5 changes: 2 additions & 3 deletions pictures/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

__all__ = ["PictureField", "PictureFieldFile"]

from django.utils.module_loading import import_string

from pictures import conf, utils

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

def save_all(self):
if self:
from . import tasks

tasks.process_picture(self)
import_string(conf.get_settings().PROCESSOR)(self)

def delete(self, save=True):
self.delete_all()
Expand Down