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, auth):
18 self.hash_by_object={}
20 def fetch (self, request):
21 manifold_api = ManifoldAPI(self.auth)
22 fields = ['table', 'column.name', 'column.qualifier', 'column.type',
23 'column.is_array', 'column.description', 'column.default', 'key', 'capability']
24 #fields = ['table', 'column.column',
25 # 'column.description','column.header', 'column.title',
26 # 'column.unit', 'column.info_type',
27 # 'column.resource_type', 'column.value_type',
28 # 'column.allowed_values', 'column.platforms.platform',
29 # 'column.platforms.platform_url']
30 request={ 'action': 'get',
31 'object': 'local:object', # proposed to replace metadata:table
34 result = manifold_api.forward(request)
36 # xxx need a way to export error messages to the UI
37 if result['code'] == 1: # warning
38 # messages.warning(request, result['description'])
39 logger.warning(("METADATA WARNING - {} {}".format(request,result['description'])))
40 elif result['code'] == 2:
41 # messages.error(request, result['description'])
42 logger.error(("METADATA ERROR - {} {}".format(request,result['description'])))
46 rows = result.ok_value()
47 # API errors will be handled by the outer logic
49 # print "Failed to retrieve metadata",rows_result.error()
51 self.hash_by_object = dict ( [ (row['table'], row) for row in rows ] )
54 return json.dumps(self.hash_by_object)
56 def details_by_object (self, object):
57 return self.hash_by_object[object]
59 def sorted_fields_by_object (self, object):
60 return self.hash_by_object[object]['column'].sort()
62 def get_field_type(self, object, field):
64 logger.debug("Temp fix for metadata::get_field_type() -> consider moving to manifold.core.metadata soon")