示例#1
0
 def constructQuery(self, context):
     users = super(MembershipUserSource, self).constructQuery(context)
     trusted = removeSecurityProxy(context)
     exclude_ids = set()
     if IContainer.providedBy(trusted):
         for member in trusted.values():
             exclude_ids.add(member.user_id)
         users = users.filter(
             sql.not_(domain.User.user_id.in_(list(exclude_ids))))
     return users
    def publishTraverse(self, request, name):
        try:
            content = getUtility(IIntIds).queryObject(int(name))
        except:
            raise NotFound(self.context, name, request)
        while not IContainer.providedBy(content) and content is not None:
            content = content.__parent__

        if content is not None:
            return content
            
        raise NotFound(self.context, name, request)
示例#3
0
 def constructQuery(self, context):
     users = super(MembershipUserSource, self).constructQuery(
         context
     )
     trusted = removeSecurityProxy(context)
     exclude_ids = set()
     if IContainer.providedBy(trusted):
         for member in trusted.values():
             exclude_ids.add(member.user_id)
         users = users.filter(
             sql.not_(domain.User.user_id.in_(list(exclude_ids)))
         )
     return users
示例#4
0
def recursiveCronSubscriber(obj):
    """distibution of cron event
    """

    if ISite.providedBy(obj):
        sitem = obj.getSiteManager()
        smList = list(sitem.getAllUtilitiesRegisteredFor(IAdmUtilCron))
        for utilObj in smList:
            if IAdmUtilCron.providedBy(utilObj) :
                globalCronUtility.subscribeToCron(utilObj)
    if IContainer.providedBy(obj):
        for (dummy_name, subObject) in obj.items():
            recursiveCronSubscriber(subObject)
示例#5
0
 def constructQuery(self, context):
     mp_query = super(MemberOfParliamentSignatorySource,
                      self).constructQuery(context)
     trusted = removeSecurityProxy(context)
     if ISignatory.providedBy(context):
         trusted = removeSecurityProxy(trusted.__parent__)
     if IContainer.providedBy(trusted):
         exclude_ids = set([member.user_id for member in trusted.values()])
         if trusted.__parent__ is not None:
             trusted_parent = removeSecurityProxy(trusted.__parent__)
             exclude_ids.add(trusted_parent.owner_id)
         return mp_query.filter(
             sql.not_(
                 domain.MemberOfParliament.user_id.in_(list(exclude_ids))))
     return mp_query
示例#6
0
def recursiveEventCrossbarSubscriber(obj):
    """distibution of eventcrossbar event
    """

    if ISite.providedBy(obj):
        sitem = obj.getSiteManager()
        smList = list(
            sitem.getAllUtilitiesRegisteredFor(IAdmUtilEventCrossbar))
        for utilObj in smList:
            if IAdmUtilEventCrossbar.providedBy(utilObj):
                globalEventCrossbarUtility.subscribeToEventCrossbar(utilObj)
    if IContainer.providedBy(obj):
        try:
            for (dummy_name, subObject) in obj.items():
                recursiveEventCrossbarSubscriber(subObject)
        except AttributeError:
            pass
示例#7
0
 def constructQuery(self, context):
     mp_query = super(MemberOfParliamentSignatorySource, 
             self).constructQuery(context)
     trusted = removeSecurityProxy(context)
     if ISignatory.providedBy(context):
         trusted = removeSecurityProxy(trusted.__parent__)
     if IContainer.providedBy(trusted):
         exclude_ids = set(
             [ member.user_id for member in trusted.values() ]
         )
         if trusted.__parent__ is not None:
             trusted_parent = removeSecurityProxy(trusted.__parent__)
             exclude_ids.add(trusted_parent.owner_id)
         return mp_query.filter(
             sql.not_(domain.MemberOfParliament.user_id.in_(
                     list(exclude_ids)
                 )
             )
         )
     return mp_query
