예제 #1
0
    def transformIterable(self, result, encoding):
        pagerequest = CustomPageRequest(self.request)

        if not pagerequest.apply_transformation:
            return result

        # use the tree from plone.app.theming to avoid building it ourselves
        tree = ThemeTransform(self.published, self.request).parseTree(result)
        tree = tree.tree if tree else None

        if not tree:
            return result

        # save the tree on the instance for testing, when running for real
        # plone.app.theming / diazo will take care of serializing the tree
        self._tree = tree

        path = pagerequest.original_path

        for a in tree.xpath("//a[contains(@href, '%s')]" % path):
            a.attrib['href'] = pagerequest.transform_url(a.attrib['href'])

        for form in tree.xpath("//form[contains(@action, '%s')]" % path):
            form.attrib['action'] = pagerequest.transform_url(
                form.attrib['action']
            )

        return result