- # use cached version if present
- if 'metadata' in request.session.keys():
- self._metadata = request.session['metadata']
- else:
- manifold_api_session_auth = request.session['manifold']['auth']
- manifold_api = ManifoldAPI(auth=manifold_api_session_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']
-
- results = manifold_api.Get('metadata:table', [], [], fields)
-
- for res in results:
- subject = res['table']
- self._metadata[subject] = res
-
- request.session['metadata'] = self._metadata
-
- javascript = "var MANIFOLD_METADATA =" + json.dumps(self._metadata) + ";"
- self.add_js_chunks(javascript)
-
- def metadata_get_fields(self, subject):
- return self._metadata[subject]['column'].sort()
-
+ manifold=session['manifold']
+ # if cached, use it
+ if 'metadata' in manifold and isinstance(manifold['metadata'],MetaData):
+ if debug: print "Page.get_metadata: return cached value"
+ return manifold['metadata']
+ # otherwise retrieve it
+ manifold_api_session_auth = session['manifold']['auth']
+ metadata=MetaData (manifold_api_session_auth)
+ metadata.fetch()
+ # store it for next time
+ manifold['metadata']=metadata
+ if debug: print "Page.get_metadata: return new value"
+ return metadata
+
+ def expose_js_metadata (self):
+ # export in this js global...
+ self.add_js_chunks("var MANIFOLD_METADATA =" + self.get_metadata().to_json() + ";")
+