Beispiel #1
0
 def search(self, query, start=None, batch_size=None):
     """Search through this principal provider.
     """
     search = query.get('search')
     if search is None:
         return
     search = search.lower()
     n = 1
     values = [
         x for x in principalRegistry.getPrincipals('') if x is not None
     ]
     values.sort(cmp=lambda x, y: cmp(str(x.id), str(y.id)))
     for i, value in enumerate(values):
         if (search in value.id.lower() or search in value.title.lower()
                 or search in value.description.lower()
                 or search in value.getLogin().lower()):
             if not ((start is not None and i < start) or
                     (batch_size is not None and n > batch_size)):
                 n += 1
                 yield u'' + value.__name__
Beispiel #2
0
 def getPortalGroups(self):
     """Returns portal wide groups."""
     for principal in principalRegistry.getPrincipals(''):
         if IGroupAwarePrincipal.providedBy(principal):
             continue
         yield principal.id, principal.title
Beispiel #3
0
    def getSortedFeedEntries(self,
                             user,
                             url,
                             block=None,
                             filter_name=None,
                             filter_group=None,
                             filter_type=None,
                             search_string=None):
        """ Processes the  incoming query."""
        session = Session()
        query = session.query(AnnotationMaster)

        if filter_name and "select_all" in filter_name:
            filter_name = None
        if filter_type and "select_all" in filter_type:
            filter_type = None
        if filter_group and "select_all" in filter_group:
            filter_group = None

        if filter_name:
            filter_name = filter_name.split(",")
        if filter_type:
            filter_type = filter_type.split(",")
        if filter_group:
            filter_group = filter_group.split(",")

        if not filter_type:
            filter_type = ['comment', 'delete', 'insert', 'replace']
        if 'annotate' in filter_type:
            raise Exception, "Cannot display annotations on the amendment page"

        query = query.filter(AnnotationMaster.url == url)
        if search_string:
            query = query.filter(AnnotationMaster.quote == search_string)
        if filter_type:
            query = query.filter(AnnotationMaster.edit_type.in_(filter_type))
        if filter_name:
            query = query.filter(
                AnnotationMaster.quote_author.in_(filter_name))

        user = self.getAuthenticatedUser()

        annotation_list = []
        public_annotations = query.filter(
            AnnotationMaster.access == 'public').all()
        users_annotations = query.filter(
            AnnotationMaster.quote_author == user).all()
        annotation_list.extend(public_annotations)
        annotation_list.extend(users_annotations)

        # Filter by position (if block was specified )
        annotations = []
        uids = []
        if block is not None and block != '':
            block = SequencePoint(block)
            for annotation in annotation_list:
                if annotation.id in uids:
                    continue
                uids.append(annotation.id)
                arange = annotation.getSequenceRange()
                if arange.start.compareInclusive(block) <= 0 and \
                       arange.end.compareInclusive(block) >= 0:
                    annotations.append(annotation)
            return annotations

        for annotation in annotation_list:
            if annotation.id in uids:
                continue
            uids.append(annotation.id)
            annotations.append(annotation)

        if filter_group:
            filter_group = set(filter_group)
            group_annotations = []
            for annotation in annotations:
                principal = principalRegistry.getPrincipals(
                    annotation.quote_author)
                if not principal:
                    continue
                principal = principal[0]
                groups = principal.groups
                if not groups:
                    groups = [
                        principal.id,
                    ]
                if not set(groups).intersection(filter_group):
                    continue
                group_annotations.append(annotation)
            annotations = group_annotations

        return annotations
