Created
November 11, 2025 22:22
-
-
Save cnk/be9e0269b178605c7e0769f47c9c1a3b to your computer and use it in GitHub Desktop.
Documents in subfolders in s3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AbstractPermissionedDocument(AbstractDocument): | |
| """ | |
| We are now using a patched version of Wagtails document permissions via collection permissions | |
| and using WAGTAILDOCS_SERVE_METHOD = 'serve_view' so users never see the S3 url for documents. | |
| Note, however, that they'll still see the base filename in the URLs that Wagtail | |
| serves. | |
| We monkey patch the serve() method to set cache control headers to private. The code | |
| for this is in multitenant.wagtail_patches.views.misc.py | |
| """ | |
| file = S3FileField(upload_to=get_upload_to, verbose_name="file", max_length=255) | |
| admin_form_fields = Document.admin_form_fields | |
| class Meta: | |
| abstract = True | |
| def get_upload_to(self, filename): | |
| # This function is called by wagtail.documents.models.get_upload_to(), to which self.file.upload_to is set. | |
| full_path = PurePath(get_collection_path(self.collection), "documents", filename) | |
| return str(full_path) | |
| class PermissionedDocument(AbstractPermissionedDocument): | |
| search_fields = [ | |
| *AbstractDocument.search_fields, | |
| index.FilterField("created_at"), | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment