Skip to content

Commit fa1877e

Browse files
committed
Merge pull request #102 from OpenDataServices/100-template-titles
Some fixes for the titles template
2 parents dceac82 + b9b7e00 commit fa1877e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

flattentool/schema.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ def parse(self):
9999
else:
100100
self.main_sheet.append(field)
101101

102-
def parse_schema_dict(self, parent_path, schema_dict, parent_id_fields=None, title_lookup=None):
102+
def parse_schema_dict(self, parent_path, schema_dict, parent_id_fields=None, title_lookup=None, parent_title=''):
103103
if parent_path:
104104
parent_path = parent_path + '/'
105105
parent_id_fields = parent_id_fields or []
106106
title_lookup = self.title_lookup if title_lookup is None else title_lookup
107107
if 'properties' in schema_dict:
108108
if 'id' in schema_dict['properties']:
109109
if self.use_titles:
110-
id_fields = parent_id_fields + [parent_path+(schema_dict['properties']['id'].get('title') or 'id')]
110+
id_fields = parent_id_fields + [(parent_title if parent_title is not None else parent_path)+(schema_dict['properties']['id'].get('title') or 'id')]
111111
else:
112112
id_fields = parent_id_fields + [parent_path+'id']
113113
else:
@@ -127,7 +127,8 @@ def parse_schema_dict(self, parent_path, schema_dict, parent_id_fields=None, tit
127127
parent_path+property_name,
128128
property_schema_dict,
129129
parent_id_fields=id_fields,
130-
title_lookup=title_lookup.get(title)):
130+
title_lookup=title_lookup.get(title),
131+
parent_title=parent_title+title+':' if title else None):
131132
yield (
132133
property_name+'/'+field,
133134
# TODO ambiguous use of "title"
@@ -165,7 +166,8 @@ def parse_schema_dict(self, parent_path, schema_dict, parent_id_fields=None, tit
165166
parent_path+property_name+'/0',
166167
property_schema_dict['items'],
167168
parent_id_fields=id_fields,
168-
title_lookup=title_lookup.get(title))
169+
title_lookup=title_lookup.get(title),
170+
parent_title=parent_title+title+':' if title else None)
169171

170172
rolledUp = set()
171173

@@ -177,8 +179,7 @@ def parse_schema_dict(self, parent_path, schema_dict, parent_id_fields=None, tit
177179
warn('Field {} does not have a title, skipping it and all its children.'.format(property_name))
178180
else:
179181
# This code only works for arrays that are at 0 or 1 layer of nesting
180-
assert len(parent_path.replace('/0/', '/').split('/')) <= 2
181-
sub_sheet.add_field(title+':'+child_title)
182+
sub_sheet.add_field(parent_title+title+':'+child_title)
182183
else:
183184
sub_sheet.add_field(parent_path+property_name+'/0/'+field)
184185
if self.rollup and 'rollUp' in property_schema_dict and field in property_schema_dict['rollUp']:

0 commit comments

Comments
 (0)