Skip to content

Commit

Permalink
Coerce amendment source DOIs to URL form.
Browse files Browse the repository at this point in the history
This is done when fetching, adding, or updating a taxonomic amendment
via the API (so it "repairs" old amendments on the fly). Addresses #155.
  • Loading branch information
jimallman committed Sep 28, 2016
1 parent db4dcd3 commit 782bf9b
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion peyotl/api/amendments_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from peyotl.amendments.amendments_umbrella import TaxonomicAmendmentStore, TaxonomicAmendmentStoreProxy
from peyotl.api.wrapper import _WSWrapper, APIWrapper
from peyotl.amendments import AMENDMENT_ID_PATTERN
from peyotl.utility import get_logger
from peyotl.utility import get_logger, doi2url
import anyjson
import os
_LOG = get_logger(__name__)
Expand Down Expand Up @@ -121,6 +121,7 @@ def get_amendment(self, amendment_id):
else:
assert self._src_code == _GET_API
r = self._remote_get_amendment(amendment_id)
self._coerce_source_dois_to_urls(r.get('data'))
return r
@property
def auth_token(self):
Expand All @@ -146,10 +147,25 @@ def _remote_push_failure(self):
def unmerged_branches(self):
uri = '{}/amendments/unmerged_branches'.format(self._prefix)
return self.json_http_get(uri)
def _coerce_source_dois_to_urls(self,
json):
# Convert source DOIs to their URL form (when fetching, saving, or
# updating an amendment)
taxa = json.get('taxa')
if isinstance(taxa, list):
for taxon in taxa:
sources = taxon.get('sources')
if isinstance(sources, list):
for src in sources:
if src.get('source_type') == "Link (DOI) to publication":
doi = src.get('source', "")
src.set('source', doi2url(doi) )

def post_amendment(self,
json,
commit_msg=None):
assert json is not None
self._coerce_source_dois_to_urls(json)
uri = '{d}/amendment'.format(d=self._prefix)
params = {'auth_token': self.auth_token}
if commit_msg:
Expand All @@ -163,6 +179,7 @@ def put_amendment(self,
starting_commit_sha,
commit_msg=None):
assert json is not None
self._coerce_source_dois_to_urls(json)
uri = '{d}/amendment/{i}'.format(d=self._prefix, i=amendment_id)
params = {'starting_commit_SHA':starting_commit_sha,
'auth_token': self.auth_token}
Expand Down

0 comments on commit 782bf9b

Please sign in to comment.