def sortable_title(obj, portal, **kwargs):
        """ Helper method for to provide FieldIndex for Title.
    
        >>> from Products.CMFPlone.CatalogTool import sortable_title
    
        >>> self.folder.setTitle('Plone42 _foo')
        >>> sortable_title(self.folder, self.portal)
        'plone00000042 _foo'
        """
        title = getattr(obj, 'Title', None)
        if title is not None:
            if safe_callable(title):
                title = title()
        if not title:  # we want to catch empty string
            title = getattr(obj, 'getId', None)
            if title is not None and safe_callable(title):
                title = title()
            else:
                title = obj.id

        if isinstance(title, basestring):
            sortabletitle = title.lower().strip()
            # Replace numbers with zero filled numbers
            sortabletitle = num_sort_regex.sub(zero_fill, sortabletitle)
            # Truncate to prevent bloat
            sortabletitle = safe_unicode(sortabletitle)[:30].encode('utf-8')
            return sortabletitle
        return ''
示例#2
0
def sortable_title(obj):
    """Custom sortable_title indexer for all content types.

    This is a copy from Products.CMFPlone.CatalogTool.sortable_title
    except that we overwrite MAX_SORTABLE_TITLE with SORTABLE_TITLE_LENGTH.
    We set set it to a high enough value to basically avoid ever cropping
    the title, even with number padding. This is to avoid sorting issues
    in content listings.
    """
    title = getattr(obj, 'Title', None)
    if title is not None:
        if safe_callable(title):
            title = title()

        if isinstance(title, basestring):
            # Ignore case, normalize accents, strip spaces
            sortabletitle = mapUnicode(safe_unicode(title)).lower().strip()
            # Replace numbers with zero filled numbers
            sortabletitle = num_sort_regex.sub(zero_fill, sortabletitle)
            # Truncate to prevent bloat, take bits from start and end
            if len(sortabletitle) > SORTABLE_TITLE_LENGTH:
                start = sortabletitle[:(SORTABLE_TITLE_LENGTH - 13)]
                end = sortabletitle[-10:]
                sortabletitle = start + u'...' + end
            return sortabletitle.encode('utf-8')
    return ''
    def sortable_title(obj, portal, **kwargs):
        """ Helper method for to provide FieldIndex for Title.
    
        >>> from Products.CMFPlone.CatalogTool import sortable_title
    
        >>> self.folder.setTitle('Plone42 _foo')
        >>> sortable_title(self.folder, self.portal)
        'plone00000042 _foo'
        """
        title = getattr(obj, 'Title', None)
        if title is not None:
            if safe_callable(title):
                title = title()
        if not title:  # we want to catch empty string
            title = getattr(obj, 'getId', None)
            if title is not None and safe_callable(title):
                title = title()
            else:
                title = obj.id

        if isinstance(title, basestring):
            sortabletitle = title.lower().strip()
            # Replace numbers with zero filled numbers
            sortabletitle = num_sort_regex.sub(zero_fill, sortabletitle)
            # Truncate to prevent bloat
            sortabletitle = safe_unicode(sortabletitle)[:30].encode('utf-8')
            return sortabletitle
        return ''
示例#4
0
def sortable_title(obj):
    """Custom sortable_title indexer for RepositoryFolders.

    This implementation doesn't count space needed for zero padded numbers
    towards the maximum length. We need this for repofolders because otherwise
    for deeply nested folders the reference numbers alone eat up all
    the available space (40 characters).
    """
    title = getattr(obj, 'Title', None)
    if title is not None:
        if safe_callable(title):
            title = title()

        if isinstance(title, basestring):
            # Ignore case, normalize accents, strip spaces
            sortabletitle = mapUnicode(safe_unicode(title)).lower().strip()
            # Replace numbers with zero filled numbers
            sortabletitle = num_sort_regex.sub(zero_fill, sortabletitle)

            # Determine the length of the sortable title
            padded_numbers = re.findall(num_sort_regex, sortabletitle)
            max_length = MAX_SORTABLE_TITLE + sum([
                len(match) - len(match.lstrip('0'))
                for match in padded_numbers
            ])

            # Truncate to prevent bloat, take bits from start and end
            if len(sortabletitle) > max_length:
                start = sortabletitle[:(max_length - 13)]
                end = sortabletitle[-10:]
                sortabletitle = start + '...' + end
            return sortabletitle.encode('utf-8')
    return ''
示例#5
0
def sortable_title(obj):
    title = getattr(obj, 'Title', None)
    if title is not None:
        if safe_callable(title):
            title = title()

        if isinstance(title, basestring):
            sortabletitle = safe_unicode(title).lower().strip()
            sortabletitle = num_sort_regex.sub(zero_fill, sortabletitle)
            sortabletitle = sortabletitle[:70].encode('utf-8')
            return locale.strxfrm(sortabletitle)

    return ''
 def __call__(self, **kwargs):
     title = getattr(self.obj, 'Title', None)
     if title is not None:
         if safe_callable(title):
             if kwargs.has_key('lang'):
                 try: title = title(lang=kwargs['lang'])
                 except: title = title()
             else:
                 title = title()
         if isinstance(title, basestring):
             sortabletitle = title.lower().strip()
             # Replace numbers with zero filled numbers
             sortabletitle = num_sort_regex.sub(zero_fill, sortabletitle)
             # Truncate to prevent bloat
             sortabletitle = safe_unicode(sortabletitle)[:30].encode('utf-8')
             return sortabletitle
     return ''
示例#7
0
def sortable_sender(obj):
    """
      Helper method used to provide a FieldIndex for destOrigin field
      in CourrierFile objects
    """
    sender = getattr(obj, 'getDestOrigin', None)
    if sender is not None:
        if safe_callable(sender):
            sender = sender()

        if isinstance(sender, basestring):
            # Ignore case, normalize accents, strip spaces
            sortablesender = mapUnicode(safe_unicode(sender)).lower().strip()
            # Replace numbers with zero filled numbers
            sortablesender = num_sort_regex.sub(zero_fill, sortablesender)
            # Truncate to prevent bloat, take bits from start and end
            if len(sortablesender) > MAX_SORTABLE_SENDER:
                start = sortablesender[:(MAX_SORTABLE_SENDER - 13)]
                end = sortablesender[-10:]
                sortablesender = start + '...' + end
            return sortablesender.encode('utf-8')
    return ''
示例#8
0
def sortable_title(obj):
    """ Helper method for to provide FieldIndex for Title.

    >>> from Products.CMFPlone.CatalogTool import sortable_title

    >>> self.folder.setTitle('Plone42 _foo')
    >>> sortable_title(self.folder, self.portal)
    'plone000042 _foo'
    """
    title = getattr(obj, 'Title', None)
    if title is not None:
        if safe_callable(title):
            title = title()

        if isinstance(title, basestring):
            # Ignore case, normalize accents, strip spaces
            sortabletitle = safe_unicode(title).lower().strip()
            # Replace numbers with zero filled numbers
            sortabletitle = num_sort_regex.sub(zero_fill, sortabletitle)
            # Truncate to prevent bloat
            sortabletitle = sortabletitle[:70].encode('utf-8')
            return locale.strxfrm(sortabletitle)

    return ''
示例#9
0
def sort_on_sortable_title(item):
    if isinstance(item[0], unicode):
        return num_sort_regex.sub(zero_fill, item[0])
    return num_sort_regex.sub(zero_fill, item[0].Title())
示例#10
0
def sort_on_sortable_title(item):
    if isinstance(item[0], unicode):
        return num_sort_regex.sub(zero_fill, item[0])
    return num_sort_regex.sub(zero_fill, item[0].Title())