diff --git a/fs_file/fields.py b/fs_file/fields.py index bb53c2e424..fb5a46d41e 100644 --- a/fs_file/fields.py +++ b/fs_file/fields.py @@ -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: diff --git a/fs_file/readme/newsfragments/281.feature b/fs_file/readme/newsfragments/281.feature new file mode 100644 index 0000000000..a34f81be34 --- /dev/null +++ b/fs_file/readme/newsfragments/281.feature @@ -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*). diff --git a/fs_file/tests/test_fs_file.py b/fs_file/tests/test_fs_file.py index 193e31375d..6b4e8a6b30 100644 --- a/fs_file/tests/test_fs_file.py +++ b/fs_file/tests/test_fs_file.py @@ -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({})