From 036a4be5edffd7b6373a968ca16ee0c74c3e94a5 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Mon, 25 Nov 2019 11:49:34 +0000 Subject: [PATCH] Expand focus from paintings to more artworks Replace all references to 'painting' with 'artwork' --- app.py | 78 +++++++++---------- depicts/{painting.py => artwork.py} | 2 +- depicts/model.py | 10 +-- depicts/wd_catalog.py | 2 +- templates/browse_index.html | 4 +- templates/catalog.html | 2 +- templates/find_more.html | 2 +- templates/item.html | 20 ++--- templates/list_edits.html | 10 +-- templates/navbar.html | 2 +- templates/next.html | 8 +- templates/property.html | 2 +- ...picts.sparql => artwork_no_depicts.sparql} | 0 templates/user_page.html | 10 +-- 14 files changed, 76 insertions(+), 76 deletions(-) rename depicts/{painting.py => artwork.py} (99%) rename templates/query/{painting_no_depicts.sparql => artwork_no_depicts.sparql} (100%) diff --git a/app.py b/app.py index 794f984..40acf9e 100755 --- a/app.py +++ b/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', 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") 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,9 +447,9 @@ 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))) - .scalar()) + item_count = (database.session + .query(func.count(distinct(Edit.artwork_id))) + .scalar()) user_count = (database.session .query(func.count(distinct(Edit.username))) @@ -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/") @@ -466,16 +466,16 @@ 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))) - .filter_by(username=username) - .scalar()) + item_count = (database.session + .query(func.count(distinct(Edit.artwork_id))) + .filter_by(username=username) + .scalar()) return render_template('user_page.html', username=username, edits=Edit.query, edit_list=edit_list, - painting_count=painting_count) + item_count=item_count) @app.route("/next/Q") 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) diff --git a/depicts/painting.py b/depicts/artwork.py similarity index 99% rename from depicts/painting.py rename to depicts/artwork.py index cca218b..40cd67b 100644 --- a/depicts/painting.py +++ b/depicts/artwork.py @@ -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:]) diff --git a/depicts/model.py b/depicts/model.py index 8dfad18..00449e3 100644 --- a/depicts/model.py +++ b/depicts/model.py @@ -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 diff --git a/depicts/wd_catalog.py b/depicts/wd_catalog.py index fea312f..4c5fe8b 100644 --- a/depicts/wd_catalog.py +++ b/depicts/wd_catalog.py @@ -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): diff --git a/templates/browse_index.html b/templates/browse_index.html index 9e1007c..98c87b7 100644 --- a/templates/browse_index.html +++ b/templates/browse_index.html @@ -1,10 +1,10 @@ {% extends "base.html" %} -{% block title %}Wikidata painting depicts{% endblock %} +{% block title %}Wikidata Art Depiction Explorer{% endblock %} {% block content %}
-

random painting +

random artwork {% if not g.user %} | connect to Wikidata account diff --git a/templates/catalog.html b/templates/catalog.html index 2212bf5..9574679 100644 --- a/templates/catalog.html +++ b/templates/catalog.html @@ -74,7 +74,7 @@

${ hit.label } (${ hit.alt_label }) - — ${ hit.count } existing paintings + — ${ hit.count } existing artworks (${ hit.qid }) view on Wikidata
diff --git a/templates/find_more.html b/templates/find_more.html index 1fbe56b..a4d1480 100644 --- a/templates/find_more.html +++ b/templates/find_more.html @@ -27,7 +27,7 @@ {% endfor %}

-

{{ '{:,d}'.format(total) }} paintings found

+

{{ '{:,d}'.format(total) }} artworks found

toggle filters diff --git a/templates/item.html b/templates/item.html index 7eeda06..cae96f2 100644 --- a/templates/item.html +++ b/templates/item.html @@ -30,8 +30,8 @@ span.description { color: rgb(96, 96, 96); }

@@ -109,7 +109,7 @@ span.description { color: rgb(96, 96, 96); } {% raw %}
-
this painting has {{ existing_depicts.length }} existing depicts statement
+
this artwork has {{ existing_depicts.length }} existing depicts statement
@@ -118,14 +118,14 @@ span.description { color: rgb(96, 96, 96); } ({{ hit.qid }})   {{ hit.description }} - — {{ hit.count }} paintings + — {{ hit.count }} artworks
-

what can you see in this painting?

+

what can you see in this artwork?

-
These people were born and died in the same years as appears in the title of the painting.
+
These people were born and died in the same years as appears in the title of the artwork.
{{ person.label || '[name missing]' }}, {{ person.year_of_birth }}-{{ person.year_of_death}} ({{ person.qid }}) @@ -135,7 +135,7 @@ span.description { color: rgb(96, 96, 96); }
-
{{ new_depicts.length }} new items to add to painting depicts statement
+
{{ new_depicts.length }} new items to add to artwork depicts statement
@@ -144,7 +144,7 @@ span.description { color: rgb(96, 96, 96); } {{ hit.label }} ({{ hit.alt_label }}) remove - — {{ hit.count }} existing paintings + — {{ hit.count }} existing artworks ({{ hit.qid }}) [wikidata]
@@ -153,7 +153,7 @@ span.description { color: rgb(96, 96, 96); }
- + @@ -162,7 +162,7 @@ span.description { color: rgb(96, 96, 96); }
{{ hit.label }} ({{ hit.alt_label }}) - — {{ hit.count }} existing paintings + — {{ hit.count }} existing artworks ({{ hit.qid }}) view on Wikidata
diff --git a/templates/list_edits.html b/templates/list_edits.html index ebb1064..f5439c9 100644 --- a/templates/list_edits.html +++ b/templates/list_edits.html @@ -7,13 +7,13 @@

{{ user_count }} users have tried this tool.

-

{{ painting_count }} paintings have been cataloged.

+

{{ item_count }} artworks have been cataloged.

- + @@ -22,9 +22,9 @@ {% for edit in edit_list %} - diff --git a/templates/navbar.html b/templates/navbar.html index ad065db..bde2ebf 100644 --- a/templates/navbar.html +++ b/templates/navbar.html @@ -15,7 +15,7 @@
usernamepaintingartwork depicts when
{{ edit.username }}{{ edit.painting.label }} - ({{ edit.painting_qid }}) - [wikidata] + {{ edit.artwork.label }} + ({{ edit.artwork_qid }}) + [wikidata] {{ edit.depicts.label }} ({{ edit.depicts_qid }})
- + @@ -20,9 +20,9 @@ {% for edit in edit_list %} -
paintingartwork depicts when
{{ edit.painting.label }} - ({{ edit.painting_qid }}) - [wikidata] + {{ edit.artwork.label }} + ({{ edit.artwork_qid }}) + [wikidata] {{ edit.depicts.label }} ({{ edit.depicts_qid }})