X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=manifold%2Fmetadata.py;h=04f8511f12aa6d08141a656b4faee717a39ef374;hb=96cf681a06ae76e67bb186e5bc02a696a9784c3d;hp=eb0e48a4c80dcd800c3e653623eb74a762e4b0c1;hpb=f14a5114d0cf6673c172bdb89669fa80efcd3f2b;p=myslice.git diff --git a/manifold/metadata.py b/manifold/metadata.py index eb0e48a4..04f8511f 100644 --- a/manifold/metadata.py +++ b/manifold/metadata.py @@ -14,17 +14,14 @@ class MetaData: def __init__ (self, auth): self.auth=auth - self.hash_by_subject={} - - # XXX Retrieve all metadata the first time we instanciate the class - self.fetch() + self.hash_by_object={} def fetch (self): offline_filename="offline-metadata.json" if work_offline: try: with file(offline_metadata) as f: - self.hash_by_subject=json.loads(f.read()) + self.hash_by_object=json.loads(f.read()) return except: print "metadata.work_offline: failed to decode %s"%offline_filename @@ -35,26 +32,37 @@ class MetaData: 'column.resource_type', 'column.value_type', 'column.allowed_values', 'column.platforms.platform', 'column.platforms.platform_url'] - rows_result = manifold_api.Get({ - 'fact_table': 'local:objects', # proposed to replace metadata:table + result = manifold_api.Get({ + 'object': 'local:object', # proposed to replace metadata:table 'fields': fields }) -#old# rows_result = manifold_api.Get('metadata:table', [], [], fields) - rows = rows_result.ok_value() - if not rows: - print "Failed to retrieve metadata",rows_result.error() - rows=[] - self.hash_by_subject = dict ( [ (row['table'], row) for row in rows ] ) + + if result['code'] == 1: # warning + messages.warning(request, result['description']) + elif result['code'] == 2: + messages.error(request, result['description']) + # XXX FAIL HERE XXX + + rows = result.ok_value() +# API errors will be handled by the outer logic +# if not rows: +# print "Failed to retrieve metadata",rows_result.error() +# rows=[] + self.hash_by_object = dict ( [ (row['table'], row) for row in rows ] ) # save for next time we use offline mode - if debug: + if debug and rows: with file(offline_filename,'w') as f: - f.write(json.dumps(self.hash_by_subject)) + f.write(json.dumps(self.hash_by_object)) def to_json(self): - return json.dumps(self.hash_by_subject) + return json.dumps(self.hash_by_object) + + def details_by_object (self, object): + return self.hash_by_object[object] - def details_by_subject (self, subject): - return self.hash_by_subject[subject] + def sorted_fields_by_object (self, object): + return self.hash_by_object[object]['column'].sort() - def sorted_fields_by_subject (self, subject): - return self.hash_by_subject[subject]['columns'].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