Rename ArtworkItem to Item and add more fields

This commit is contained in:
Edward Betts 2019-12-17 16:10:45 +00:00
parent d2cbcc4c04
commit 7313df54f7
2 changed files with 19 additions and 10 deletions

12
app.py
View file

@ -4,7 +4,7 @@ from flask import Flask, render_template, url_for, redirect, request, g, jsonify
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, ArtworkItem,
from depicts.model import (DepictsItem, DepictsItemAltLabel, Edit, Item,
Language, WikidataQuery)
from depicts.error_mail import setup_error_mail
from requests_oauthlib import OAuth1Session
@ -121,11 +121,11 @@ def save(item_id):
token = wikidata_oauth.get_token()
artwork_item = ArtworkItem.query.get(item_id)
artwork_item = Item.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)
artwork_item = Item(item_id=item_id, label=label, entity=artwork_entity)
database.session.add(artwork_item)
database.session.commit()
@ -221,7 +221,7 @@ def random_artwork():
has_depicts = True
while has_depicts:
item_id = wdqs.row_id(random.choice(rows))
if ArtworkItem.query.get(item_id):
if Item.query.get(item_id):
continue
entity = mediawiki.get_entity_with_cache(f'Q{item_id}', refresh=True)
en_label = wikibase.get_en_label(entity)
@ -380,9 +380,9 @@ def item_page(item_id):
people = human.from_name(label) if label else None
artwork_item = ArtworkItem.query.get(item_id)
artwork_item = Item.query.get(item_id)
if artwork_item is None:
artwork_item = ArtworkItem(item_id=item_id, label=label, entity=entity)
artwork_item = Item(item_id=item_id, label=label, entity=entity)
database.session.add(artwork_item)
catalog = wd_catalog.get_catalog_from_artwork(entity)

View file

@ -46,13 +46,22 @@ class DepictsItemAltLabel(Base):
def __init__(self, alt_label):
self.alt_label = alt_label
class ArtworkItem(Base):
__tablename__ = 'artwork'
class Item(Base):
__tablename__ = 'item'
item_id = Column(Integer, primary_key=True, autoincrement=False)
label = Column(String)
entity = Column(postgresql.JSON)
lastrevid = Column(Integer, nullable=True, unique=True)
modified = Column(DateTime, nullable=True)
is_artwork = Column(Boolean, nullable=False, default=False)
qid = column_property('Q' + cast(item_id, String))
class Triple(Base):
__tablename__ = 'triple'
subject_id = Column(Integer, primary_key=True)
predicate_id = Column(Integer, primary_key=True, index=True)
object_id = Column(Integer, primary_key=True, index=True)
class HumanItem(Base):
__tablename__ = 'human'
item_id = Column(Integer, primary_key=True, autoincrement=False)
@ -81,7 +90,7 @@ class Language(Base):
class Edit(Base):
__tablename__ = 'edit'
username = Column(String, primary_key=True)
artwork_id = Column(Integer, ForeignKey('artwork.item_id'), primary_key=True)
artwork_id = Column(Integer, ForeignKey('item.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)
@ -89,7 +98,7 @@ class Edit(Base):
artwork_qid = column_property('Q' + cast(artwork_id, String))
depicts_qid = column_property('Q' + cast(depicts_id, String))
artwork = relationship('ArtworkItem')
artwork = relationship('Item')
depicts = relationship('DepictsItem')
@property