comparison MoinMoin/items/__init__.py @ 993:6dd0b0755b6a

disconnected levels now shown in index, fixes #75 todo: treat non-existent item listed in index.
author "Luis Henrique Fagundes <lhfagundes@gmail.com>"
date Fri, 28 Oct 2011 00:16:20 -0200
parents 5bf6d7a2ffcf
children 9fd0a6a988bb afe0afe4e1a6
comparison
equal deleted inserted replaced
973:854211821d1b 993:6dd0b0755b6a
523 revs = flaskg.storage.search(query, sortedby=NAME_EXACT, limit=None) 523 revs = flaskg.storage.search(query, sortedby=NAME_EXACT, limit=None)
524 items = [(rev.meta[NAME], rev.meta[NAME][prefix_len:], rev.meta[CONTENTTYPE]) 524 items = [(rev.meta[NAME], rev.meta[NAME][prefix_len:], rev.meta[CONTENTTYPE])
525 for rev in revs] 525 for rev in revs]
526 return items 526 return items
527 527
528 def _connect_levels(self, index):
529 new_index = []
530 last = self.name
531 for item in index:
532 name = item[0]
533
534 while not name.startswith(last):
535 last = last.rpartition('/')[0]
536
537 missing_layers = name.split('/')[last.count('/')+1:-1]
538
539 for layer in missing_layers:
540 last = '/'.join([last, layer])
541 new_index.append((last, last[len(self.name)+1:], u'application/x-nonexistent'))
542
543 last = item[0]
544 new_index.append(item)
545
546 return new_index
547
528 def flat_index(self, startswith=None, selected_groups=None): 548 def flat_index(self, startswith=None, selected_groups=None):
529 """ 549 """
530 creates an top level index of sub items of this item 550 creates a top level index of sub items of this item
531 if startswith is set, filtering is done on the basis of starting letter of item name 551 if startswith is set, filtering is done on the basis of starting letter of item name
532 if selected_groups is set, items whose contentype belonging to the selected contenttype_groups, are filtered. 552 if selected_groups is set, items whose contentype belonging to the selected contenttype_groups, are filtered.
533 """ 553 """
534 index = self.get_index() 554 index = self.get_index()
555 index = self._connect_levels(index)
535 556
536 all_ctypes = [[ctype for ctype, clabel in contenttypes] 557 all_ctypes = [[ctype for ctype, clabel in contenttypes]
537 for gname, contenttypes in CONTENTTYPE_GROUPS] 558 for gname, contenttypes in CONTENTTYPE_GROUPS]
538 all_ctypes_chain = itertools.chain(*all_ctypes) 559 all_ctypes_chain = itertools.chain(*all_ctypes)
539 all_contenttypes = list(all_ctypes_chain) 560 all_contenttypes = list(all_ctypes_chain)