예제 #1
0
 def __call__(self, value):
     value = super().__call__(value)
     if self.field.getName() == "remoteUrl":
         portal = getMultiAdapter(
             (self.context, self.context.REQUEST), name="plone_portal_state"
         ).portal()
         portal_url = portal.portal_url()
         if value.startswith(portal_url) or value.startswith("/"):
             value = path2uid(context=self.context, link=value)
     return value
예제 #2
0
 def __call__(self, block):
     # Convert absolute links to resolveuid
     #   http://localhost:55001/plone/link-target
     #   ->
     #   ../resolveuid/023c61b44e194652804d05a15dc126f4
     entity_map = block.get("text", {}).get("entityMap", {})
     for entity in entity_map.values():
         if entity.get("type") == "LINK":
             href = entity.get("data", {}).get("url", "")
             entity["data"]["url"] = path2uid(context=self.context,
                                              link=href)
     return block
예제 #3
0
    def __call__(self, block):
        # Convert absolute links to resolveuid
        for field in self.fields:
            link = block.get(field, "")
            if link and isinstance(link, str):
                block[field] = path2uid(context=self.context, link=link)
            elif link and isinstance(link, list):
                # Detect if it has an object inside with an "@id" key (object_widget)
                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"] = path2uid(context=self.context,
                                                     link=item_clone["@id"])
                        result.append(item_clone)

                    block[field] = result
                elif len(link) > 0 and isinstance(link[0], str):
                    block[field] = [
                        path2uid(context=self.context, link=item)
                        for item in link
                    ]
        return block
예제 #4
0
 def handle_link(self, child):
     if child.get("data", {}).get("url"):
         child["data"]["url"] = path2uid(self.context, child["data"]["url"])
예제 #5
0
 def __call__(self, block):
     url = block.get("url", "")
     block["url"] = path2uid(context=self.context, link=url)
     return block