Skip to content

Commit

Permalink
Merge 800e4ea into 178b3ea
Browse files Browse the repository at this point in the history
  • Loading branch information
egabancho committed Apr 22, 2016
2 parents 178b3ea + 800e4ea commit d8f7b57
Show file tree
Hide file tree
Showing 30 changed files with 266 additions and 28 deletions.
11 changes: 5 additions & 6 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,21 @@

include *.rst
include *.sh
include *.txt
include *.yml
include .coveragerc
include .travis.yml
include .dockerignore
include .travis.yml
include Dockerfile
include LICENSE
include pytest.ini
include tox.ini
recursive-include cds_dojson *.json
recursive-include cds_dojson *.py
recursive-include docs *.py
recursive-include docs *.rst
recursive-include docs Makefile
recursive-include dojson *.py
recursive-include dojson *.json
recursive-include dojson *.py
recursive-include tests *.py

# added by check_manifest.py
include *.txt
recursive-include cds_dojson *.py
recursive-include tests *.xml
6 changes: 4 additions & 2 deletions cds_dojson/marc21/models/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@

"""Album model."""

from ...overdo import Overdo
from ...overdo import OverdoJSONSchema
from .default import model as cds_marc21


class CDSAlbum(Overdo):
class CDSAlbum(OverdoJSONSchema):
"""Translation Index for CDS Albums."""

__query__ = '999__.a:ALBUM'

__schema__ = 'marc21/cds_bibliographic/album-v1.0.0.json'

model = CDSAlbum(bases=(cds_marc21, ),
entry_point_group='cds_dojson.marc21.album')

Expand Down
6 changes: 4 additions & 2 deletions cds_dojson/marc21/models/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@

from dojson.contrib.marc21 import marc21

from ...overdo import Overdo
from ...overdo import OverdoJSONSchema


class CDSMarc21(Overdo):
class CDSMarc21(OverdoJSONSchema):
"""Translation Index for CDS specific MARC21."""

__query__ = '690C_.a:CERN'

__schema__ = 'marc21/cds_bibliographic/default-v1.0.0.json'


model = CDSMarc21(bases=(marc21, ),
entry_point_group='cds_dojson.marc21.default')
Expand Down
6 changes: 4 additions & 2 deletions cds_dojson/marc21/models/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@

"""Image model."""

from ...overdo import Overdo
from ...overdo import OverdoJSONSchema
from .default import model as cds_marc21


class CDSImage(Overdo):
class CDSImage(OverdoJSONSchema):
"""Translation Index for CDS Images."""

__query__ = '999__.a:IMAGE'

__schema__ = 'marc21/cds_bibliographic/image-v1.0.0.json'

model = CDSImage(bases=(cds_marc21, ),
entry_point_group='cds_dojson.marc21.image')

Expand Down
6 changes: 4 additions & 2 deletions cds_dojson/marc21/models/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@

"""Video model."""

from ...overdo import Overdo
from ...overdo import OverdoJSONSchema
from .default import model as cds_marc21


class CDSVideo(Overdo):
class CDSVideo(OverdoJSONSchema):
"""Translation Index for CDS Videos."""

__query__ = '980__.a:PUBLVIDEOMOVIE'

__schema__ = 'marc21/cds_bibliographic/video-v1.0.0.json'

