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 ''
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 sort_func(value): if not isinstance(value, basestring): return value # Ignore case, normalize accents, strip spaces value = mapUnicode(safe_unicode(value)).lower().strip() # Replace numbers with zero filled numbers value = num_sort_regex.sub(zero_fill, value) return value.encode('utf-8')
def sortable_title(obj): """ Helper method for to provide FieldIndex for Title. """ 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) > MAX_SORTABLE_TITLE: start = sortabletitle[:(MAX_SORTABLE_TITLE - 13)] end = sortabletitle[-10:] sortabletitle = start + '...' + end return sortabletitle.encode('utf-8') return ''
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 ''
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 = mapUnicode(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 sortabletitle return ''
def normalize(self, text, locale=None, max_length=None): """ Returns a normalized text. text has to be a unicode string. """ return mapUnicode(text, mapping=mapping)
def sortable_string(string): return num_sort_regex.sub(lambda m: m.group().zfill(6), mapUnicode(safe_unicode(string)).lower().strip())
def sortable_string(string): return num_sort_regex.sub( lambda m: m.group().zfill(6), mapUnicode(safe_unicode(string)).lower().strip())