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