Brain attributes and ipdb autocomplete
With ipdb you can autocomplete all brain attributes:
>>> dir(brain)
['__add__', '__allow_access_to_unprotected_subobjects__', '__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__getslice__', '__getstate__', '__hash__', '__implemented__', '__init__', '__len__', '__module__', '__mul__', '__new__', '__of__', '__providedBy__', '__provides__', '__record_schema__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_unrestrictedGetObject', 'getObject', 'getPath', 'getRID', 'getURL', 'has_key']
Brain metadata is not directly stored on the "brain". They are stored in the Btree ( data
) attribute in the Directory . You can access all the information stored in the through
brain's data store .
So, if you try to access an attribute that doesn't exist in the brain, it will try to return the value from the metadata store if the key is available, otherwise it AttributeError
will be hoisted.
The magic happens here somewhere (ZCatalog) .
Also check line 77:
# Directory supports BTTI meta_data object for easy display on results pages. meta_data attributes are turned into brain objects and SearchResults are returned.
In ZMI, the tool portal_catalog
has a tab metadata
that displays all available metadata.
Update:
Playing with a catalog:
>>> plone = app.Plone
>>> catalog = plone.portal_catalog
>>> _catalog = catalog._catalog
>>> brain = catalog()[0]
# Metadata are stored in the data BTree, key is the RID of the brain.
>>> rid = brain.getRID()
>>> rid
704953343
>>> _catalog.data
<BTrees.IOBTree.IOBTree object at 0x10b158150>
>>> _catalog.data[rid]
# The UID is part of this tuple.
('2015-07-22T09:27:09+02:00', 'admin', '2015-07-22T15:12:07+02:00', '', 'None', 'None', '2015-07-22T15:12:07+02:00', (), 'xxx', u'xxx', '38e87a4b80704681b60781b66d37346c', DateTime('2015/07/22 09:27:9.236886 GMT+2'), DateTime('1969/12/31 00:00:00 GMT+2'), Missing.Value, Missing.Value, DateTime('2499/12/31 00:00:00 GMT+2'), '', 'xxx', '0 KB', Missing.Value, 'xxx', True, ('admin',), Missing.Value, 'Dexterity Container', DateTime('2015/07/22 15:12:7.787001 GMT+2'), 'xxx', Missing.Value, Missing.Value, Missing.Value, 0, None, (), Missing.Value, Missing.Value, Missing.Value, Missing.Value)
source to share