3 from manifold.manifoldresult import ManifoldResult
4 from manifold.manifoldapi import ManifoldAPI
9 # turn this on if you want to work offline
15 def __init__ (self, auth):
17 self.hash_by_object={}
20 offline_filename="offline-metadata.json"
23 with file(offline_metadata) as f:
24 self.hash_by_object=json.loads(f.read())
27 print "metadata.work_offline: failed to decode %s"%offline_filename
28 manifold_api = ManifoldAPI(self.auth)
29 fields = ['table', 'column.name', 'column.qualifier', 'column.type', 'column.is_array', 'column.description', 'column.default', 'key', 'capability']
30 #fields = ['table', 'column.column',
31 # 'column.description','column.header', 'column.title',
32 # 'column.unit', 'column.info_type',
33 # 'column.resource_type', 'column.value_type',
34 # 'column.allowed_values', 'column.platforms.platform',
35 # 'column.platforms.platform_url']
36 result = manifold_api.Get({
37 'object': 'local:object', # proposed to replace metadata:table
41 if result['code'] == 1: # warning
42 messages.warning(request, result['description'])
43 elif result['code'] == 2:
44 messages.error(request, result['description'])
47 rows = result.ok_value()
48 # API errors will be handled by the outer logic
50 # print "Failed to retrieve metadata",rows_result.error()
52 self.hash_by_object = dict ( [ (row['table'], row) for row in rows ] )
53 # save for next time we use offline mode
55 with file(offline_filename,'w') as f:
56 f.write(json.dumps(self.hash_by_object))
59 return json.dumps(self.hash_by_object)
61 def details_by_object (self, object):
62 return self.hash_by_object[object]
64 def sorted_fields_by_object (self, object):
65 return self.hash_by_object[object]['column'].sort()
67 def get_field_type(self, object, field):
68 print "Temp fix for metadata::get_field_type() -> consider moving to manifold.core.metadata soon"