Skip to content

Commit

Permalink
Merge d6a7878 into 97565a9
Browse files Browse the repository at this point in the history
  • Loading branch information
drjova committed Oct 9, 2017
2 parents 97565a9 + d6a7878 commit 6984fa6
Show file tree
Hide file tree
Showing 13 changed files with 1,195 additions and 1,056 deletions.
11 changes: 7 additions & 4 deletions cds_dojson/marc21/fields/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,14 @@ def contributors(self, key, value):
"""Contributors."""
authors = self.get('contributors', [])
if key in ['100__', '700__']:
item = build_contributor(value)
items = build_contributor(value)
else:
item = build_contributor_from_508(value)
if item and item not in authors:
authors.append(item)
items = build_contributor_from_508(value)
# add only contributors that are not part of the authors
if items:
authors.extend(
[item for item in items if item and item not in authors]
)
return authors


Expand Down
33 changes: 26 additions & 7 deletions cds_dojson/marc21/fields/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,8 @@ def _extract_json_ids(info):
}
regex = re.compile('((AUTHOR\|\((CDS|INSPIRE)\))|(\(SzGeCERN\)))(.*)')
ids = []
for id_ in info.get('0', []):
match = regex.match(id_)
if not match:
pass
match = regex.match(info.get('0', ''))
if match:
ids.append({
'value': match.group(5),
'source': SOURCES[match.group(1)]
Expand All @@ -190,7 +188,17 @@ def _extract_json_ids(info):


def build_contributor(value):
"""Create a."""
"""Create a.
:returns: Contributors
:rtype: list
.. note::
In some cases contributor has a tuple of roles
(i.e. ('Producer', 'Director')) in such cases we return the contributor
as many times as the roles (2 in the example).
"""
OLD_VIDEO_TEAM_NAMES = {
'cern', 'cern ', 'cern / audiovisual service', 'cern ???',
'cern audio service', 'cern audio video service',
Expand All @@ -214,6 +222,7 @@ def build_contributor(value):
value = get_author_info_from_people_collection(value)

role = _get_correct_video_contributor_role(value.get('e', 'producer'))
contributors = []
contributor = {
'ids': _extract_json_ids(value) or None,
'name': value.get('name') or value.get('a'),
Expand All @@ -223,8 +232,18 @@ def build_contributor(value):
if contributor['name'].lower() in OLD_VIDEO_TEAM_NAMES:
contributor['name'] = 'CERN Video Productions'

contributor['role'] = role
return dict((k, v) for k, v in iteritems(contributor) if v is not None)
contributor = dict(
(k, v) for k, v in iteritems(contributor) if v is not None
)

if isinstance(role, tuple):
for _role in role:
contributor['role'] = _role
contributors.append(contributor)
else:
contributor['role'] = role
contributors.append(contributor)
return contributors


def build_contributor_from_508(value):
Expand Down
23 changes: 19 additions & 4 deletions cds_dojson/marc21/fields/videos/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,22 @@ def find_match(seq, copy):
return _physical_medium[0]
else:
for i in _physical_medium:
if seq and seq == i.get('sequence_number') \
if seq and seq in i.get('sequence_number') \
or copy and copy == i.get('copy_number'):
return i

_physical_medium.append({})
return _physical_medium[-1]

_physical_medium = self.get('physical_medium', [])
sequence_numbers = []
for value in force_list(value):
pm = find_match(value.get('8'), value.get('y'))
# Append ``_8`` and ``_9``
sequence_numbers.append(value.get('8'))
sequence_numbers.append(value.get('9'))
if key == '340__':
pm.update({
'sequence_number': value.get('8'),
'medium_standard': value.get('a'),
'note': value.get('j'),
'camera': value.get('d'),
Expand All @@ -91,15 +94,19 @@ def find_match(seq, copy):
})
elif key == '852__':
pm.update({
'sequence_number': value.get('8'),
'internal_note': value.get('9'),
'location': value.get('a'),
'shelf': value.get('b'),
'bar_code': value.get('c'),
'copy_number': value.get('t'),
'note': value.get('z'),
})

pm.update({
'sequence_number': [
sequence_number for sequence_number in set(sequence_numbers)
if sequence_number is not None
]
})
return [dict((k, v) for k, v in iteritems(i) if v is not None)
for i in _physical_medium]

Expand Down Expand Up @@ -280,3 +287,11 @@ def compute(value, context_type, media_type):
result['key'] = 'posterframe{0}'.format(ext)

return result


@model.over('audio_characteristics', '^344__')
def audio_characteristics(self, key, value):
"""Audio characteristics."""
return {
'playback_channels': value.get('g'),
}
1 change: 1 addition & 0 deletions cds_dojson/marc21/models/videos/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class CDSVideoProject(OverdoJSONSchema):
'961__x',
'980__a',
'980__b',
'981__a',
}


Expand Down
3 changes: 2 additions & 1 deletion cds_dojson/marc21/models/videos/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ class CDSVideo(OverdoJSONSchema):
'962__t',
'963__a',
'980__a',
'980__b'
'980__b',
'981__a',
}


Expand Down
Loading

0 comments on commit 6984fa6

Please sign in to comment.