Images management command to purge and regenerate renditions
See original GitHub issueIs your proposal related to a problem?
- Occasionally, you can create problems when syncing data from production environments or you just want to clear out unused renditions.
- There are also cases where there is a need to clear space on a server and we may want to intentionally only load image renditions when requested.
Describe the solution you’d like
A new management command, in the images app, that provides the ability to regenerate image renditions. With an optional argument to also purge any existing ones.
manage.py update_image_renditions
- will regenerate all the rendition images (not the DB entries)manage.py update_image_renditions --purge
- will first purge all rendition images and then regenerate all the rendition imagesmanage.py update_image_renditions --purge-only
- will ONLY purge all rendition images
Describe alternatives you’ve considered
- Use something like
rm -rf
within the media folder, however this risks removing images that are not renditions, plus will mean that the next load for users will be slow for each image needed.
Additional context
- See the documented method of writing Django Management commands https://docs.djangoproject.com/en/4.0/howto/custom-management-commands/
- There is an old PR that started this https://github.com/wagtail/wagtail/pull/759 - could be a good reference
- There is also this PR that may be covering similar functionality https://github.com/wagtail/wagtail/pull/6595
- Use the Django documented
self.stdout.write("Unterminated line", ending='')
andself.stdout.write(self.style.SUCCESS('Successfully closed poll "%s"' % poll_id))
for messages, notprint
- Should have documentation added to the page https://docs.wagtail.org/en/stable/reference/management_commands.html
- Needs unit tests
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Optimizing drawing files in AutoCAD with Purge, Audit ...
For AutoCAD 2012 and later versions, the PURGE and RECOVER command can be performed simultaneously by using the DWGCONVERT utility.
Read more >Management commands - Wagtail's documentation
Options: –purge-only : This argument will purge all image renditions without regenerating them. They will be regenerated when next requested.
Read more >Repair a Windows Image | Microsoft Learn
This command will not unmount images that are already mounted, nor will it delete images that can be recovered using the /Remount-Image command....
Read more >Image management best practices | Compute Engine ...
To completely delete the image and its data, you must send an explicit delete command for that image. Sharing images between projects. Organizations...
Read more >Management commands - sorl-thumbnail - Read the Docs
This cleans up the Key Value Store from stale cache. It removes references to images that do not exist and thumbnail references and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That makes sense and appears to summarise correctly @Hitansh-Shah
As noted above, feel free to start with a simple version of this that simply purges (deletes) renditions (even if that means a different name is needed.
Please also namespace the command.
wagtail_update_image_renditions
See https://github.com/wagtail/wagtail/issues/8162 for context
Hey @lb- , so I looked into the resources and the requirements of this issue. So I am just confirming what I understood so far and what I am planning to do. For regenerating the renditions I will just loop through all the renditions and for each rendition I will use the
get_rendition
method onrendition.image
withrendition.filter
as the parameter (all of this in the command function obviously). This will regenerate each and every rendition. I don’t know if I have caught on to the problem, please correct me if I am wrong. If I am in the right direction do let me know so that I can open a draft Pr to work further. Thanks