aboutsummaryrefslogtreecommitdiffstats
path: root/fatcat
diff options
context:
space:
mode:
Diffstat (limited to 'fatcat')
-rw-r--r--fatcat/api.py50
-rw-r--r--fatcat/api_client.py4
-rw-r--r--fatcat/models.py32
-rw-r--r--fatcat/routes.py4
-rw-r--r--fatcat/sql.py20
5 files changed, 55 insertions, 55 deletions
diff --git a/fatcat/api.py b/fatcat/api.py
index 60d0ba0c..77afef0a 100644
--- a/fatcat/api.py
+++ b/fatcat/api.py
@@ -8,21 +8,21 @@ from fatcat.sql import *
### Helpers #################################################################
-def get_or_create_edit_group(param=None):
+def get_or_create_editgroup(param=None):
if param != None:
- edit_group = EditGroup.query.filter(EditGroup.id==int(param)).first_or_404()
- return edit_group
+ editgroup = EditGroup.query.filter(EditGroup.id==int(param)).first_or_404()
+ return editgroup
editor = Editor.query.filter(Editor.id==1).first()
- if editor.active_edit_group:
- return editor.active_edit_group
+ if editor.active_editgroup:
+ return editor.active_editgroup
- edit_group = EditGroup(editor=editor)
- db.session.add(edit_group)
+ editgroup = EditGroup(editor=editor)
+ db.session.add(editgroup)
db.session.commit()
- editor.active_edit_group = edit_group
+ editor.active_editgroup = editgroup
db.session.add(editor)
db.session.commit()
- return edit_group
+ return editgroup
### Views ###################################################################
@@ -35,13 +35,13 @@ def api_work_get(ident):
def api_work_create():
# TODO: Special-case to pull out primary and create that?
params = request.get_json()
- edit_group = get_or_create_edit_group(params.get('editgroup'))
+ editgroup = get_or_create_editgroup(params.get('editgroup'))
rev = WorkRev(
title=params.get('title', None),
work_type=params.get('work_type', None),
)
ident = WorkIdent(is_live=False, rev=rev)
- edit = WorkEdit(edit_group=edit_group, ident=ident, rev=rev)
+ edit = WorkEdit(editgroup=editgroup, ident=ident, rev=rev)
if params.get('extra', None):
ser = json.dumps(params['extra'], indent=False).encode('utf-8')
rev.extra_json = ExtraJson(json=ser, sha1=hashlib.sha1(ser).hexdigest())
@@ -63,7 +63,7 @@ def api_release_get(ident):
@app.route('/v0/release', methods=['POST'])
def api_release_create():
params = request.get_json()
- edit_group = get_or_create_edit_group(params.get('editgroup'))
+ editgroup = get_or_create_editgroup(params.get('editgroup'))
creators = params.get('creators', [])
creators = [CreatorIdent.query.filter(CreatorIdent.id==c).first_or_404() for c in creators]
targets = [ref['target'] for ref in params.get('refs', []) if ref.get('target') != None]
@@ -88,7 +88,7 @@ def api_release_create():
rev.refs = refs
db.session.add_all(refs)
ident = ReleaseIdent(is_live=False, rev=rev)
- edit = ReleaseEdit(edit_group=edit_group, ident=ident, rev=rev)
+ edit = ReleaseEdit(editgroup=editgroup, ident=ident, rev=rev)
if params.get('extra', None):
ser = json.dumps(params['extra'], indent=False).encode('utf-8')
rev.extra_json = ExtraJson(json=ser, sha1=hashlib.sha1(ser).hexdigest())
@@ -123,13 +123,13 @@ def api_creator_get(ident):
@app.route('/v0/creator', methods=['POST'])
def api_creator_create():
params = request.get_json()
- edit_group = get_or_create_edit_group(params.get('editgroup'))
+ editgroup = get_or_create_editgroup(params.get('editgroup'))
rev = CreatorRev(
name=params.get('name', None),
orcid=params.get('orcid', None),
)
ident = CreatorIdent(is_live=False, rev=rev)
- edit = CreatorEdit(edit_group=edit_group, ident=ident, rev=rev)
+ edit = CreatorEdit(editgroup=editgroup, ident=ident, rev=rev)
if params.get('extra', None):
ser = json.dumps(params['extra'], indent=False).encode('utf-8')
rev.extra_json = ExtraJson(json=ser, sha1=hashlib.sha1(ser).hexdigest())
@@ -159,14 +159,14 @@ def api_container_get(ident):
@app.route('/v0/container', methods=['POST'])
def api_container_create():
params = request.get_json()
- edit_group = get_or_create_edit_group(params.get('editgroup'))
+ editgroup = get_or_create_editgroup(params.get('editgroup'))
rev = ContainerRev(
name=params.get('name', None),
publisher=params.get('publisher', None),
issn=params.get('issn', None),
)
ident = ContainerIdent(is_live=False, rev=rev)
- edit = ContainerEdit(edit_group=edit_group, ident=ident, rev=rev)
+ edit = ContainerEdit(editgroup=editgroup, ident=ident, rev=rev)
if params.get('extra', None):
ser = json.dumps(params['extra'], indent=False).encode('utf-8')
rev.extra_json = ExtraJson(json=ser, sha1=hashlib.sha1(ser).hexdigest())
@@ -196,7 +196,7 @@ def api_file_get(ident):
@app.route('/v0/file', methods=['POST'])
def api_file_create():
params = request.get_json()
- edit_group = get_or_create_edit_group(params.get('editgroup'))
+ editgroup = get_or_create_editgroup(params.get('editgroup'))
releases = params.get('releases', [])
releases = [ReleaseIdent.query.filter(ReleaseIdent.id==r).first_or_404() for r in releases]
rev = FileRev(
@@ -208,7 +208,7 @@ def api_file_create():
rev.releases = file_releases
db.session.add_all(file_releases)
ident = FileIdent(is_live=False, rev=rev)
- edit = FileEdit(edit_group=edit_group, ident=ident, rev=rev)
+ edit = FileEdit(editgroup=editgroup, ident=ident, rev=rev)
if params.get('extra', None):
ser = json.dumps(params['extra'], indent=False).encode('utf-8')
rev.extra_json = ExtraJson(json=ser, sha1=hashlib.sha1(ser).hexdigest())
@@ -218,15 +218,15 @@ def api_file_create():
@app.route('/v0/editgroup/<int:ident>', methods=['GET'])
-def api_edit_group_get(ident):
+def api_editgroup_get(ident):
entity = EditGroup.query\
.join(EditGroup.editor)\
.filter(EditGroup.id==ident).first_or_404()
# TODO: fill in all the related edit types...
- return edit_group_schema.jsonify(entity)
+ return editgroup_schema.jsonify(entity)
@app.route('/v0/editgroup', methods=['POST'])
-def api_edit_group_create():
+def api_editgroup_create():
params = request.get_json()
eg = EditGroup(
editor_id=1,
@@ -237,10 +237,10 @@ def api_edit_group_create():
eg.extra_json = ExtraJson(json=ser, sha1=hashlib.sha1(ser).hexdigest())
db.session.add(eg)
db.session.commit()
- return edit_group_schema.jsonify(eg)
+ return editgroup_schema.jsonify(eg)
@app.route('/v0/editgroup/<int:ident>/accept', methods=['POST'])
-def api_edit_group_accept(ident):
+def api_editgroup_accept(ident):
entity = EditGroup.query.filter(EditGroup.id==ident).first_or_404()
accept_editgroup(entity)
return jsonify({'success': True})
@@ -254,7 +254,7 @@ def api_editor_get(username):
@app.route('/v0/editor/<username>/changelog', methods=['GET'])
def api_editor_changelog(username):
entries = ChangelogEntry.query\
- .join(ChangelogEntry.edit_group)\
+ .join(ChangelogEntry.editgroup)\
.join(EditGroup.editor)\
.filter(Editor.username==username)\
.all()
diff --git a/fatcat/api_client.py b/fatcat/api_client.py
index 181c3ca7..e371b727 100644
--- a/fatcat/api_client.py
+++ b/fatcat/api_client.py
@@ -21,14 +21,14 @@ class FatCatApiClient:
return self.session.post(self.host_url + path, json=data, headers=hdrs)
def import_crossref_file(self, json_file):
- eg = self.new_edit_group()
+ eg = self.new_editgroup()
with open(json_file, 'r') as file:
for line in file:
obj = json.loads(line)
self.import_crossref_dict(obj, editgroup=eg)
self.accept_editgroup(eg)
- def new_edit_group(self):
+ def new_editgroup(self):
rv = self.post('/v0/editgroup', data=dict(
editor=1))
assert rv.status_code == 200
diff --git a/fatcat/models.py b/fatcat/models.py
index 01aef79f..1bb648c8 100644
--- a/fatcat/models.py
+++ b/fatcat/models.py
@@ -87,12 +87,12 @@ class WorkEdit(db.Model):
ident_id = db.Column(db.ForeignKey('work_ident.id'), nullable=True)
rev_id = db.Column(db.ForeignKey('work_rev.id'), nullable=True)
redirect_id = db.Column(db.ForeignKey('work_ident.id'), nullable=True)
- edit_group_id = db.Column(db.ForeignKey('edit_group.id'), nullable=True)
+ editgroup_id = db.Column(db.ForeignKey('editgroup.id'), nullable=True)
extra_json_id = db.Column(db.ForeignKey('extra_json.sha1'), nullable=True)
extra_json = db.relationship("ExtraJson")
ident = db.relationship("WorkIdent", foreign_keys="WorkEdit.ident_id")
rev = db.relationship("WorkRev")
- edit_group = db.relationship("EditGroup")
+ editgroup = db.relationship("EditGroup")
class ReleaseRev(db.Model):
@@ -131,12 +131,12 @@ class ReleaseEdit(db.Model):
ident_id = db.Column(db.ForeignKey('release_ident.id'), nullable=True)
rev_id = db.Column(db.ForeignKey('release_rev.id'), nullable=True)
redirect_id = db.Column(db.ForeignKey('release_ident.id'), nullable=True)
- edit_group_id = db.Column(db.ForeignKey('edit_group.id'), nullable=True)
+ editgroup_id = db.Column(db.ForeignKey('editgroup.id'), nullable=True)
extra_json_id = db.Column(db.ForeignKey('extra_json.sha1'), nullable=True)
extra_json = db.relationship("ExtraJson")
ident = db.relationship("ReleaseIdent", foreign_keys="ReleaseEdit.ident_id")
rev = db.relationship("ReleaseRev")
- edit_group = db.relationship("EditGroup")
+ editgroup = db.relationship("EditGroup")
class CreatorRev(db.Model):
@@ -163,12 +163,12 @@ class CreatorEdit(db.Model):
ident_id = db.Column(db.ForeignKey('creator_ident.id'), nullable=True)
rev_id = db.Column(db.ForeignKey('creator_rev.id'), nullable=True)
redirect_id = db.Column(db.ForeignKey('creator_ident.id'), nullable=True)
- edit_group_id = db.Column(db.ForeignKey('edit_group.id'), nullable=True)
+ editgroup_id = db.Column(db.ForeignKey('editgroup.id'), nullable=True)
extra_json_id = db.Column(db.ForeignKey('extra_json.sha1'), nullable=True)
extra_json = db.relationship("ExtraJson")
ident = db.relationship("CreatorIdent", foreign_keys="CreatorEdit.ident_id")
rev = db.relationship("CreatorRev")
- edit_group = db.relationship("EditGroup")
+ editgroup = db.relationship("EditGroup")
class ContainerRev(db.Model):
@@ -198,12 +198,12 @@ class ContainerEdit(db.Model):
ident_id = db.Column(db.ForeignKey('container_ident.id'), nullable=True)
rev_id = db.Column(db.ForeignKey('container_rev.id'), nullable=True)
redirect_id = db.Column(db.ForeignKey('container_ident.id'), nullable=True)
- edit_group_id = db.Column(db.ForeignKey('edit_group.id'), nullable=True)
+ editgroup_id = db.Column(db.ForeignKey('editgroup.id'), nullable=True)
extra_json_id = db.Column(db.ForeignKey('extra_json.sha1'), nullable=True)
extra_json = db.relationship("ExtraJson")
ident = db.relationship("ContainerIdent", foreign_keys="ContainerEdit.ident_id")
rev = db.relationship("ContainerRev")
- edit_group = db.relationship("EditGroup")
+ editgroup = db.relationship("EditGroup")
class FileRev(db.Model):
@@ -231,18 +231,18 @@ class FileEdit(db.Model):
ident_id = db.Column(db.ForeignKey('file_ident.id'), nullable=True)
rev_id = db.Column(db.ForeignKey('file_rev.id'), nullable=True)
redirect_id = db.Column(db.ForeignKey('file_ident.id'), nullable=True)
- edit_group_id = db.Column(db.ForeignKey('edit_group.id'), nullable=True)
+ editgroup_id = db.Column(db.ForeignKey('editgroup.id'), nullable=True)
extra_json_id = db.Column(db.ForeignKey('extra_json.sha1'), nullable=True)
extra_json = db.relationship("ExtraJson")
ident = db.relationship("FileIdent", foreign_keys="FileEdit.ident_id")
rev = db.relationship("FileRev")
- edit_group = db.relationship("EditGroup")
+ editgroup = db.relationship("EditGroup")
### Editing #################################################################
class EditGroup(db.Model):
- __tablename__ = 'edit_group'
+ __tablename__ = 'editgroup'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
editor_id = db.Column(db.ForeignKey('editor.id'), nullable=False)
description = db.Column(db.String)
@@ -256,15 +256,15 @@ class Editor(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
username = db.Column(db.String, nullable=False, unique=True)
is_admin = db.Column(db.Boolean, nullable=False, default=False)
- active_edit_group_id = db.Column(db.ForeignKey('edit_group.id', use_alter=True))
- active_edit_group = db.relationship('EditGroup', foreign_keys='Editor.active_edit_group_id')
+ active_editgroup_id = db.Column(db.ForeignKey('editgroup.id', use_alter=True))
+ active_editgroup = db.relationship('EditGroup', foreign_keys='Editor.active_editgroup_id')
class ChangelogEntry(db.Model):
__tablename__= 'changelog'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
- edit_group_id = db.Column(db.ForeignKey('edit_group.id'))
+ editgroup_id = db.Column(db.ForeignKey('editgroup.id'))
timestamp = db.Column(db.Integer)
- edit_group = db.relationship("EditGroup")
+ editgroup = db.relationship("EditGroup")
### Other ###################################################################
@@ -445,7 +445,7 @@ class EditGroupSchema(ma.ModelSchema):
editor = ma.Nested(EditorSchema)
editor_schema = EditorSchema()
-edit_group_schema = EditGroupSchema()
+editgroup_schema = EditGroupSchema()
class ChangelogEntrySchema(ma.ModelSchema):
class Meta:
diff --git a/fatcat/routes.py b/fatcat/routes.py
index f6d6c4e3..b1568833 100644
--- a/fatcat/routes.py
+++ b/fatcat/routes.py
@@ -71,7 +71,7 @@ def file_view(ident):
@app.route('/editgroup/<int:ident>', methods=['GET'])
def editgroup_view(ident):
- rv = api.api_edit_group_get(ident)
+ rv = api.api_editgroup_get(ident)
if rv.status_code != 200:
# TODO: better wrapping for all entities
return abort(rv.status_code)
@@ -80,7 +80,7 @@ def editgroup_view(ident):
@app.route('/editgroup/current', methods=['GET'])
def editgroup_current():
- eg = api.get_or_create_edit_group()
+ eg = api.get_or_create_editgroup()
return redirect('/editgroup/{}'.format(eg.id))
@app.route('/editor/<username>', methods=['GET'])
diff --git a/fatcat/sql.py b/fatcat/sql.py
index 3f88ea12..f05bd0ee 100644
--- a/fatcat/sql.py
+++ b/fatcat/sql.py
@@ -85,13 +85,13 @@ def accept_editgroup(eg):
# check if already accepted
# XXX: add a test for this
- assert ChangelogEntry.query.filter(ChangelogEntry.edit_group_id==eg.id).count() == 0
+ assert ChangelogEntry.query.filter(ChangelogEntry.editgroup_id==eg.id).count() == 0
# start transaction (TODO: explicitly?)
# for each entity type:
for cls in (WorkEdit, ReleaseEdit, CreatorEdit, ContainerEdit, FileEdit):
- edits = cls.query.filter(cls.edit_group_id==eg.id).all()
+ edits = cls.query.filter(cls.editgroup_id==eg.id).all()
# for each entity edit->ident:
for edit in edits:
# update entity ident state (activate, redirect, delete)
@@ -102,7 +102,7 @@ def accept_editgroup(eg):
# append log/changelog row
cle = ChangelogEntry(
- edit_group_id=eg.id,
+ editgroup_id=eg.id,
# TODO: is this UTC?
timestamp=int(time.time()))
db.session.add(cle)
@@ -111,12 +111,12 @@ def accept_editgroup(eg):
db.session.add(eg)
# no longer "active"
- eg.editor.active_edit_group = None
+ eg.editor.active_editgroup = None
db.session.add(eg.editor)
db.session.commit()
-def merge_works(left_id, right_id, edit_group=None):
+def merge_works(left_id, right_id, editgroup=None):
"""Helper to merge two works together."""
left = WorkIdent.query.filter(WorkIdent.id == left_id).first_or_404()
right = WorkIdent.query.filter(WorkIdent.id == right_id).first_or_404()
@@ -124,8 +124,8 @@ def merge_works(left_id, right_id, edit_group=None):
assert left.rev and right.rev
assert (left.redirect_id == None) and (right.redirect_id == None)
- if edit_group is None:
- edit_group = fatcat.api.get_or_create_edit_group()
+ if editgroup is None:
+ editgroup = fatcat.api.get_or_create_editgroup()
releases = ReleaseIdent.query\
.join(ReleaseIdent.rev)\
@@ -142,11 +142,11 @@ def merge_works(left_id, right_id, edit_group=None):
rev.id = None
rev.parent = old_id
rev.work_ident_id = left.id
- re = ReleaseEdit(edit_group=edit_group, ident=release_ident, rev=rev)
+ re = ReleaseEdit(editgroup=editgroup, ident=release_ident, rev=rev)
db.session.add_all([rev, re])
- # redirect right id to left (via edit_group)
- neww = WorkEdit(edit_group=edit_group, ident=right,
+ # redirect right id to left (via editgroup)
+ neww = WorkEdit(editgroup=editgroup, ident=right,
rev=left.rev, redirect_id=left.id)
db.session.add_all([neww])