我通过重写Schemata()方法来自定义Plone Archetypes内容类型以动态获取词汇内容:
def Schemata(self):
""" Overrides field definitions in fly.
"""
# XXX: Cache this method?
schemata = getSchemata(self).copy()
settings = self.getResearchSettings()
for row in settings.getFieldCustomizations():
name = row.get("fieldName", None)
vocab = row.get("vocabToUse", None)
field = schemata.get(name, None)
if field and vocab:
# Modify field copy ion
field.vocabulery = vocab
return schemata
我是否需要对Schemata()函数使用缓存装饰器,或者内部处理Schemata()的Archetypes如此智能,以便每次请求只调用一次?
Plone 4.0。
答案 0 :(得分:2)
答案 1 :(得分:0)
您肯定希望缓存Schema()和Schemata()的结果,因为在同一请求期间至少会多次调用Schema()。