Expand focus from paintings to more artworks
Replace all references to 'painting' with 'artwork'
This commit is contained in:
parent
df8ff30b64
commit
036a4be5ed
72
app.py
72
app.py
|
@ -1,10 +1,10 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from flask import Flask, render_template, url_for, redirect, request, g, jsonify, session
|
||||
from depicts import (utils, wdqs, commons, mediawiki, painting, database,
|
||||
from depicts import (utils, wdqs, commons, mediawiki, artwork, database,
|
||||
wd_catalog, human, wikibase, wikidata_oauth, wikidata_edit)
|
||||
from depicts.pager import Pagination, init_pager
|
||||
from depicts.model import (DepictsItem, DepictsItemAltLabel, Edit, PaintingItem,
|
||||
from depicts.model import (DepictsItem, DepictsItemAltLabel, Edit, ArtworkItem,
|
||||
Language)
|
||||
from depicts.error_mail import setup_error_mail
|
||||
from requests_oauthlib import OAuth1Session
|
||||
|
@ -94,7 +94,7 @@ def user_settings():
|
|||
return 'flipped. find more is ' + display
|
||||
|
||||
def existing_edit(item_id, depicts_id):
|
||||
q = Edit.query.filter_by(painting_id=item_id, depicts_id=depicts_id)
|
||||
q = Edit.query.filter_by(artwork_id=item_id, depicts_id=depicts_id)
|
||||
return q.count() != 0
|
||||
|
||||
@app.route('/save/Q<int:item_id>', methods=['POST'])
|
||||
|
@ -105,12 +105,12 @@ def save(item_id):
|
|||
|
||||
token = wikidata_oauth.get_token()
|
||||
|
||||
painting_item = PaintingItem.query.get(item_id)
|
||||
if painting_item is None:
|
||||
painting_entity = mediawiki.get_entity_with_cache(f'Q{item_id}')
|
||||
label = wikibase.get_entity_label(painting_entity)
|
||||
painting_item = PaintingItem(item_id=item_id, label=label, entity=painting_entity)
|
||||
database.session.add(painting_item)
|
||||
artwork_item = ArtworkItem.query.get(item_id)
|
||||
if artwork_item is None:
|
||||
artwork_entity = mediawiki.get_entity_with_cache(f'Q{item_id}')
|
||||
label = wikibase.get_entity_label(artwork_entity)
|
||||
artwork_item = ArtworkItem(item_id=item_id, label=label, entity=artwork_entity)
|
||||
database.session.add(artwork_item)
|
||||
database.session.commit()
|
||||
|
||||
for depicts_qid in depicts:
|
||||
|
@ -136,7 +136,7 @@ def save(item_id):
|
|||
lastrevid = saved['pageinfo']['lastrevid']
|
||||
assert saved['success'] == 1
|
||||
edit = Edit(username=username,
|
||||
painting_id=item_id,
|
||||
artwork_id=item_id,
|
||||
depicts_id=depicts_id,
|
||||
lastrevid=lastrevid)
|
||||
database.session.add(edit)
|
||||
|
@ -184,19 +184,19 @@ def property_query_page(property_id):
|
|||
|
||||
@app.route('/')
|
||||
def start():
|
||||
return random_painting()
|
||||
return random_artwork()
|
||||
username = wikidata_oauth.get_username()
|
||||
username = None
|
||||
return render_template('start.html', username=username)
|
||||
|
||||
@app.route('/next')
|
||||
def random_painting():
|
||||
q = render_template('query/painting_no_depicts.sparql')
|
||||
def random_artwork():
|
||||
q = render_template('query/artwork_no_depicts.sparql')
|
||||
rows = wdqs.run_query_with_cache(q)
|
||||
has_depicts = True
|
||||
while has_depicts:
|
||||
item_id = wdqs.row_id(random.choice(rows))
|
||||
if PaintingItem.query.get(item_id):
|
||||
if ArtworkItem.query.get(item_id):
|
||||
continue
|
||||
entity = mediawiki.get_entity_with_cache(f'Q{item_id}', refresh=True)
|
||||
en_label = wikibase.get_en_label(entity)
|
||||
|
@ -259,7 +259,7 @@ def oauth_callback():
|
|||
session['owner_secret'] = oauth_tokens.get('oauth_token_secret')
|
||||
|
||||
next_page = session.get('after_login')
|
||||
return redirect(next_page) if next_page else random_painting()
|
||||
return redirect(next_page) if next_page else random_artwork()
|
||||
|
||||
@app.route('/oauth/disconnect')
|
||||
def oauth_disconnect():
|
||||
|
@ -268,13 +268,13 @@ def oauth_disconnect():
|
|||
del session[key]
|
||||
return redirect(url_for('browse_page'))
|
||||
|
||||
def create_claim(painting_id, depicts_id, token):
|
||||
painting_qid = f'Q{painting_id}'
|
||||
def create_claim(artwork_id, depicts_id, token):
|
||||
artwork_qid = f'Q{artwork_id}'
|
||||
value = json.dumps({'entity-type': 'item',
|
||||
'numeric-id': depicts_id})
|
||||
params = {
|
||||
'action': 'wbcreateclaim',
|
||||
'entity': painting_qid,
|
||||
'entity': artwork_qid,
|
||||
'property': 'P180',
|
||||
'snaktype': 'value',
|
||||
'value': value,
|
||||
|
@ -332,7 +332,7 @@ def get_institution(entity, other):
|
|||
@app.route("/item/Q<int:item_id>")
|
||||
def item_page(item_id):
|
||||
qid = f'Q{item_id}'
|
||||
item = painting.Painting(qid)
|
||||
item = artwork.Artwork(qid)
|
||||
from_redirect = qid in session and session.pop(qid) == 'from redirect'
|
||||
entity = mediawiki.get_entity_with_cache(qid, refresh=not from_redirect)
|
||||
|
||||
|
@ -355,12 +355,12 @@ def item_page(item_id):
|
|||
|
||||
people = human.from_name(label) if label else None
|
||||
|
||||
painting_item = PaintingItem.query.get(item_id)
|
||||
if painting_item is None:
|
||||
painting_item = PaintingItem(item_id=item_id, label=label, entity=entity)
|
||||
database.session.add(painting_item)
|
||||
artwork_item = ArtworkItem.query.get(item_id)
|
||||
if artwork_item is None:
|
||||
artwork_item = ArtworkItem(item_id=item_id, label=label, entity=entity)
|
||||
database.session.add(artwork_item)
|
||||
|
||||
catalog = wd_catalog.get_catalog_from_painting(entity)
|
||||
catalog = wd_catalog.get_catalog_from_artwork(entity)
|
||||
if not catalog.get('institution'):
|
||||
catalog['institution'] = get_institution(entity, other)
|
||||
|
||||
|
@ -447,8 +447,8 @@ def get_other(entity):
|
|||
def list_edits():
|
||||
edit_list = Edit.query.order_by(Edit.timestamp.desc())
|
||||
|
||||
painting_count = (database.session
|
||||
.query(func.count(distinct(Edit.painting_id)))
|
||||
item_count = (database.session
|
||||
.query(func.count(distinct(Edit.artwork_id)))
|
||||
.scalar())
|
||||
|
||||
user_count = (database.session
|
||||
|
@ -458,7 +458,7 @@ def list_edits():
|
|||
return render_template('list_edits.html',
|
||||
edits=Edit.query,
|
||||
edit_list=edit_list,
|
||||
painting_count=painting_count,
|
||||
item_count=item_count,
|
||||
user_count=user_count)
|
||||
|
||||
@app.route("/user/<username>")
|
||||
|
@ -466,8 +466,8 @@ def user_page(username):
|
|||
edit_list = (Edit.query.filter_by(username=username)
|
||||
.order_by(Edit.timestamp.desc()))
|
||||
|
||||
painting_count = (database.session
|
||||
.query(func.count(distinct(Edit.painting_id)))
|
||||
item_count = (database.session
|
||||
.query(func.count(distinct(Edit.artwork_id)))
|
||||
.filter_by(username=username)
|
||||
.scalar())
|
||||
|
||||
|
@ -475,7 +475,7 @@ def user_page(username):
|
|||
username=username,
|
||||
edits=Edit.query,
|
||||
edit_list=edit_list,
|
||||
painting_count=painting_count)
|
||||
item_count=item_count)
|
||||
|
||||
@app.route("/next/Q<int:item_id>")
|
||||
def next_page(item_id):
|
||||
|
@ -569,11 +569,11 @@ def get_facets(params):
|
|||
if values
|
||||
}
|
||||
|
||||
def get_painting_params():
|
||||
def get_artwork_params():
|
||||
return [(pid, qid) for pid, qid in request.args.items()
|
||||
if pid.startswith('P') and qid.startswith('Q')]
|
||||
|
||||
def filter_painting(params):
|
||||
def filter_artwork(params):
|
||||
flat = '_'.join(f'{pid}={qid}' for pid, qid in params)
|
||||
q = render_template('query/find_more.sparql', params=params)
|
||||
bindings = wdqs.run_query_with_cache(q, flat)
|
||||
|
@ -582,8 +582,8 @@ def filter_painting(params):
|
|||
|
||||
@app.route('/catalog')
|
||||
def catalog_page():
|
||||
params = get_painting_params()
|
||||
bindings = filter_painting(params)
|
||||
params = get_artwork_params()
|
||||
bindings = filter_artwork(params)
|
||||
page = utils.get_int_arg('page') or 1
|
||||
page_size = 45
|
||||
|
||||
|
@ -655,7 +655,7 @@ def debug_show_user():
|
|||
|
||||
@app.route('/browse')
|
||||
def browse_page():
|
||||
params = get_painting_params()
|
||||
params = get_artwork_params()
|
||||
|
||||
if not params:
|
||||
return browse_index()
|
||||
|
@ -664,7 +664,7 @@ def browse_page():
|
|||
|
||||
item_labels = get_labels(qid for pid, qid in params)
|
||||
|
||||
bindings = filter_painting(params)
|
||||
bindings = filter_artwork(params)
|
||||
|
||||
facets = get_facets(params)
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ class QueryResultRow:
|
|||
for k, v in self.row.items()
|
||||
if not k.startswith('item')]
|
||||
|
||||
class Painting:
|
||||
class Artwork:
|
||||
def __init__(self, qid):
|
||||
self.entity = mediawiki.get_entity_with_cache(qid)
|
||||
self.item_id = int(qid[1:])
|
|
@ -45,8 +45,8 @@ class DepictsItemAltLabel(Base):
|
|||
def __init__(self, alt_label):
|
||||
self.alt_label = alt_label
|
||||
|
||||
class PaintingItem(Base):
|
||||
__tablename__ = 'painting'
|
||||
class ArtworkItem(Base):
|
||||
__tablename__ = 'artwork'
|
||||
item_id = Column(Integer, primary_key=True, autoincrement=False)
|
||||
label = Column(String)
|
||||
entity = Column(postgresql.JSON)
|
||||
|
@ -80,15 +80,15 @@ class Language(Base):
|
|||
class Edit(Base):
|
||||
__tablename__ = 'edit'
|
||||
username = Column(String, primary_key=True)
|
||||
painting_id = Column(Integer, ForeignKey('painting.item_id'), primary_key=True)
|
||||
artwork_id = Column(Integer, ForeignKey('artwork.item_id'), primary_key=True)
|
||||
depicts_id = Column(Integer, ForeignKey('depicts.item_id'), primary_key=True)
|
||||
timestamp = Column(DateTime, default=now_utc())
|
||||
lastrevid = Column(Integer, nullable=True)
|
||||
|
||||
painting_qid = column_property('Q' + cast(painting_id, String))
|
||||
artwork_qid = column_property('Q' + cast(artwork_id, String))
|
||||
depicts_qid = column_property('Q' + cast(depicts_id, String))
|
||||
|
||||
painting = relationship('PaintingItem')
|
||||
artwork = relationship('ArtworkItem')
|
||||
depicts = relationship('DepictsItem')
|
||||
|
||||
@property
|
||||
|
|
|
@ -176,7 +176,7 @@ def check_catalog(entity, catalog):
|
|||
'description': description,
|
||||
}
|
||||
|
||||
def get_catalog_from_painting(entity):
|
||||
def get_catalog_from_artwork(entity):
|
||||
catalog_ids = find_catalog_id(entity)
|
||||
catalog_detail = []
|
||||
for property_id in sorted(catalog_ids):
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Wikidata painting depicts{% endblock %}
|
||||
{% block title %}Wikidata Art Depiction Explorer{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="m-3">
|
||||
<p><a href="{{ url_for('random_painting') }}">random painting</a>
|
||||
<p><a href="{{ url_for('random_artwork') }}">random artwork</a>
|
||||
|
||||
{% if not g.user %}
|
||||
| <a href="{{ url_for('start_oauth') }}">connect to Wikidata account</a>
|
||||
|
|
|
@ -74,7 +74,7 @@
|
|||
<div>
|
||||
<a href="#">${ hit.label }</a>
|
||||
<span v-if="hit.alt_label">(${ hit.alt_label })</span>
|
||||
— ${ hit.count } existing paintings
|
||||
— ${ hit.count } existing artworks
|
||||
(${ hit.qid })
|
||||
<a :href="'https://www.wikidata.org/wiki/' + hit.qid">view on Wikidata</a>
|
||||
</div>
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
{% endfor %}
|
||||
</p>
|
||||
|
||||
<p>{{ '{:,d}'.format(total) }} paintings found</p>
|
||||
<p>{{ '{:,d}'.format(total) }} artworks found</p>
|
||||
|
||||
<p class="mb-3">
|
||||
<a href="#" id="toggle-filters" class="btn btn-primary">toggle filters</a>
|
||||
|
|
|
@ -30,8 +30,8 @@ span.description { color: rgb(96, 96, 96); }
|
|||
|
||||
<div class="m-2">
|
||||
<a href="https://www.wikidata.org/wiki/{{ qid }}" class="btn btn-primary">view on Wikidata</a>
|
||||
<a href="{{ url_for('random_painting') }}" class="btn btn-primary">skip this photo</a>
|
||||
<a href="{{ url_for('browse_page') }}" class="btn btn-primary">browse paintings</a>
|
||||
<a href="{{ url_for('random_artwork') }}" class="btn btn-primary">skip this artwork</a>
|
||||
<a href="{{ url_for('browse_page') }}" class="btn btn-primary">browse artworks</a>
|
||||
</div>
|
||||
|
||||
|
||||
|
@ -109,7 +109,7 @@ span.description { color: rgb(96, 96, 96); }
|
|||
{% raw %}
|
||||
<div id="app" class="mt-2">
|
||||
<div v-if="existing_depicts.length">
|
||||
<div>this painting has {{ existing_depicts.length }} existing depicts statement</div>
|
||||
<div>this artwork has {{ existing_depicts.length }} existing depicts statement</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-2" v-for="(hit, index) in existing_depicts">
|
||||
|
@ -118,14 +118,14 @@ span.description { color: rgb(96, 96, 96); }
|
|||
({{ hit.qid }})
|
||||
|
||||
<span v-if="hit.description" class="description">{{ hit.description }}</span>
|
||||
— {{ hit.count }} paintings
|
||||
— {{ hit.count }} artworks
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h3>what can you see in this painting?</h3>
|
||||
<h3>what can you see in this artwork?</h3>
|
||||
|
||||
<div v-if="people.length">
|
||||
<div>These people were born and died in the same years as appears in the title of the painting.</div>
|
||||
<div>These people were born and died in the same years as appears in the title of the artwork.</div>
|
||||
<div v-for="person in people">
|
||||
<a href="#" @click.prevent="add_person(person)">{{ person.label || '[name missing]' }}</a>,
|
||||
{{ person.year_of_birth }}-{{ person.year_of_death}} ({{ person.qid }})
|
||||
|
@ -135,7 +135,7 @@ span.description { color: rgb(96, 96, 96); }
|
|||
</div>
|
||||
|
||||
<div v-if="new_depicts.length">
|
||||
<div>{{ new_depicts.length }} new items to add to painting depicts statement</div>
|
||||
<div>{{ new_depicts.length }} new items to add to artwork depicts statement</div>
|
||||
</div>
|
||||
|
||||
<div v-for="(hit, index) in new_depicts">
|
||||
|
@ -144,7 +144,7 @@ span.description { color: rgb(96, 96, 96); }
|
|||
{{ hit.label }}
|
||||
<span v-if="hit.alt_label">({{ hit.alt_label }})</span>
|
||||
<a href="#" @click.prevent="remove(index)" >remove</a>
|
||||
— {{ hit.count }} existing paintings
|
||||
— {{ hit.count }} existing artworks
|
||||
({{ hit.qid }})
|
||||
<a :href="'https://www.wikidata.org/wiki/' + hit.qid">[wikidata]</a>
|
||||
</div>
|
||||
|
@ -153,7 +153,7 @@ span.description { color: rgb(96, 96, 96); }
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" v-if="new_depicts.length" class="btn btn-primary">add these to painting on Wikidata</button>
|
||||
<button type="submit" v-if="new_depicts.length" class="btn btn-primary">add these to artwork on Wikidata</button>
|
||||
|
||||
<input class="form-control-lg my-2 w-100" autocomplete="off" v-model.trim="searchTerms" ref="search" @input="search" />
|
||||
|
||||
|
@ -162,7 +162,7 @@ span.description { color: rgb(96, 96, 96); }
|
|||
<div>
|
||||
<a href="#" @click.prevent="add_depicts(hit)">{{ hit.label }}</a>
|
||||
<span v-if="hit.alt_label">({{ hit.alt_label }})</span>
|
||||
— {{ hit.count }} existing paintings
|
||||
— {{ hit.count }} existing artworks
|
||||
({{ hit.qid }})
|
||||
<a :href="'https://www.wikidata.org/wiki/' + hit.qid">view on Wikidata</a>
|
||||
</div>
|
||||
|
|
|
@ -7,13 +7,13 @@
|
|||
|
||||
<p>{{ user_count }} users have tried this tool.</p>
|
||||
|
||||
<p>{{ painting_count }} paintings have been cataloged.</p>
|
||||
<p>{{ item_count }} artworks have been cataloged.</p>
|
||||
|
||||
<table class="table w-auto">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>username</th>
|
||||
<th>painting</th>
|
||||
<th>artwork</th>
|
||||
<th>depicts</th>
|
||||
<th>when</th>
|
||||
</tr>
|
||||
|
@ -22,9 +22,9 @@
|
|||
{% for edit in edit_list %}
|
||||
<tr>
|
||||
<td><a href="{{ url_for('user_page', username=edit.username.replace('_', ' ')) }}">{{ edit.username }}</a></td>
|
||||
<td><a href="{{ url_for('item_page', item_id=edit.painting_id) }}">{{ edit.painting.label }}</a>
|
||||
({{ edit.painting_qid }})
|
||||
<a href="https://www.wikidata.org/wiki/{{ edit.painting_qid }}">[wikidata]</a>
|
||||
<td><a href="{{ url_for('item_page', item_id=edit.artwork_id) }}">{{ edit.artwork.label }}</a>
|
||||
({{ edit.artwork_qid }})
|
||||
<a href="https://www.wikidata.org/wiki/{{ edit.artwork_qid }}">[wikidata]</a>
|
||||
</td>
|
||||
<td><a href="https://www.wikidata.org/wiki/{{ edit.depicts_qid }}">{{ edit.depicts.label }}</a>
|
||||
({{ edit.depicts_qid }})</td>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<ul class="navbar-nav mr-auto">
|
||||
{{ nav_item('browse_page', 'Browse') }}
|
||||
{{ nav_item('list_edits', 'Recent changes') }}
|
||||
{{ nav_item('random_painting', 'Random painting') }}
|
||||
{{ nav_item('random_artwork', 'Random artwork') }}
|
||||
</ul>
|
||||
</ul>
|
||||
<ul class="navbar-nav">
|
||||
|
|
|
@ -12,15 +12,15 @@
|
|||
<h1>{{ self.title() }}</h1>
|
||||
|
||||
<div class="alert alert-primary" role="alert">
|
||||
Thanks for contributing. Your edits have been saved to the painting on Wikidata. Use the links below to find other similar paintings to catalog.
|
||||
Thanks for contributing. Your edits have been saved to the artwork on Wikidata. Use the links below to find other similar artworks to catalog.
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<a href="https://www.wikidata.org/wiki/{{ qid }}">view this painting on Wikidata</a>
|
||||
<a href="https://www.wikidata.org/wiki/{{ qid }}">view this artwork on Wikidata</a>
|
||||
|
|
||||
<a href="{{ url_for('random_painting') }}">switch to another painting</a>
|
||||
<a href="{{ url_for('random_artwork') }}">switch to another artwork</a>
|
||||
|
|
||||
<a href="{{ url_for('browse_page') }}">browse paintings</a>
|
||||
<a href="{{ url_for('browse_page') }}">browse artworks</a>
|
||||
</p>
|
||||
|
||||
{% if session.no_find_more %}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
— {{ row.objectDescription.value }}
|
||||
{% endif %}
|
||||
|
||||
({{ '{:,d}'.format(row.count.value | int) }} paintings)
|
||||
({{ '{:,d}'.format(row.count.value | int) }} artworks)
|
||||
{% if 'objectLabel' not in row %}
|
||||
<a href="https://wikidata.org/wiki/{{ qid }}">view in Wikidata</a>
|
||||
{% endif %}
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
|
||||
<p>This user has added a total of {{ edits.count() }} depicts statements.</p>
|
||||
|
||||
<p>{{ painting_count }} paintings have been cataloged.</p>
|
||||
<p>{{ item_count }} artworks have been cataloged.</p>
|
||||
|
||||
<table class="table w-auto">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>painting</th>
|
||||
<th>artwork</th>
|
||||
<th>depicts</th>
|
||||
<th>when</th>
|
||||
</tr>
|
||||
|
@ -20,9 +20,9 @@
|
|||
<tbody>
|
||||
{% for edit in edit_list %}
|
||||
<tr>
|
||||
<td><a href="{{ url_for('item_page', item_id=edit.painting_id) }}">{{ edit.painting.label }}</a>
|
||||
({{ edit.painting_qid }})
|
||||
<a href="https://www.wikidata.org/wiki/{{ edit.painting_qid }}">[wikidata]</a>
|
||||
<td><a href="{{ url_for('item_page', item_id=edit.artwork_id) }}">{{ edit.artwork.label }}</a>
|
||||
({{ edit.artwork_qid }})
|
||||
<a href="https://www.wikidata.org/wiki/{{ edit.artwork_qid }}">[wikidata]</a>
|
||||
</td>
|
||||
<td><a href="https://www.wikidata.org/wiki/{{ edit.depicts_qid }}">{{ edit.depicts.label }}</a>
|
||||
({{ edit.depicts_qid }})</td>
|
||||
|
|
Loading…
Reference in a new issue