♻️(documents) store document file in object storage in a folder
We will need to store more than a file for a document: multiple languages, images, etc. For this, the document ID should be a folder and the content a file in this folder.
This commit is contained in:
committed by
Samuel Paccoud
parent
9c19b22a66
commit
b4e4ba3516
@@ -316,12 +316,19 @@ class Document(BaseModel):
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
@property
|
||||
def key_base(self):
|
||||
"""Key base of the location where the document is stored in object storage."""
|
||||
if not self.pk:
|
||||
raise RuntimeError(
|
||||
"The document instance must be saved before requesting a storage key."
|
||||
)
|
||||
return str(self.pk)
|
||||
|
||||
@property
|
||||
def file_key(self):
|
||||
"""Key of the object storage file to which the document content is stored"""
|
||||
if not self.pk:
|
||||
return None
|
||||
return str(self.pk)
|
||||
return f"{self.key_base}/file"
|
||||
|
||||
@property
|
||||
def content(self):
|
||||
|
||||
@@ -47,6 +47,12 @@ def test_models_documents_title_max_length():
|
||||
factories.DocumentFactory(title="a" * 256)
|
||||
|
||||
|
||||
def test_models_documents_file_key():
|
||||
"""The file key should be built from the instance uuid."""
|
||||
document = factories.DocumentFactory(id="9531a5f1-42b1-496c-b3f4-1c09ed139b3c")
|
||||
assert document.file_key == "9531a5f1-42b1-496c-b3f4-1c09ed139b3c/file"
|
||||
|
||||
|
||||
# get_abilities
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user