def __call__(self, value): for field in self.fields: if field in value.keys(): link = value.get(field, "") if isinstance(link, str): value[field] = uid_to_url(link) elif isinstance(link, list): if len(link) > 0 and isinstance(link[0], dict) and "@id" in link[0]: result = [] for item in link: item_clone = deepcopy(item) item_clone["@id"] = uid_to_url(item_clone["@id"]) result.append(item_clone) value[field] = result elif len(link) > 0 and isinstance(link[0], str): value[field] = [uid_to_url(item) for item in link] return value
def __call__(self, value): # Resolve UID links: # ../resolveuid/023c61b44e194652804d05a15dc126f4 # -> # http://localhost:55001/plone/link-target entity_map = value.get("text", {}).get("entityMap", {}) for entity in entity_map.values(): if entity.get("type") == "LINK": url = entity.get("data", {}).get("url", "") entity["data"]["url"] = uid_to_url(url) return value
def __call__(self): if self.field.getName() != "remoteUrl": return super().__call__() value = self.get_value() # Expect that all internal links will have resolveuid if value and "resolveuid" in value: return uid_to_url(value) # Fallback in case we still have a variable in there path = replace_link_variables_by_paths(context=self.context, url=value) portal = getMultiAdapter((self.context, self.context.REQUEST), name="plone_portal_state").portal() # We should traverse unrestricted, just in case that the path to the object # is not all public, we should be able to reach it by finger pointing ref_obj = portal.unrestrictedTraverse(path, None) if ref_obj: value = ref_obj.absolute_url() return json_compatible(value) else: # The URL does not point to an existing object, so just return the value # without value interpolation return json_compatible(value.replace("${portal_url}", ""))
def handle_link(self, child): if child.get("data", {}).get("url"): child["data"]["url"] = uid_to_url(child["data"]["url"])
def _uid_to_url(self, context, path): return uid_to_url(path)