4 from manifoldresult import ManifoldResult
5 from manifoldapi import ManifoldAPI
7 from django.contrib import messages
9 from myslice.settings import logger
16 def __init__ (self, url, auth):
19 self.hash_by_object={}
21 def fetch (self, request):
22 manifold_api = ManifoldAPI(self.url, self.auth)
23 fields = ['table', 'column.name', 'column.qualifier', 'column.type',
24 'column.is_array', 'column.description', 'column.default', 'key', 'capability']
25 #fields = ['table', 'column.column',
26 # 'column.description','column.header', 'column.title',
27 # 'column.unit', 'column.info_type',
28 # 'column.resource_type', 'column.value_type',
29 # 'column.allowed_values', 'column.platforms.platform',
30 # 'column.platforms.platform_url']
31 request={ 'action': 'get',
32 'object': 'local:object', # proposed to replace metadata:table
35 result = manifold_api.forward(request)
37 # xxx need a way to export error messages to the UI
38 if result['code'] == 1: # warning
39 # messages.warning(request, result['description'])
40 logger.warning(("METADATA WARNING - {} {}".format(request,result['description'])))
41 elif result['code'] == 2:
42 # messages.error(request, result['description'])
43 logger.error(("METADATA ERROR - {} {}".format(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 ] )
55 return json.dumps(self.hash_by_object)
57 def details_by_object (self, object):
58 return self.hash_by_object[object]
60 def sorted_fields_by_object (self, object):
61 return self.hash_by_object[object]['column'].sort()
63 def get_field_type(self, object, field):
65 logger.debug("Temp fix for metadata::get_field_type() -> consider moving to manifold.core.metadata soon")