예제 #1
0
    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
예제 #2
0
 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
예제 #3
0
    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}", ""))
예제 #4
0
 def handle_link(self, child):
     if child.get("data", {}).get("url"):
         child["data"]["url"] = uid_to_url(child["data"]["url"])
예제 #5
0
 def _uid_to_url(self, context, path):
     return uid_to_url(path)