本文整理汇总了Python中org.bccvl.site.interfaces.IBCCVLMetadata.setdefault方法的典型用法代码示例。如果您正苦于以下问题:Python IBCCVLMetadata.setdefault方法的具体用法?Python IBCCVLMetadata.setdefault怎么用?Python IBCCVLMetadata.setdefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bccvl.site.interfaces.IBCCVLMetadata
的用法示例。
在下文中一共展示了IBCCVLMetadata.setdefault方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DatasetMetadataAdapter
# 需要导入模块: from org.bccvl.site.interfaces import IBCCVLMetadata [as 别名]
# 或者: from org.bccvl.site.interfaces.IBCCVLMetadata import setdefault [as 别名]
class DatasetMetadataAdapter(object):
"""
Gives z3c.form datamanagers attribute access to the metadata object.
This class takes care of properly updateing the underlying storage object.
"""
# There is a datamanager problem.
# The Datamanager is looked up for the context (which returns an AttributeField manager)
# but then the Datamanager adapts the context to this adapter and tries attribute
# access which fails.
def __init__(self, context):
self._data = IBCCVLMetadata(context)
def __getattr__(self, name):
ob = self._data
try:
if name in ('scientificName', 'taxonID', 'vernacularName'):
return ob['species'][name]
else:
return ob[name]
except:
raise AttributeError('Attribute %s not found' % name)
def __setattr__(self, name, value):
if name == '_data':
self.__dict__['_data'] = value
# shortcut here to not store _data in metadata dictionary
return
if name in ('scientificName', 'taxonID', 'vernacularName'):
# FIXME: need a new dict here?
ob = self._data.setdefault('species', {})
else:
ob = self._data
ob[name] = value
def __delattr__(self, name):
if name in ('scientificName', 'taxonID', 'vernacularName'):
# FIXME: update dict?
ob = self._data['species']
del ob[name]
if not ob:
del self._data['species']
else:
del self._data[name]