X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=manifold%2Fmetadata.py;h=08fdf61dea73339adf7149723d754df0503c9fbc;hb=d1197c134b70bda643a752bdaf891190cb5a15e7;hp=59d600b17dd42e4f485891eff3ea5b1a31a07edd;hpb=014edeca57deed3141dda9056949e537f55fdf25;p=myslice.git diff --git a/manifold/metadata.py b/manifold/metadata.py index 59d600b1..08fdf61d 100644 --- a/manifold/metadata.py +++ b/manifold/metadata.py @@ -1,8 +1,11 @@ import json +import os.path from manifold.manifoldresult import ManifoldResult from manifold.manifoldapi import ManifoldAPI +from django.contrib import messages + debug=False debug=True @@ -16,8 +19,8 @@ class MetaData: self.auth=auth self.hash_by_object={} - def fetch (self): - offline_filename="offline-metadata.json" + def fetch (self, request): + offline_filename="%s/../offline-metadata.json"%os.path.dirname(__file__) if work_offline: try: with file(offline_metadata) as f: @@ -26,17 +29,31 @@ class MetaData: except: print "metadata.work_offline: failed to decode %s"%offline_filename manifold_api = ManifoldAPI(self.auth) - fields = ['table', 'column.column', - 'column.description','column.header', 'column.title', - 'column.unit', 'column.info_type', - 'column.resource_type', 'column.value_type', - 'column.allowed_values', 'column.platforms.platform', - 'column.platforms.platform_url'] - rows_result = manifold_api.Get({ - 'object': 'local:object', # proposed to replace metadata:table - 'fields': fields - }) - rows = rows_result.ok_value() + fields = ['table', 'column.name', 'column.qualifier', 'column.type', + 'column.is_array', 'column.description', 'column.default', 'key', 'capability'] + #fields = ['table', 'column.column', + # 'column.description','column.header', 'column.title', + # 'column.unit', 'column.info_type', + # 'column.resource_type', 'column.value_type', + # 'column.allowed_values', 'column.platforms.platform', + # 'column.platforms.platform_url'] + request={ 'action': 'get', + 'object': 'local:object', # proposed to replace metadata:table + 'fields': fields , + } + result = manifold_api.forward(request) + + # xxx need a way to export error messages to the UI + if result['code'] == 1: # warning + # messages.warning(request, result['description']) + print ("METADATA WARNING -",request,result['description']) + elif result['code'] == 2: + # messages.error(request, result['description']) + print ("METADATA ERROR -",request,result['description']) + # XXX FAIL HERE XXX + return + + rows = result.ok_value() # API errors will be handled by the outer logic # if not rows: # print "Failed to retrieve metadata",rows_result.error() @@ -54,4 +71,8 @@ class MetaData: return self.hash_by_object[object] def sorted_fields_by_object (self, object): - return self.hash_by_object[object]['columns'].sort() + return self.hash_by_object[object]['column'].sort() + + def get_field_type(self, object, field): + print "Temp fix for metadata::get_field_type() -> consider moving to manifold.core.metadata soon" + return field