def get(self, instance, **kwargs):
        """ Return DataGridField value

        Value is a list object of rows.
        Row id dictionary object with standard 'link', 'uid' and 'title' keys
        plus extra informal *url* and *url_title* keys
        """
        purl = getToolByName(instance, "portal_url")
        # use portal_catalog to hide protected object for the logged in user.
        catalog = getToolByName(instance, "portal_catalog")

        result = []
        uids = {}
        rows = DataGridField.get(self, instance, **kwargs)

        for row in rows:
            uid = row.get("uid","")
            link = row.get("link","")
            title = decode(row.get("title",""), self)
            dataGridFieldRowData = row
            dataGridFieldRowData["url"] = ""
            dataGridFieldRowData["default_title"] = None
            if title:
                dataGridFieldRowData["title"] = title
            result.append(dataGridFieldRowData) 
            data = result[-1]
            if uid:
                uids[uid] = data
            else:
                # Process remote URL and collect UIDs
                data["url"] = quote(link, safe='?$#@/:=+;$,&%')
                data["default_title"] = link
                # if title not set for remote url - set it equals to url
                # manually entered link does not have title column field
                if not data.get("title"):
                    data["title"] = data["default_title"]
        # Process UIDs
        if uids:
            brains = catalog(UID=uids.keys())
            for b in brains:
                data = uids[b.UID]
                data["url"] = b.getURL()
                data["link"] = b.getPath()
                data["default_title"] = self._brains_title_or_id(b, instance)
                # If title not set - get it from the brain
                if not data["title"]:
                    data["title"] = data["default_title"]
            # Remove records with links to unexistent objects
            del_uids = set(uids.keys()) - set([b.UID for b in brains])
            result = filter(lambda r: not r["uid"] in del_uids, result)
        return result
Esempio n. 2
0
    def get(self, instance, **kwargs):
        """ Return DataGridField value

        Value is a list object of rows.
        Row id dictionary object with standard 'link', 'uid' and 'title' keys
        plus extra informal *url* and *url_title* keys
        """
        purl = getToolByName(instance, "portal_url")
        # use portal_catalog to hide protected object for the logged in user.
        catalog = getToolByName(instance, "portal_catalog")

        result = []
        uids = {}
        rows = DataGridField.get(self, instance, **kwargs)

        for row in rows:
            uid = row.get("uid", "")
            link = row.get("link", "")
            title = row.get("title", "")
            dataGridFieldRowData = row
            dataGridFieldRowData["url"] = ""
            dataGridFieldRowData["default_title"] = None
            result.append(dataGridFieldRowData)
            data = result[-1]
            if uid:
                uids[uid] = data
            else:
                # Process remote URL and collect UIDs
                data["url"] = quote(link, safe='?$#@/:=+;$,&%')
                data["default_title"] = link
                # if title not set for remote url - set it equals to url
                # manually entered link does not have title column field
                if not data.get("title"):
                    data["title"] = data["default_title"]
        # Process UIDs
        if uids:
            brains = catalog(UID=uids.keys())
            for b in brains:
                data = uids[b.UID]
                data["url"] = b.getURL()
                data["link"] = b.getPath()
                data["default_title"] = self._brains_title_or_id(b, instance)
                # If title not set - get it from the brain
                if not data["title"]:
                    data["title"] = data["default_title"]
            # Remove records with links to unexistent objects
            del_uids = set(uids.keys()) - set([b.UID for b in brains])
            result = filter(lambda r: not r["uid"] in del_uids, result)
        return result