forked from jirikuncar/marc-json-schema
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdojson.tpl
61 lines (52 loc) · 1.77 KB
/
dojson.tpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -*- coding: utf-8 -*-
#
# This file is part of DoJSON
# Copyright (C) 2015 CERN.
#
# DoJSON is free software; you can redistribute it and/or
# modify it under the terms of the Revised BSD License; see LICENSE
# file for more details.
"""MARC 21 model definition."""
from dojson import utils
from ..model import marc21
{%- for tag, field in data if tag|length() == 3 %}
{%- if 'subfields' in field %}
{%- set indicator1 = get_indicator(1, field) %}
{%- set indicator2 = get_indicator(2, field) %}
@marc21.over('{{ clean_name(field.name) }}', '^{{ tag }}{{ indicator1['re'] }}{{ indicator2['re'] }}')
{%- if field.repeatable %}
@utils.for_each_value
{%- endif %}
@utils.filter_values
def {{ clean_name(field.name) }}(self, key, value):
"""{{ field.name }}."""
{%- if indicator1.get('name') %}
indicator_map1 = {{ tojson(indicator1.get('values', {})) }}
{%- endif %}
{%- if indicator2.get('name') %}
indicator_map2 = {{ tojson(indicator2.get('values', {})) }}
{%- endif %}
return {
{%- for code, subfield in field.get('subfields').iteritems() %}
{%- if subfield.get('repeatable', False) %}
'{{ clean_name(subfield['name']) }}': utils.force_list(
value.get('{{ code }}')
),
{%- else %}
'{{ clean_name(subfield['name']) }}': value.get('{{ code }}'),
{%- endif %}
{%- endfor %}
{%- if indicator1.get('name') %}
'{{ indicator1['name'] }}': indicator_map1.get(key[3]),
{%- endif %}
{%- if indicator2.get('name') %}
'{{ indicator2['name'] }}': indicator_map2.get(key[4]),
{%- endif %}
}
{%- else %}
@marc21.over('{{ clean_name(field.name) }}', '^{{ tag }}')
def {{ clean_name(field.name) }}(self, key, value):
"""{{ field.name }}."""
return value[0]
{%- endif %}
{%- endfor %}