Beispiel #4
0
    def getSortedFeedEntries(self,
                             user,
                             url,
                             block=None,
                             filter_name=None,
                             filter_group=None,
                             filter_type=None,
                             search_string=None):
        """ The incoming query specifies an URL like 
        http://server/somedocument/annotate/#*
        where the fragment identifier ('#*') specifies all annotations
        for this page. The document is cataloged under the URL w/o
        fragment, so chop that to get the same effect. 

        To query per fragment identifier, filter the returned
        annotations by looking at their 'url' field.
        """
        session = Session()
        query = session.query(AnnotationMaster)

        if filter_name and "select_all" in filter_name:
            filter_name = None
        if filter_group and "select_all" in filter_group:
            filter_group = None

        if filter_name:
            filter_name = filter_name.split(",")
        if filter_group:
            filter_group = filter_group.split(",")

        filter_type = [
            'annotate',
        ]

        query = query.filter(AnnotationMaster.url == url)
        if search_string:
            query = query.filter(AnnotationMaster.quote == search_string)
        if filter_type:
            query = query.filter(AnnotationMaster.edit_type.in_(filter_type))
        if filter_name:
            query = query.filter(
                AnnotationMaster.quote_author.in_(filter_name))

        user = self.getAuthenticatedUser()

        annotation_list = []
        public_annotations = query.filter(
            AnnotationMaster.access == 'public').all()
        users_annotations = query.filter(
            AnnotationMaster.quote_author == user).all()
        annotation_list.extend(public_annotations)
        annotation_list.extend(users_annotations)

        # Filter by position (if block was specified )
        annotations = []
        uids = []
        if block is not None and block != '':
            block = SequencePoint(block)
            for annotation in annotation_list:
                if annotation.id in uids:
                    continue
                uids.append(annotation.id)
                arange = annotation.getSequenceRange()
                if arange.start.compareInclusive(block) <= 0 and \
                       arange.end.compareInclusive(block) >= 0:
                    annotations.append(annotation)
            return annotations

        for annotation in annotation_list:
            if annotation.id in uids:
                continue
            uids.append(annotation.id)
            annotations.append(annotation)

        if filter_group:
            filter_group = set(filter_group)
            group_annotations = []
            for annotation in annotations:
                principal = principalRegistry.getPrincipals(
                    annotation.quote_author)
                if not principal:
                    continue
                principal = principal[0]
                groups = principal.groups
                if not groups:
                    groups = [
                        principal.id,
                    ]
                if not set(groups).intersection(filter_group):
                    continue
                group_annotations.append(annotation)
            annotations = group_annotations
        return annotations
 def getPortalGroups(self):
     """Returns portal wide groups."""
     for principal in principalRegistry.getPrincipals(''):
         if IGroupAwarePrincipal.providedBy(principal):
             continue
         yield principal.id, principal.title
    def getSortedFeedEntries(self, user, url, block=None, filter_name=None, filter_group=None, filter_type=None, search_string=None):
        """ Processes the  incoming query."""
        session = Session()
        query = session.query(AnnotationMaster)

        if filter_name and "select_all" in filter_name:
            filter_name = None
        if filter_type and "select_all" in filter_type:
            filter_type = None
        if filter_group and "select_all" in filter_group:
            filter_group = None

        if filter_name:
            filter_name = filter_name.split(",")
        if filter_type:
            filter_type = filter_type.split(",")
        if filter_group:
            filter_group = filter_group.split(",")

        if not filter_type:
            filter_type = ['comment', 'delete', 'insert', 'replace']
        if 'annotate' in filter_type:
            raise Exception, "Cannot display annotations on the amendment page"            
        
        query = query.filter(AnnotationMaster.url == url)
        if search_string:
            query = query.filter(AnnotationMaster.quote == search_string)
        if filter_type:
            query = query.filter(AnnotationMaster.edit_type.in_(filter_type))
        if filter_name:
            query = query.filter(AnnotationMaster.quote_author.in_(filter_name))
                                 
        user = self.getAuthenticatedUser()

        annotation_list = []
        public_annotations = query.filter(AnnotationMaster.access == 'public').all()
        users_annotations =  query.filter(AnnotationMaster.quote_author == user).all()                        
        annotation_list.extend(public_annotations)
        annotation_list.extend(users_annotations)
                    
        # Filter by position (if block was specified )
        annotations = [ ]
        uids = []
        if block is not None and block != '':
            block = SequencePoint(block);
            for annotation in annotation_list:
                if annotation.id in uids:
                    continue
                uids.append(annotation.id)                
                arange = annotation.getSequenceRange( )
                if arange.start.compareInclusive(block) <= 0 and \
                       arange.end.compareInclusive(block) >= 0:            
                    annotations.append( annotation )
            return annotations

        for annotation in annotation_list:
            if annotation.id in uids:
                continue
            uids.append(annotation.id)                
            annotations.append(annotation)

        if filter_group:
            filter_group = set(filter_group)
            group_annotations = []
            for annotation in annotations:
                principal = principalRegistry.getPrincipals(annotation.quote_author)
                if not principal:
                    continue
                principal = principal[0]
                groups = principal.groups
                if not groups:
                    groups = [principal.id,]                
                if not set(groups).intersection(filter_group):
                    continue
                group_annotations.append(annotation)
            annotations = group_annotations
                
        return annotations
    def getSortedFeedEntries(self, user, url, block=None, filter_name=None, filter_group=None, filter_type=None, search_string=None):
        """ The incoming query specifies an URL like 
        http://server/somedocument/annotate/#*
        where the fragment identifier ('#*') specifies all annotations
        for this page. The document is cataloged under the URL w/o
        fragment, so chop that to get the same effect. 

        To query per fragment identifier, filter the returned
        annotations by looking at their 'url' field.
        """
        session = Session()
        query = session.query(AnnotationMaster)

        if filter_name and "select_all" in filter_name:
            filter_name = None
        if filter_group and "select_all" in filter_group:
            filter_group = None

        if filter_name:
            filter_name = filter_name.split(",")
        if filter_group:
            filter_group = filter_group.split(",")

        filter_type = ['annotate', ]
        
        query = query.filter(AnnotationMaster.url == url)
        if search_string:
            query = query.filter(AnnotationMaster.quote == search_string)
        if filter_type:
            query = query.filter(AnnotationMaster.edit_type.in_(filter_type))
        if filter_name:
            query = query.filter(AnnotationMaster.quote_author.in_(filter_name))
                                 
        user = self.getAuthenticatedUser()

        annotation_list = []
        public_annotations = query.filter(AnnotationMaster.access == 'public').all()
        users_annotations =  query.filter(AnnotationMaster.quote_author == user).all()                        
        annotation_list.extend(public_annotations)
        annotation_list.extend(users_annotations)
                    
        # Filter by position (if block was specified )
        annotations = [ ]
        uids = []
        if block is not None and block != '':
            block = SequencePoint(block);
            for annotation in annotation_list:
                if annotation.id in uids:
                    continue
                uids.append(annotation.id)                
                arange = annotation.getSequenceRange( )
                if arange.start.compareInclusive(block) <= 0 and \
                       arange.end.compareInclusive(block) >= 0:            
                    annotations.append( annotation )
            return annotations

        for annotation in annotation_list:
            if annotation.id in uids:
                continue
            uids.append(annotation.id)                
            annotations.append(annotation)

        if filter_group:
            filter_group = set(filter_group)
            group_annotations = []
            for annotation in annotations:
                principal = principalRegistry.getPrincipals(annotation.quote_author)
                if not principal:
                    continue
                principal = principal[0]
                groups = principal.groups
                if not groups:
                    groups = [principal.id,]
                if not set(groups).intersection(filter_group):
                    continue
                group_annotations.append(annotation)
            annotations = group_annotations
        return annotations