Tool for populating table of references.
This commit is contained in:
parent
236e920dc9
commit
d386cf7862
|
@ -34,3 +34,26 @@ def delete_item(hashid):
|
|||
item = model.Item.get_by_hashid(hashid)
|
||||
database.session.delete(item)
|
||||
database.session.commit()
|
||||
|
||||
@app.cli.command()
|
||||
def populate_references():
|
||||
home = 'http://localhost:5000/'
|
||||
seen = set()
|
||||
for link_obj in model.XanaLink.query:
|
||||
link = link_obj.parse()
|
||||
for items in link['facets']:
|
||||
for i in items:
|
||||
k, _, v = i.partition(': ')
|
||||
if k == 'span' and ',' in v:
|
||||
v = v.partition(',')[0]
|
||||
item = model.Item.from_external(v, home=home)
|
||||
if item:
|
||||
print(link_obj.id, '->', item.id)
|
||||
as_tuple = (link_obj.id, item.id)
|
||||
if as_tuple in seen:
|
||||
continue
|
||||
ref = model.Reference(subject_id=link_obj.id, object_id=item.id)
|
||||
database.session.add(ref)
|
||||
seen.add(as_tuple)
|
||||
|
||||
database.session.commit()
|
||||
|
|
Loading…
Reference in a new issue