Exemple #1
0
    def __call__(self):
      """
        If a Web Section has a default document, we render
        the default document instead of rendering the Web Section
        itself.

        The implementation is based on the presence of specific
        variables in the REQUEST (besides editable_mode and
        ignore_layout).

        current_web_section -- defines the Web Section which is
        used to display the current document.

        current_web_document -- defines the Document (ex. Web Page)
        which is being displayed within current_web_section.

        is_web_section_default_document -- a boolean which is
        set each time we display a default document as a section.

        We use REQUEST parameters so that they are reset for every
        Web transaction and can be accessed from widgets. 
      """
      # Register current web site physical path for later URL generation
      if self.REQUEST.get(self.web_section_key, MARKER) is MARKER:
        self.REQUEST[self.web_section_key] = self.getPhysicalPath()
      self.REQUEST.set('current_web_section', self)
      if not self.REQUEST.get('editable_mode') and not self.REQUEST.get('ignore_layout'):
        document = None
        if self.isDefaultPageDisplayed():
          # The following could be moved to a typed based method for more flexibility
          document = self.getDefaultDocumentValue()
          if document is None:
            # no document found for current user, still such document may exists
            # in some cases user (like Anonymous) can not view document according to portal catalog
            # but we may ask him to login if such a document exists
            isAuthorizationForced = getattr(self, 'isAuthorizationForced', None)
            if isAuthorizationForced is not None and isAuthorizationForced():
              if unrestricted_apply(self.getDefaultDocumentValue) is not None:
                # force user to login as specified in Web Section
                raise Unauthorized
          if document is not None and document.getReference() is not None:
            # we use web_site_module/site_id/section_id/page_reference
            # as the url of the default document.
            self.REQUEST.set('current_web_document', document)
            self.REQUEST.set('is_web_section_default_document', 1)
            document = aq_base(document.asContext(
                id=document.getReference(),
                original_container=document.getParentValue(),
                original_id=document.getId(),
                editable_absolute_url=document.absolute_url())).__of__(self)
        # Try to use a custom renderer if any
        custom_render_method_id = self.getCustomRenderMethodId()
        if custom_render_method_id is not None:
          if document is None:
            document = self
          return getattr(document, custom_render_method_id)()
        elif document is not None:
          return document()
      return Domain.__call__(self)
Exemple #2
0
    def __call__(self):
        """
        If a Web Section has a default document, we render
        the default document instead of rendering the Web Section
        itself.

        The implementation is based on the presence of specific
        variables in the REQUEST (besides editable_mode and
        ignore_layout).

        current_web_section -- defines the Web Section which is
        used to display the current document.

        current_web_document -- defines the Document (ex. Web Page)
        which is being displayed within current_web_section.

        is_web_section_default_document -- a boolean which is
        set each time we display a default document as a section.

        We use REQUEST parameters so that they are reset for every
        Web transaction and can be accessed from widgets.
      """
        # Register current web site physical path for later URL generation
        if self.REQUEST.get(self.web_section_key, MARKER) is MARKER:
            self.REQUEST[self.web_section_key] = self.getPhysicalPath()
        self.REQUEST.set('current_web_section', self)
        if not self.REQUEST.get('editable_mode') and not self.REQUEST.get(
                'ignore_layout'):
            document = None
            if self.isDefaultPageDisplayed():
                # The following could be moved to a typed based method for more flexibility
                document = self.getDefaultDocumentValue()
                if document is None:
                    # no document found for current user, still such document may exists
                    # in some cases user (like Anonymous) can not view document according to portal catalog
                    # but we may ask him to login if such a document exists
                    isAuthorizationForced = getattr(self,
                                                    'isAuthorizationForced',
                                                    None)
                    if isAuthorizationForced is not None and isAuthorizationForced(
                    ):
                        if unrestricted_apply(
                                self.getDefaultDocumentValue) is not None:
                            # force user to login as specified in Web Section
                            raise Unauthorized
                if document is not None and document.getReference(
                ) is not None:
                    # we use web_site_module/site_id/section_id/page_reference
                    # as the url of the default document.
                    self.REQUEST.set('current_web_document', document)
                    self.REQUEST.set('is_web_section_default_document', 1)
                    document = aq_base(
                        document.asContext(
                            id=document.getReference(),
                            original_container=document.getParentValue(),
                            original_id=document.getId(),
                            editable_absolute_url=document.absolute_url())
                    ).__of__(self)
            else:
                isAuthorizationForced = getattr(self, 'isAuthorizationForced',
                                                None)
                if isAuthorizationForced is not None and isAuthorizationForced(
                ):
                    if self.getPortalObject(
                    ).portal_membership.isAnonymousUser():
                        # force anonymous to login
                        raise Unauthorized
            # Try to use a custom renderer if any
            custom_render_method_id = self.getCustomRenderMethodId()
            if custom_render_method_id is not None:
                if document is None:
                    document = self
                result = getattr(document, custom_render_method_id)()
                view = _ViewEmulator().__of__(self)
                # If we have a conditional get, set status 304 and return
                # no content
                if _checkConditionalGET(view, extra_context={}):
                    return ''
                # call caching policy manager.
                _setCacheHeaders(view, {})
                return result
            elif document is not None:
                return document()
        return Domain.__call__(self)