model = CDSVideo(bases=(cds_marc21, ),
entry_point_group='cds_dojson.marc21.video')

Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"allOf": [
{"$ref": "default-v1.0.0.json"}
{"$ref": "album.json"}
]
}
44 changes: 44 additions & 0 deletions cds_dojson/marc21/schemas/marc21/cds_bibliographic/album.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"type": "object",
"properties": {
"images": {
"description": "Images contained in the album",
"properties": {
"record_type": {
"type": "string"
},
"relation": {
"type": "string"
},
"$ref": {
"type": "string"
}
}
},
"place_of_photo": {
"description": "Place of photo where it was taken and requester info",
"properties": {
"place": {
"type": "string"
},
"requester": {
"type": "string"
}
}
},
"photolab": {
"description": "PhotoLab",
"properties": {
"tirage":{
"type": "string"
},
"photolab_1": {
"type": "string"
},
"photolab_2": {
"type": "string"
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"allOf": [
{"$ref": "bd-v1.0.1.json"},

]

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"allOf": [
{"$ref": "default-v1.0.0.json"}
{"$ref": "image.json"}
]
}
60 changes: 60 additions & 0 deletions cds_dojson/marc21/schemas/marc21/cds_bibliographic/image.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"type": "object",
"properties": {
"album_parent": {
"description": "Album ID which contains this photo",
"type": "array",
"items": {
"type": "object",
"properties": {
"dump_album": {
"type": "string"
},
"album_id": {
"type": "string"
},
}
}
},
"image_url": {
"description": "Image URL",
"type": "array",
"items": {
"type": "object",
"properties": {
"size": {
"type": "string"
},
"path": {
"type": "string"
},
"electronic_format_type": {
"type": "string"
},
"uri": {
"type": "string"
},
"link_text": {
"type": "string"
},
"subformat": {
"type": "string"
},
"photo_id": {
"type": "string"
},
"relationship": {
"type": "string"
},
"public_note": {
"type": "string"
},
"access_method": {
"type": "string"
},
}
}
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"allOf": [
{"$ref": "default-v1.0.0.json"}
{"$ref": "video.json"}
]
}

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
43 changes: 43 additions & 0 deletions cds_dojson/overdo.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,24 @@

"""Base classes for CDS DoJSON."""

import pkg_resources

from dojson.overdo import Overdo as DoJSONOverdo
from dojson.contrib.to_marc21.model import Underdo as DoJSONUnderdo

from .matcher import matcher

try:
pkg_resources.get_distribution('flask')
from flask import current_app
current_app.app_context()
if 'invenio-jsonschemas' not in current_app.extension:
raise RuntimeError
except (pkg_resources.DistributionNotFound, RuntimeError):
HAS_FLASK = False
else:
HAS_FLASK = True


class OverdoBase(DoJSONOverdo):
"""Base entry class."""
Expand Down Expand Up @@ -72,3 +86,32 @@ def override(rule):
self.rules[:] = [rule for rule in self.rules if not override(rule)]

return super(Overdo, self).over(name, *source_tags)


class OverdoJSONSchema(Overdo):
"""Translation index which adds $schema key."""

__schema__ = ''
"""Name of the schema to be added to the final JSON."""

def do(self, blob, ignore_missing=True, exception_handlers=None):
"""."""
json = super(Overdo, self).do(
blob=blob,
ignore_missing=ignore_missing,
exception_handlers=exception_handlers
)
if HAS_FLASK:
json_schema = current_app.extensions['invenio-jsonschemas']
json['$schema'] = json_schema.path_to_url(
self.__class__.__schema__)
else:
json['$schema'] = {'$ref': self.__class__.__schema__}

return json


class Underdo(Overdo, DoJSONUnderdo):
"""Translation index specification for reverse marc21 translation."""

pass
5 changes: 2 additions & 3 deletions cds_dojson/to_marc21/models/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@

"""Album model."""

from dojson.contrib.to_marc21.model import Underdo

from ...overdo import Overdo
from ...overdo import Underdo
from .default import model as cds_to_marc21


class CDSToAlbum(Overdo, Underdo):
class CDSToAlbum(Underdo):
"""Translation Index for CDS Albums."""

__query__ = 'record_type.record_type:ALBUM'
Expand Down
5 changes: 2 additions & 3 deletions cds_dojson/to_marc21/models/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
"""CDS To MARC21 model."""

from dojson.contrib.to_marc21 import to_marc21
from dojson.contrib.to_marc21.model import Underdo

from ...overdo import Overdo
from ...overdo import Underdo


class CDSToMarc21(Overdo, Underdo):
class CDSToMarc21(Underdo):

"""Translation Index for CDS specific MARC21."""

Expand Down
6 changes: 2 additions & 4 deletions cds_dojson/to_marc21/models/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@

"""Image model."""

from dojson.contrib.to_marc21.model import Underdo

from ...overdo import Overdo
from ...overdo import Underdo
from .default import model as cds_to_marc21


class CDSToImage(Overdo, Underdo):
class CDSToImage(Underdo):
"""Translation Index for CDS Images."""

__query__ = 'record_type.record_type:IMAGE'
Expand Down
6 changes: 2 additions & 4 deletions cds_dojson/to_marc21/models/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@

"""Video model."""

from dojson.contrib.to_marc21.model import Underdo

from ...overdo import Overdo
from ...overdo import Underdo
from .default import model as cds_to_marc21


class CDSToVideo(Overdo, Underdo):
class CDSToVideo(Underdo):
"""Translation Index for CDS Videos."""

__query__ = 'collection.primary:PUBLVIDEOMOVIE'
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
tests_require = [
'check-manifest>=0.25',
'coverage>=4.0',
'invenio-jsonschemas>=1.0.0a2',
'isort>=4.2.2',
'mock>=1.0.0',
'pydocstyle>=1.0.0',
Expand Down
Loading

0 comments on commit d8f7b57

Please sign in to comment.