summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-04-12 12:48:10 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-04-12 12:48:10 -0700
commit9156b2f4ff73df43ed63b12ac135dbb0e22d3663 (patch)
tree6a770c8289dbcc3aed63af1e9cc8c3350948da20
parentf819a369af5237f340e9229169c4fbed92778d64 (diff)
downloadfatcat-9156b2f4ff73df43ed63b12ac135dbb0e22d3663.tar.gz
fatcat-9156b2f4ff73df43ed63b12ac135dbb0e22d3663.zip
citations
-rw-r--r--fatcat/models.py4
-rw-r--r--fatcat/sql.py13
2 files changed, 10 insertions, 7 deletions
diff --git a/fatcat/models.py b/fatcat/models.py
index 6672ce2e..9abb286e 100644
--- a/fatcat/models.py
+++ b/fatcat/models.py
@@ -39,7 +39,7 @@ class ReleaseRef(db.Model):
__tablename__ = "release_ref"
id = db.Column(db.Integer, primary_key=True, nullable=False)
release_rev= db.Column(db.ForeignKey('release_revision.id'), nullable=False)
- target_release_id= db.Column(db.ForeignKey('release_id.id'), nullable=False)
+ target_release_id= db.Column(db.ForeignKey('release_id.id'), nullable=True)
index = db.Column(db.Integer, nullable=True)
stub = db.Column(db.String, nullable=True)
doi = db.Column(db.String, nullable=True)
@@ -122,9 +122,7 @@ class ReleaseRevision(db.Model):
issue = db.Column(db.String, nullable=True)
creators = db.relationship('ReleaseContrib', lazy='subquery')
- #backref=db.backref('releases', lazy=True))
refs = db.relationship('ReleaseRef', lazy='subquery')
- #backref=db.backref('backrefs', lazy=True))
class CreatorId(db.Model):
__tablename__ = 'creator_id'
diff --git a/fatcat/sql.py b/fatcat/sql.py
index c3c928a8..ad0a045f 100644
--- a/fatcat/sql.py
+++ b/fatcat/sql.py
@@ -184,10 +184,15 @@ def add_crossref(meta):
extra_json = ExtraJson(json=extra, sha1=hashlib.sha1(extra).hexdigest())
release.extra_json = extra_json.sha1
- # references (TODO)
- #refs = []
- #for rm in meta['reference']:
- # rm: author, volume, first-page, year, journal-title, DOI
+ # references
+ for i, rm in enumerate(meta.get('reference', [])):
+ ref = ReleaseRef(
+ release_rev=release.id,
+ doi=rm.get("DOI", None),
+ index=i+1,
+ # TODO: how to generate a proper stub here from k/v metadata?
+ stub="| ".join(rm.values()))
+ release.refs.append(ref)
db.session.add_all([work, work_id, release, release_id, container,
container_id, extra_json])