Skip to content

Commit 96fcd26

Browse files
Cherry pick ef445e2 Option to transform primary field target to provide information about the target rather than just it's URL plone#1903
1 parent c1dc83c commit 96fcd26

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/plone/restapi/serializer/dxfields.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from zope.schema.interfaces import IVocabularyTokenized
2424

2525
import logging
26+
import os
2627

2728

2829
log = logging.getLogger(__name__)
@@ -203,6 +204,19 @@ def __call__(self):
203204
if namedfile is None:
204205
return
205206

207+
enable_transform = os.environ.get("enable_link_target_transform", False)
208+
209+
if enable_transform:
210+
download_url = "/".join((self.context.absolute_url(), "@@download", self.field.__name__))
211+
result = {
212+
"url": self.context.absolute_url(),
213+
"download": download_url,
214+
"filename": namedfile.filename,
215+
"content-type": namedfile.contentType,
216+
"size": namedfile.getSize(),
217+
}
218+
return json_compatible(result)
219+
206220
return "/".join(
207221
(self.context.absolute_url(), "@@download", self.field.__name__)
208222
)

0 commit comments

Comments
 (0)