Exemple #1
0
    def localBuild(self, activity_kw=()):
      """Activate builders for this delivery

      The generated activity will find all buildable business links for this
      delivery, and call related builders, which will select all simulation
      movements part of the same explanation(s) as the delivery.

      XXX: Consider moving it to SimulableMixin if it's useful for
           Subscription Items.
      """
      # XXX: Previous implementation waited for expand activities of related
      #      documents and even suggested to look at explanation tree,
      #      instead of causalities. Is it required ?
      kw = {'priority': 3}
      kw.update(activity_kw)
      after_tag = kw.pop('after_tag', None)
      if isinstance(after_tag, basestring):
        after_tag = [after_tag]
      else:
        after_tag = list(after_tag) if after_tag else []
      # Now that 'delivery' category relation are indexed in ZODB, this is the
      # only method that depends on built: tag (via _updateSimulation), which
      # is still required because builders only use catalog to find buildable
      # movements and we don't want to miss any for local building.
      after_tag.append('expand:' + self.getPath())
      sm = getSecurityManager()
      newSecurityManager(None, nobody)
      try:
        unrestricted_apply(self.activate(after_tag=after_tag, **kw)._localBuild)
      finally:
        setSecurityManager(sm)
Exemple #2
0
    def localBuild(self, activity_kw=()):
        """Activate builders for this delivery

      The generated activity will find all buildable business links for this
      delivery, and call related builders, which will select all simulation
      movements part of the same explanation(s) as the delivery.

      XXX: Consider moving it to SimulableMixin if it's useful for
           Subscription Items.
      """
        # XXX: Previous implementation waited for expand activities of related
        #      documents and even suggested to look at explanation tree,
        #      instead of causalities. Is it required ?
        kw = {'priority': 3}
        kw.update(activity_kw)
        after_tag = kw.pop('after_tag', None)
        if isinstance(after_tag, basestring):
            after_tag = [after_tag]
        else:
            after_tag = list(after_tag) if after_tag else []
        after_tag.append('build:' + self.getPath())
        sm = getSecurityManager()
        newSecurityManager(None, nobody)
        try:
            unrestricted_apply(
                self.activate(after_tag=after_tag, **kw)._localBuild)
        finally:
            setSecurityManager(sm)
    def getExtensibleContent(self, request, name):
        old_manager, user = self._forceIdentification(request)
        # Next get the document per name
        portal = self.getPortalObject()
        document = self.getDocumentValue(name=name, portal=portal)
        # restore original security context if there's a logged in user
        if user is not None:
            setSecurityManager(old_manager)
        if document is not None:
            document = aq_base(
                document.asContext(
                    id=
                    name,  # Hide some properties to permit locating the original
                    original_container=document.getParentValue(),
                    original_id=document.getId(),
                    editable_absolute_url=document.absolute_url()))
            return document.__of__(self)

        # 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.getDocumentValue,
                                  (name, portal)) is not None:
                # force user to login as specified in Web Section
                raise Unauthorized
Exemple #4
0
    def getPriceCalculationOperandDict(self, default=None, context=None, **kw):
        """Return a dict object which contains operands used for price
    calculation. The returned items depend on a site configuration,
    because this will invoke a custom script at the end. The only
    assumption is that the dict must contain a key 'price'
    which represents the final result of the price calculation.

    The purpose is to obtain descriptive information to notify the user
    of how a price is calculated in details, in particular, for invoices
    and quotations. So a script which is eventually called should provide
    all values required for generating such reports (e.g. a price,
    a price without a discount, and a discount).
    """
        # First, try a type-based method, and if not present, use
        # the good-old-days way (which only returns a final result).
        if context is None:
            context = self
        method = context._getTypeBasedMethod('getPriceCalculationOperandDict')
        if method is None:
            # Try this, because when the context is an instance of a derived
            # class of Movement, Movement_getPriceCalculationOperandDict is
            # not searched.
            method = getattr(context,
                             'Movement_getPriceCalculationOperandDict', None)
        if method is not None:
            operand_dict = unrestricted_apply(method, kw=kw)
            if operand_dict is None:
                return default
            assert 'price' in operand_dict
            return operand_dict
        return {'price': context.Movement_lookupPrice()}
