Refactor the code for grabbing titles.
This commit is contained in:
parent
c7ef45d126
commit
a681d2cef4
|
@ -266,20 +266,30 @@ class XanaLink(Item):
|
|||
else:
|
||||
return "link: " + self.hashid
|
||||
|
||||
@classmethod
|
||||
def get_all_titles(cls):
|
||||
titles = {}
|
||||
for link in (obj.parse() for obj in cls.query):
|
||||
if link['type'] != 'title':
|
||||
continue
|
||||
facet1, facet2 = link['facets']
|
||||
link_type, _, ident = facet1[0].partition(': ')
|
||||
item = Item.from_external(ident)
|
||||
def item_and_title(self, home=None):
|
||||
link = self.parse()
|
||||
if link['type'] != 'title':
|
||||
return
|
||||
|
||||
ident2, start, length = parse_span(facet2[0])
|
||||
source_of_title = SourceDoc.from_external(ident2)
|
||||
if source_of_title:
|
||||
titles[item] = source_of_title.text[start:length + start]
|
||||
facet1, facet2 = link['facets']
|
||||
link_type, _, ident = facet1[0].partition(': ')
|
||||
item = Item.from_external(ident, home)
|
||||
|
||||
ident2, start, length = parse_span(facet2[0])
|
||||
source_of_title = SourceDoc.from_external(ident2, home)
|
||||
if source_of_title:
|
||||
return(item, source_of_title.text[start:length + start])
|
||||
|
||||
@classmethod
|
||||
def get_all_titles(cls, home=None):
|
||||
titles = {}
|
||||
for link in cls.query:
|
||||
ret = link.item_and_title(home)
|
||||
if ret is None:
|
||||
continue
|
||||
item, title = ret
|
||||
titles[item] = title
|
||||
print(link.hashid, title)
|
||||
return titles
|
||||
|
||||
def snippet(self):
|
||||
|
|
Loading…
Reference in a new issue