Make MimetypeHandlers take care of deleting associated files for a file attachment.
Review Request #13141 — Created July 13, 2023 and submitted
Currently we have no centralized method for deleting extra files associated
with file attachments, such as thumbnail files. This adds a
delete_associated_files
method to the baseMimetypeHandler
class, which
can be implemented by subclasses to take care of deleting any extra associated
files that are created for file attachments of certain mimetypes. This also
updates theImageMimetype
class to delete the files it creates for thumbnails.
- Tested in an upcoming change where deleting draft file attachments will
trigger deleting all files associated with the draft. - Ran unit tests.
Summary | ID |
---|---|
703c798031b051fc96aa2847144a1184a9db3dbe |
Description | From | Last Updated |
---|---|---|
Might be worth centralizing the list of available thumbnail files using some function, and then using that in both get_thumbnail() … |
chipx86 | |
Can you show me an example of how these paths end up looking? The before/after? I feel like there's got … |
chipx86 | |
Can you add -> None for each of these, so we can do type checking as part of tests? |
chipx86 | |
Just for alignment purposes, we can prefix all these with f, even if we're not putting in any format strings. … |
chipx86 | |
Add a blank line between these two. |
david | |
Missing trailing comma. |
chipx86 | |
We can just use attachment, since we have that locally. |
chipx86 | |
lstrip() isn't safe. It doesn't remove a prefix. It removes any leading characters found in the provided string. So, any … |
chipx86 |
- Change Summary:
-
- Moved to RB6.
- Commits:
-
Summary ID 890c0ac5f9f90eb78fd5c80eecf9c5c6ba57e900 9d92b9af22ed0348151e5042e975fb73402e0a3e - Branch:
-
release-5.0.xrelease-6.x
Checks run (2 succeeded)
-
-
Might be worth centralizing the list of available thumbnail files using some function, and then using that in both
get_thumbnail()
and in here. Maybe something that supplies the filename and the 1x/2x/etc. This will also help us scale up thumbnails for higher-res displays down the road. -
Can you show me an example of how these paths end up looking? The before/after? I feel like there's got to be another way to do what we want to do here.
-
-
Just for alignment purposes, we can prefix all these with
f
, even if we're not putting in any format strings.There's no difference to Python. A format string that doesn't format just becomes a string.
>>> import dis >>> def foo(): ... return ( ... 'test' ... f'{hi}' ... 'bar' ... ) ... >>> def bar(): ... return ( ... f'test' ... f'{hi}' ... f'bar' ... ) ... >>> dis.dis(foo) == dis.dis(bar) True
- Description:
-
Currently we have no centralized method for deleting extra files associated
with file attachments, such as thumbnail files. This adds a delete_associated_files
method to the baseMimetypeHandler
class, whichcan be implemented by subclasses to take care of deleting any extra associated ~ files that are created for file attachments of certain mimetypes. This change ~ files that are created for file attachments of certain mimetypes. This also updates the ImageMimetype
class to delete the files it creates for thumbnails. - Commits:
-
Summary ID 9d92b9af22ed0348151e5042e975fb73402e0a3e 5fb3e05b973ea6579baa617a247deba6b489bf58
Checks run (2 succeeded)
- Commits:
-
Summary ID 5fb3e05b973ea6579baa617a247deba6b489bf58 ad35ffde62324aff1a8413afad9548c85d260ec5
Checks run (2 succeeded)
-
-
-
-
lstrip()
isn't safe. It doesn't remove a prefix. It removes any leading characters found in the provided string. So, any characters listed insite_media_url
will be removed from the beginning of the URL.Ideally we'd use
removeprefix()
, but that's only in 3.9+. So you'd instead need to do:if t.startswith(site_media_url): t = t[len(site_media_url):]
Or maybe assert that it starts with it? Or skip/log if it doesn't?