aboutsummaryrefslogtreecommitdiffstats
path: root/fatcat
diff options
context:
space:
mode:
Diffstat (limited to 'fatcat')
-rw-r--r--fatcat/api.py21
-rw-r--r--fatcat/api_client.py21
-rw-r--r--fatcat/models.py16
-rw-r--r--fatcat/routes.py21
-rw-r--r--fatcat/templates/editgroup_view.html8
-rw-r--r--fatcat/templates/editor_changelog.html17
-rw-r--r--fatcat/templates/editor_view.html9
7 files changed, 92 insertions, 21 deletions
diff --git a/fatcat/api.py b/fatcat/api.py
index 905a4317..60d0ba0c 100644
--- a/fatcat/api.py
+++ b/fatcat/api.py
@@ -10,7 +10,7 @@ from fatcat.sql import *
def get_or_create_edit_group(param=None):
if param != None:
- edit_group = EditGroup.query.filter(EditGroup.id==1).first_or_404()
+ edit_group = EditGroup.query.filter(EditGroup.id==int(param)).first_or_404()
return edit_group
editor = Editor.query.filter(Editor.id==1).first()
if editor.active_edit_group:
@@ -219,7 +219,9 @@ def api_file_create():
@app.route('/v0/editgroup/<int:ident>', methods=['GET'])
def api_edit_group_get(ident):
- entity = EditGroup.query.filter(EditGroup.id==ident).first_or_404()
+ 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)
@@ -242,3 +244,18 @@ def api_edit_group_accept(ident):
entity = EditGroup.query.filter(EditGroup.id==ident).first_or_404()
accept_editgroup(entity)
return jsonify({'success': True})
+
+
+@app.route('/v0/editor/<username>', methods=['GET'])
+def api_editor_get(username):
+ entity = Editor.query.filter(Editor.username==username).first_or_404()
+ return editor_schema.jsonify(entity)
+
+@app.route('/v0/editor/<username>/changelog', methods=['GET'])
+def api_editor_changelog(username):
+ entries = ChangelogEntry.query\
+ .join(ChangelogEntry.edit_group)\
+ .join(EditGroup.editor)\
+ .filter(Editor.username==username)\
+ .all()
+ return changelogentry_schema.jsonify(entries, many=True)
diff --git a/fatcat/api_client.py b/fatcat/api_client.py
index 12c70407..181c3ca7 100644
--- a/fatcat/api_client.py
+++ b/fatcat/api_client.py
@@ -9,11 +9,9 @@ class FatCatApiClient:
self.host_url = host_url
self.session = requests.Session()
-
def get(self, path):
return self.session.get(self.host_url + path)
-
def post(self, path, data=None, headers=None):
hdrs = {"content-type": "application/json"}
if headers:
@@ -22,22 +20,27 @@ class FatCatApiClient:
# data = json.dumps(data, indent=None).encode('utf-8')
return self.session.post(self.host_url + path, json=data, headers=hdrs)
-
def import_crossref_file(self, json_file):
+ eg = self.new_edit_group()
with open(json_file, 'r') as file:
for line in file:
obj = json.loads(line)
- self.import_crossref_dict(obj)
-
+ self.import_crossref_dict(obj, editgroup=eg)
+ self.accept_editgroup(eg)
def new_edit_group(self):
- rv = self.post('/v0/editgroup')
+ rv = self.post('/v0/editgroup', data=dict(
+ editor=1))
assert rv.status_code == 200
editgroup_id = rv.json()['id']
return editgroup_id
+ def accept_editgroup(self, eg):
+ rv = self.post('/v0/editgroup/{}/accept'.format(eg))
+ assert rv.status_code == 200
+ return rv
- def import_crossref_dict(self, meta):
+ def import_crossref_dict(self, meta, editgroup=None):
# creators
creators = []
@@ -71,7 +74,7 @@ class FatCatApiClient:
# work and release
title = meta['title'][0]
rv = self.post('/v0/work',
- data=dict(title=title)) #work_type="book"
+ data=dict(title=title, editgroup=editgroup)) #work_type="book"
assert rv.status_code == 200
work_id = rv.json()['id']
@@ -88,6 +91,7 @@ class FatCatApiClient:
issue=meta.get('issue', None),
volume=meta.get('volume', None),
pages=meta.get('page', None),
+ editgroup=editgroup,
extra=dict(crossref={
'links': meta.get('link', []),
'subject': meta['subject'],
@@ -96,7 +100,6 @@ class FatCatApiClient:
assert rv.status_code == 200
release_id = rv.json()['id']
-
def health(self):
rv = self.get("/health")
assert rv.status_code == 200
diff --git a/fatcat/models.py b/fatcat/models.py
index 957c929f..01aef79f 100644
--- a/fatcat/models.py
+++ b/fatcat/models.py
@@ -246,15 +246,15 @@ class EditGroup(db.Model):
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)
- editor = db.relationship('Editor', foreign_keys='EditGroup.editor_id')
extra_json_id = db.Column(db.ForeignKey('extra_json.sha1'), nullable=True)
extra_json = db.relationship("ExtraJson")
- # TODO: changelog entry relationship
+
+ editor = db.relationship("Editor", foreign_keys="EditGroup.editor_id")
class Editor(db.Model):
__tablename__ = 'editor'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
- username = db.Column(db.String)
+ 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')
@@ -264,6 +264,7 @@ class ChangelogEntry(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
edit_group_id = db.Column(db.ForeignKey('edit_group.id'))
timestamp = db.Column(db.Integer)
+ edit_group = db.relationship("EditGroup")
### Other ###################################################################
@@ -441,6 +442,13 @@ class EditorSchema(ma.ModelSchema):
class EditGroupSchema(ma.ModelSchema):
class Meta:
model = EditGroup
+ editor = ma.Nested(EditorSchema)
-editor_schema = EditGroupSchema()
+editor_schema = EditorSchema()
edit_group_schema = EditGroupSchema()
+
+class ChangelogEntrySchema(ma.ModelSchema):
+ class Meta:
+ model = ChangelogEntry
+
+changelogentry_schema = ChangelogEntrySchema()
diff --git a/fatcat/routes.py b/fatcat/routes.py
index 3bfcf58a..75411da9 100644
--- a/fatcat/routes.py
+++ b/fatcat/routes.py
@@ -83,6 +83,27 @@ def editgroup_current(ident):
eg = api.get_or_create_edit_group()
return redirect('/editgroup/{}'.format(eg.id))
+@app.route('/editor/<username>', methods=['GET'])
+def editor_view(username):
+ rv = api.api_editor_get(username)
+ if rv.status_code != 200:
+ # TODO: better wrapping for all entities
+ return abort(rv.status_code)
+ entity = json.loads(rv.data.decode('utf-8'))
+ return render_template('editor_view.html', editor=entity)
+
+@app.route('/editor/<username>/changelog', methods=['GET'])
+def editor_changelog(username):
+ rv = api.api_editor_get(username)
+ if rv.status_code != 200:
+ # TODO: better wrapping for all entities
+ return abort(rv.status_code)
+ editor = json.loads(rv.data.decode('utf-8'))
+ rv = api.api_editor_changelog(username)
+ changelog_entries = json.loads(rv.data.decode('utf-8'))
+ return render_template('editor_changelog.html', editor=editor,
+ changelog_entries=changelog_entries)
+
### Static Routes ###########################################################
diff --git a/fatcat/templates/editgroup_view.html b/fatcat/templates/editgroup_view.html
index 13eb2d7f..144c9502 100644
--- a/fatcat/templates/editgroup_view.html
+++ b/fatcat/templates/editgroup_view.html
@@ -1,13 +1,9 @@
{% extends "base.html" %}
{% block body %}
-<h1>Edit Group: {{ editgroup.id}}</h1>
+<h1>Edit Group: #{{ editgroup.id}}</h1>
- description = db.Column(db.String)
- editor = db.relationship('Editor', foreign_keys='EditGroup.editor_id')
-
-
-<p>Editor: <a href="/editor/{{ editgroup.editor.id }}">{{ editgroup.editor.username }}</a>
+<p>Editor: <a href="/editor/{{ editgroup.editor.username }}">{{ editgroup.editor.username }}</a>
<p>Description: {{ editgroup.description }}
<p>TODO: list edits by type...</p>
diff --git a/fatcat/templates/editor_changelog.html b/fatcat/templates/editor_changelog.html
new file mode 100644
index 00000000..5d87d82e
--- /dev/null
+++ b/fatcat/templates/editor_changelog.html
@@ -0,0 +1,17 @@
+{% extends "base.html" %}
+{% block body %}
+
+<h1>Editor Changelog: {{ editor.username }}</h1>
+
+<p>Editor: <a href="/editor/{{ editor.username }}">{{ editor.username }}</a>
+
+<p>Changes accepted (aka, merged editgroups):
+<ul>
+{% for entry in changelog_entries %}
+ <li><a href="/editgroup/{{ entry.edit_group }}">Edit Group #{{ entry.edit_group }}</a> (on {{ entry.timestamp }})
+{% else %}
+NONE
+{% endfor %}
+</ul>
+
+{% endblock %}
diff --git a/fatcat/templates/editor_view.html b/fatcat/templates/editor_view.html
new file mode 100644
index 00000000..e0625c42
--- /dev/null
+++ b/fatcat/templates/editor_view.html
@@ -0,0 +1,9 @@
+{% extends "base.html" %}
+{% block body %}
+
+<h1>Editor: {{ editor.username }}</h1>
+
+<p>Is Admin? {{ editor.is_admin }}
+<p><a href="/editor/{{ editor.username }}/changelog">Changelog</a>
+
+{% endblock %}