Skip to content

Commit

Permalink
[IMP] fs_file: New property 'url_path' on FSFileValue object
Browse files Browse the repository at this point in the history
In the same time ensures the value is None for the 'url', 'url_path' and 'internal_url' properties if not available (instead of 'False')
  • Loading branch information
lmignon committed Sep 28, 2023
1 parent f6aed7f commit 04bc881
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions fs_file/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,15 @@ def size(self) -> int:

@property
def url(self) -> str | None:
return self._attachment.url if self._attachment else None
return self._attachment.url or None if self._attachment else None

@property
def internal_url(self) -> str | None:
return self._attachment.internal_url if self._attachment else None
return self._attachment.internal_url or None if self._attachment else None

@property
def url_path(self) -> str | None:
return self._attachment.fs_url_path or None if self._attachment else None

@property
def attachment(self) -> IrAttachment | None:
Expand Down
7 changes: 7 additions & 0 deletions fs_file/readme/newsfragments/281.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Add a *url_path* property on the *FSFileValue* object. This property
allows you to easily get access to the relative path of the file on
the filesystem. This value is only available if the filesystem storage
is configured with a *Base URL* value.

The *url_path*, *url* and *internal_url* properties on the *FSFileValue*
object return *None* if the information is not available (instead of *False*).
2 changes: 2 additions & 0 deletions fs_file/tests/test_fs_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def _test_create(self, fs_file_value):
self.assertTrue(isinstance(instance.fs_file, FSFileValue))
self.assertEqual(instance.fs_file.getvalue(), self.create_content)
self.assertEqual(instance.fs_file.name, self.filename)
self.assertEqual(instance.fs_file.url_path, None)
self.assertEqual(instance.fs_file.url, None)

def _test_write(self, fs_file_value, **ctx):
instance = self.env["test.model"].create({})
Expand Down

0 comments on commit 04bc881

Please sign in to comment.