def resolve_pagename(self, parent, names, parent_id=None): '''Resolve a pagename in the right case''' # We do not ignore placeholders here. This can lead to a dependencies # in how links are resolved based on order of indexing. However, this # is not really a problem. Ignoring them means you could see duplicates # if the tree for multiple links with slightly different spelling. # Also we would need another call to return the page_id if a resolved # page happens to exist. assert isinstance(parent, Path) pagename = parent page_id = parent_id or self.get_page_id(parent) for i, basename in enumerate(names): sortkey = natural_sort_key(basename) candidates = self.db.execute( 'SELECT id, name FROM pages ' 'WHERE parent=? and sortkey=? ORDER BY name', (page_id, sortkey)).fetchall() exact = pagename.child(basename).name for row in candidates: if row['name'] == exact: pagename = Path(row['name']) page_id = row['id'] break else: if candidates: # case insensitive match(es) row = candidates[0] pagename = Path(row['name']) page_id = row['id'] else: # no match return None, pagename.child(':'.join(names[i:])) else: return page_id, pagename
def resolve_pagename(self, parent, names): '''Resolve a pagename in the right case''' # We do not ignore placeholders here. This can lead to a dependencies # in how links are resolved based on order of indexing. However, this # is not really a problem. Ignoring them means you could see duplicates # if the tree for multiple links with slightly different spelling. # Also we would need another call to return the page_id if a resolved # page happens to exist. pagename = parent page_id = self.get_page_id(parent) for i, basename in enumerate(names): if page_id == ROOT_ID: row = self.db.execute( 'SELECT id, name FROM pages WHERE name=?', (basename,) ).fetchone() else: row = self.db.execute( 'SELECT id, name FROM pages WHERE parent=? and name LIKE ?', (page_id, "%:"+basename) ).fetchone() if row: # exact match pagename = Path(row['name']) page_id = row['id'] else: sortkey = natural_sort_key(basename) row = self.db.execute( 'SELECT id, name FROM pages ' 'WHERE parent=? and sortkey=? ORDER BY name', (page_id, sortkey) ).fetchone() if row: # case insensitive match pagename = Path(row['name']) page_id = row['id'] else: # no match return None, pagename.child(':'.join(names[i:])) else: return page_id, pagename