4 from manifold.manifoldresult import ManifoldResult
5 from manifold.manifoldapi import ManifoldAPI
7 from django.contrib import messages
14 def __init__ (self, auth):
16 self.hash_by_object={}
18 def fetch (self, request):
19 manifold_api = ManifoldAPI(self.auth)
20 fields = ['table', 'column.name', 'column.qualifier', 'column.type',
21 'column.is_array', 'column.description', 'column.default', 'key', 'capability']
22 #fields = ['table', 'column.column',
23 # 'column.description','column.header', 'column.title',
24 # 'column.unit', 'column.info_type',
25 # 'column.resource_type', 'column.value_type',
26 # 'column.allowed_values', 'column.platforms.platform',
27 # 'column.platforms.platform_url']
28 request={ 'action': 'get',
29 'object': 'local:object', # proposed to replace metadata:table
32 result = manifold_api.forward(request)
34 # xxx need a way to export error messages to the UI
35 if result['code'] == 1: # warning
36 # messages.warning(request, result['description'])
37 print ("METADATA WARNING -",request,result['description'])
38 elif result['code'] == 2:
39 # messages.error(request, result['description'])
40 print ("METADATA ERROR -",request,result['description'])
44 rows = result.ok_value()
45 # API errors will be handled by the outer logic
47 # print "Failed to retrieve metadata",rows_result.error()
49 self.hash_by_object = dict ( [ (row['table'], row) for row in rows ] )
52 return json.dumps(self.hash_by_object)
54 def details_by_object (self, object):
55 return self.hash_by_object[object]
57 def sorted_fields_by_object (self, object):
58 return self.hash_by_object[object]['column'].sort()
60 def get_field_type(self, object, field):
61 if debug: print "Temp fix for metadata::get_field_type() -> consider moving to manifold.core.metadata soon"