本文整理汇总了Python中appy.fields.Field.getIndexValue方法的典型用法代码示例。如果您正苦于以下问题:Python Field.getIndexValue方法的具体用法?Python Field.getIndexValue怎么用?Python Field.getIndexValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类appy.fields.Field
的用法示例。
在下文中一共展示了Field.getIndexValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getIndexValue
# 需要导入模块: from appy.fields import Field [as 别名]
# 或者: from appy.fields.Field import getIndexValue [as 别名]
def getIndexValue(self, obj, forSearch=False):
'''For indexing purposes, we return only strings, not unicodes.'''
res = Field.getIndexValue(self, obj, forSearch)
if isinstance(res, unicode):
res = res.encode('utf-8')
if res and forSearch and (self.format == String.XHTML):
# Convert the value to simple text.
extractor = XhtmlTextExtractor(raiseOnError=False)
res = extractor.parse('<p>%s</p>' % res)
# Ugly catalog: if I give an empty tuple as index value, it keeps the
# previous value. If I give him a tuple containing an empty string, it
# is ok.
if isinstance(res, tuple) and not res: res = self.emptyStringTuple
# Ugly catalog: if value is an empty string or None, it keeps the
# previous index value.
if res in self.emptyValuesCatalogIgnored: res = ' '
return res
示例2: getIndexValue
# 需要导入模块: from appy.fields import Field [as 别名]
# 或者: from appy.fields.Field import getIndexValue [as 别名]
def getIndexValue(self, obj, forSearch=False):
'''Pure text must be extracted from rich content; multilingual content
must be concatenated.'''
isXhtml = self.format == String.XHTML
if self.isMultilingual(obj):
res = self.getValue(obj)
if res:
vals = []
for v in res.itervalues():
if isinstance(v, unicode): v = v.encode('utf-8')
if isXhtml: vals.append(self.extractText(v))
else: vals.append(v)
res = ' '.join(vals)
else:
res = Field.getIndexValue(self, obj, forSearch)
if res and isXhtml: res = self.extractText(res)
# Ugly catalog: if I give an empty tuple as index value, it keeps the
# previous value. If I give him a tuple containing an empty string, it
# is ok.
if isinstance(res, tuple) and not res: res = self.emptyStringTuple
# Ugly catalog: if value is an empty string or None, it keeps the
# previous index value.
if res in self.emptyValuesCatalogIgnored: res = ' '
return res