Create depicts object during save, if needed.
This commit is contained in:
parent
c79427f794
commit
d8c279001e
30
app.py
30
app.py
|
@ -153,6 +153,29 @@ def current_url():
|
||||||
args.update(request.args)
|
args.update(request.args)
|
||||||
return url_for(request.endpoint, **args)
|
return url_for(request.endpoint, **args)
|
||||||
|
|
||||||
|
def create_depicts_item(item_id):
|
||||||
|
qid = f'Q{item_id}'
|
||||||
|
entity = mediawiki.get_entity(qid)
|
||||||
|
if 'en' in entity['labels']:
|
||||||
|
label = entity['labels']['en']['value']
|
||||||
|
else:
|
||||||
|
label = None
|
||||||
|
|
||||||
|
if 'en' in entity['descriptions']:
|
||||||
|
description = entity['descriptions']['en']['value']
|
||||||
|
else:
|
||||||
|
description = None
|
||||||
|
|
||||||
|
if 'en' in entity['aliases']:
|
||||||
|
alt_labels = {alt['value'] for alt in entity['aliases']['en']}
|
||||||
|
else:
|
||||||
|
alt_labels = set()
|
||||||
|
|
||||||
|
return DepictsItem(label=label,
|
||||||
|
description=description,
|
||||||
|
alt_labels=alt_labels,
|
||||||
|
count=0)
|
||||||
|
|
||||||
@app.before_request
|
@app.before_request
|
||||||
def init_profile():
|
def init_profile():
|
||||||
g.profiling = []
|
g.profiling = []
|
||||||
|
@ -175,6 +198,13 @@ def save(item_id):
|
||||||
|
|
||||||
for depicts_qid in depicts:
|
for depicts_qid in depicts:
|
||||||
depicts_id = int(depicts_qid[1:])
|
depicts_id = int(depicts_qid[1:])
|
||||||
|
|
||||||
|
depicts_item = DepictsItem.query.get(depicts_id)
|
||||||
|
if depicts_item is None:
|
||||||
|
depicts_item = create_depicts_item(depicts_id)
|
||||||
|
database.session.add(depicts_item)
|
||||||
|
database.session.commit()
|
||||||
|
|
||||||
r = create_claim(item_id, depicts_id, token)
|
r = create_claim(item_id, depicts_id, token)
|
||||||
reply = r.json()
|
reply = r.json()
|
||||||
if 'error' in reply:
|
if 'error' in reply:
|
||||||
|
|
Loading…
Reference in a new issue