示例#8
0
    def _buildTree(self, node):
        children = []
        for child in node.values():
            subentries = False
            if IContainer.providedBy(child):
                subentries = bool(len(child))
           
            url = absoluteURL(child, self.request)
            expanded = self.current.startswith(url)
            name = getattr(child, 'title', child.__name__)
            
            entry = {
                "text": "<a href='%s'>%s</a>" % (url, name),
                "id": self.intid.queryId(child),
                "expanded": expanded,
                }

            if expanded and subentries:
                entry['children'] = self._buildTree(child)
            else:
                entry['hasChildren'] = subentries
            children.append(entry)
        return children
示例#9
0
    def move(self):
        if not IContainer.providedBy(self.context):
            return self.update()
        # update contained children paths when the container moves
        peer = schema.fromUID(self.context.UID())
        contained = Session().query(schema.Content).filter(
            rdb.and_(schema.Content.path.startswith(peer.path),
                     schema.Content.content_id != peer.content_id))

        # get old and new paths to update contained
        old_containment_path = peer.path
        old_relative_path = peer.relative_path
        interfaces.ISerializer(self.context).update()
        new_containment_path = peer.path
        new_relative_path = peer.relative_path

        # for large trees this might be more efficient sans the
        # peer.
        for content in contained:
            content.path = content.path.replace(
                old_containment_path, new_containment_path)
            content.relative_path = content.relative_path.replace(
                old_relative_path, new_relative_path)
        Session().flush()
示例#10
0
 def sizeForDisplay(self):
     """See `ISized`"""
     num_items = len(IContainer(self.context))
     if num_items == 1:
         return _('1 item')
     return _('%d items' % num_items)
示例#11
0
 def sizeForSorting(self):
     """See `ISized`"""
     return ('item', len(IContainer(self.context)))
示例#12
0
    def grok(self, name, factory, context, module_info, templates):
        infos = util.class_annotation_list(factory, 'grok.local_utility', None)
        if infos is None:
            return False

        for info in infos:
            if info.public and not IContainer.implementedBy(factory):
                raise GrokError(
                    "Cannot set public to True with grok.local_utility as "
                    "the site (%r) is not a container." %
                    factory, factory)
            if info.provides is None:
                if util.check_subclass(info.factory, grok.LocalUtility):
                    baseInterfaces = interface.implementedBy(grok.LocalUtility)
                    utilityInterfaces = interface.implementedBy(info.factory)
                    provides = list(utilityInterfaces - baseInterfaces)

                    if len(provides) == 0 and len(list(utilityInterfaces)) > 0:
                        raise GrokError(
                            "Cannot determine which interface to use "
                            "for utility registration of %r in site %r. "
                            "It implements an interface that is a specialization "
                            "of an interface implemented by grok.LocalUtility. "
                            "Specify the interface by either using grok.provides "
                            "on the utility or passing 'provides' to "
                            "grok.local_utility." % (info.factory, factory),
                            info.factory)
                else:
                    provides = list(interface.implementedBy(info.factory))

                util.check_implements_one_from_list(provides, info.factory)
                info.provides = provides[0]

        # raise an error in case of any duplicate registrations
        # on the class level (subclassing overrides, see below)
        used = set()
        class_infos = util.class_annotation(factory, 'grok.local_utility',
                                            [])
        for info in class_infos:
            key = (info.provides, info.name)
            if key in used:
                raise GrokError(
                    "Conflicting local utility registration %r in "
                    "site %r. Local utilities are registered multiple "
                    "times for interface %r and name %r." %
                    (info.factory, factory, info.provides, info.name),
                    factory)
            used.add(key)

        # Make sure that local utilities from subclasses override
        # utilities from base classes if the registration (provided
        # interface, name) is identical.
        overridden_infos = []
        used = set()
        for info in reversed(infos):
            key = (info.provides, info.name)
            if key in used:
                continue
            used.add(key)
            overridden_infos.append(info)
        overridden_infos.reverse()

        # store infos on site class
        factory.__grok_utilities_to_install__ = overridden_infos
        component.provideHandler(localUtilityRegistrationSubscriber,
                                 adapts=(factory, grok.IObjectAddedEvent))

        return True
示例#13
0
 def sizeForDisplay(self):
     """See `ISized`"""
     num_hosts = len(IContainer(self.context))
     if num_hosts == 1:
         return _('1 host')
     return _('%d hosts' % num_hosts)