Ejemplo n.º 1
0
    def get_page_source(self):
        """ Returns the HTML source of a web page, considering
        that the URL of the page is contained in the form under
        the 'page_url' key.
        """

        if not 'page_url' in self.request.form:
            self.errors.append('no_source')
            return

        url = self.request.form['page_url']
        context_url = self.context.absolute_url()

        view_name, get_params = extract_from_url(url, context_url)

        # Now we will reinject the GET parameters in the request.
        if get_params:
            for key in get_params:
                self.request.form[key] = get_params[key]

        if not view_name:
            ttool = getToolByName(self.context, 'portal_types')
            if self.context.portal_type in ttool:
                context_type = ttool[self.context.portal_type]
                view_name = context_type.getProperty('immediate_view')

        try:
            view = self.context.restrictedTraverse(view_name)
        except:
            return

        return update_relative_url(view(), self.context)
Ejemplo n.º 2
0
    def get_page_source(self):
        """ Returns the HTML source of a web page, considering
        that the URL of the page is contained in the form under
        the 'page_url' key.
        """

        if not 'page_url' in self.request.form:
            self.errors.append('no_source')
            return

        url = self.request.form['page_url']
        context_url = self.context.absolute_url()

        view_name, get_params = extract_from_url(url, context_url)

        # Now we will reinject the GET parameters in the request.
        if get_params:
            for key in get_params:
                self.request.form[key] = get_params[key]

        try:
            view = self.context.restrictedTraverse(view_name)
        except:
            # For some reason, 'view' as view name can fail (at least
            # in a client project in Plone 3.3.5), where calling the
            # same url in a browser works just fine...  The error here is:
            # AttributeError: 'view' object has no attribute '__of__'
            # Just take the context as view then.

            # Note that this has the same effect as calling
            # self.context.restrictedTraverse(x), where x is None or
            # an empty string.
            view = self.context

        return update_relative_url(view(), self.context)