Esempio n. 1
0
    def __new__(cls, context, request, view, manager):
        chain = _get_context_chain(context)
        chain.pop()  # bungeni_app
        top_section = chain.pop()

        if not chain:
            return

        # we require the tree to begin with a container object
        if not IReadContainer.providedBy(chain[-1]):
            return

        # remove any views from navigation tree
        if not (IAlchemistContent.providedBy(chain[0])
                or IAlchemistContainer.providedBy(chain[0])
                or ISection.providedBy(chain[0])):
            chain.pop(0)

        subcontext = chain[-1]
        if (len(chain) > 1 or IReadContainer.providedBy(subcontext)
                and not IAlchemistContainer.providedBy(subcontext)
                and len(subcontext)):
            inst = object.__new__(cls, context, request, view, manager)
            inst.chain = chain
            inst.top_section_url = url.absoluteURL(top_section, request)
            inst.id_prefix = "nav"
            return inst
Esempio n. 2
0
 def __new__(cls, context, request, view, manager):
     chain = _get_context_chain(context)
     chain.pop() # bungeni_app
     top_section = chain.pop()
     
     if not chain:
         return
     
     # we require the tree to begin with a container object
     if not IReadContainer.providedBy(chain[-1]):
         return
     
     # remove any views from navigation tree
     if not(IAlchemistContent.providedBy(chain[0]) or 
             IAlchemistContainer.providedBy(chain[0]) or
             ISection.providedBy(chain[0])
         ):
         chain.pop(0)
     
     subcontext = chain[-1]
     if (len(chain) > 1 or
             IReadContainer.providedBy(subcontext) and 
             not IAlchemistContainer.providedBy(subcontext) and 
             len(subcontext)
         ):
         inst = object.__new__(cls, context, request, view, manager)
         inst.chain = chain
         inst.top_section_url = url.absoluteURL(top_section, request)
         inst.id_prefix = "nav"
         return inst
Esempio n. 3
0
 def get_current_section(self):
     chain = _get_context_chain(self.context)
     i = len(chain) - 1
     ob = chain[i]
     while not ISection.providedBy(ob):
         i -= 1
         if i < 0:
             ob = None
             break
         ob = chain[i]
     return ob
Esempio n. 4
0
 def get_current_section(self):
     chain = _get_context_chain(self.context)
     i = len(chain) - 1
     ob = chain[i]
     while not ISection.providedBy(ob):
         i -= 1
         if i < 0:
             ob = None
             break
         ob = chain[i]
     return ob
Esempio n. 5
0
 def update(self):
     chain = _get_context_chain(self.context)
     i = len(chain) - 1
     ob = chain[i]
     while not ISection.providedBy(ob):
         i -= 1
         if i < 0:
             ob = None
             break
         ob = chain[i]
     if ob:
         self.action = absoluteURL(ob, self.request) + '/search'
     else:
         self.action = None
Esempio n. 6
0
def get_group_for_context(context):
    """Return the "main" (as meaning of this for type) group for this context,
    or None if no such logical group can be determined.
    
    The group may be None if:
    - context is a user who is not a member of any group within any chamber
    - context is a core.interfaces.ISection or workspace Container, for which
      there is no "contextual" chamber is defined in the traversal hierarchy
    - context is an IAlchemistContainer that is not hierarchically contained
      within an IBungeniContent (no such instance in its __parent__ ancestry)
    
    !+ should this be shipped out as a domain_model.group property, or 
    interfaces organized in "how group is determined" categories?
    """
    group = None
    if interfaces.IGroup.providedBy(context):
        group = context
    elif interfaces.IEvent.providedBy(context):
        group = context.group or context.head.group
    elif (interfaces.IDoc.providedBy(context) or 
            interfaces.IGroupMember.providedBy(context) or
            interfaces.IGroupAddress.providedBy(context) or
            interfaces.ISitting.providedBy(context) or
            interfaces.ITitleType.providedBy(context) or
            interfaces.IEditorialNote.providedBy(context) or
            interfaces.IHeading.providedBy(context)
        ):
        group = context.group
    elif (IAlchemistContainer.providedBy(context) or
            ISection.providedBy(context) # !+group ALWAYS None?
        ):
        group = get_group_for_context(context.__parent__)
    elif (interfaces.IAttachment.providedBy(context) or
            interfaces.ISignatory.providedBy(context)
        ):
        group = context.head.group
    elif (interfaces.IMemberTitle.providedBy(context) or
            interfaces.IMemberRole.providedBy(context)
        ):
        group = context.member.group
    elif (interfaces.IDebateRecord.providedBy(context) or
            interfaces.ISittingAttendance.providedBy(context)
        ):
        group = context.sitting.group
    if group is None:
        #from bungeni.utils import probing
        #log.warn(probing.interfaces(context))
        log.warn("!+GROUP_FOR_CONTEXT Cannot determine group for context: %s", context)
        #raise ValueError, "No group for context: %s" % (context)
    return group