Exemple #5
0
  def getPriceCalculationOperandDict(self, default=None, context=None, **kw):
    """Return a dict object which contains operands used for price
    calculation. The returned items depend on a site configuration,
    because this will invoke a custom script at the end. The only
    assumption is that the dict must contain a key 'price'
    which represents the final result of the price calculation.

    The purpose is to obtain descriptive information to notify the user
    of how a price is calculated in details, in particular, for invoices
    and quotations. So a script which is eventually called should provide
    all values required for generating such reports (e.g. a price,
    a price without a discount, and a discount).
    """
    # First, try a type-based method, and if not present, use
    # the good-old-days way (which only returns a final result).
    if context is None:
      context = self
    method = context._getTypeBasedMethod('getPriceCalculationOperandDict')
    if method is None:
      # Try this, because when the context is an instance of a derived
      # class of Movement, Movement_getPriceCalculationOperandDict is
      # not searched.
      method = getattr(context, 'Movement_getPriceCalculationOperandDict', None)
    if method is not None:
      operand_dict = unrestricted_apply(method, kw=kw)
      if operand_dict is None:
        return default
      assert 'price' in operand_dict
      return operand_dict
    return {'price': context.Movement_lookupPrice()}
Exemple #6
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 #7
0
 def getPriceCalculationOperandDict(self, default=None, context=None,
         REQUEST=None, **kw):
   """Return a dictionary which contains operands for price calculation.
   Consult the doc string in Movement.getPriceCalculationOperandDict
   for more details.
   """
   kw.update(default=default, movement=context, REQUEST=REQUEST)
   return unrestricted_apply(
     self._getTypeBasedMethod('getPriceCalculationOperandDict'), kw=kw)
Exemple #8
0
 def getPriceCalculationOperandDict(self, default=None, context=None,
         REQUEST=None, **kw):
   """Return a dictionary which contains operands for price calculation.
   Consult the doc string in Movement.getPriceCalculationOperandDict
   for more details.
   """
   kw.update(default=default, movement=context, REQUEST=REQUEST)
   return unrestricted_apply(
     self._getTypeBasedMethod('getPriceCalculationOperandDict'), kw=kw)
Exemple #9
0
 def asPredicate(self):
     """
   This method tries to convert the current Document into a predicate
   looking up methods named Class_asPredicate, MetaType_asPredicate, PortalType_asPredicate
 """
     cache = getTransactionalVariable()
     key = "asPredicate", self
     try:
         return cache[key]
     except KeyError:
         self = unrestricted_apply(self._getTypeBasedMethod("asPredicate", "_asPredicate"))
         cache[key] = self
         return self
Exemple #10
0
 def asPredicate(self):
   """
     This method tries to convert the current Document into a predicate
     looking up methods named Class_asPredicate, MetaType_asPredicate, PortalType_asPredicate
   """
   cache = getTransactionalVariable()
   key = 'asPredicate', self
   try:
     return cache[key]
   except KeyError:
     self = unrestricted_apply(self._getTypeBasedMethod("asPredicate", "_asPredicate"))
     cache[key] = self
     return self
  def getExtensibleContent(self, request, name):
    old_manager, user = self._forceIdentification(request)
    # Next get the document per name
    portal = self.getPortalObject()
    document = self.getDocumentValue(name=name, portal=portal)
    # restore original security context if there's a logged in user
    if user is not None:
      setSecurityManager(old_manager)
    if document is not None:
      document = aq_base(document.asContext(id=name, # Hide some properties to permit locating the original
                                            original_container=document.getParentValue(),
                                            original_id=document.getId(),
                                            editable_absolute_url=document.absolute_url()))
      return document.__of__(self)

    # 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.getDocumentValue, (name, portal)) is not None:
        # force user to login as specified in Web Section
        raise Unauthorized
Exemple #12
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)