我需要在archetypes.querywidget上修复它,它的buildout不是创建bin/test脚本.
我应该使用buildout.coredev吗?我需要更改它的结帐才能运行测试吗?
对于Dexterity内容类型,规范的方法是使用变换器:
from plone.app.textfield.interfaces import ITransformer
from plone.app.textfield.value import IRichTextValue
def get_text_field(obj):
"""Get text field in object on Dexterity."""
transformer = ITransformer(obj)
text = ''
if IRichTextValue.providedBy(obj.text): # Dexterity
text = transformer(obj.text, 'text/plain')
return text
Run Code Online (Sandbox Code Playgroud)
但是我找不到规范的方法来做Archetypes,变换器不能用rawhtml,只是用RichTextValue对象.
我现在的方法是使用lxml.html将html转换为文本,但我不知道它是否像它应该的那样工作:
def get_text_field(obj):
"""Get text field in object on both, Archetypes and Dexterity."""
text = ''
try:
raw = obj.getText() # Archetypes
if raw != '':
from lxml import html
el = html.fromstring(raw)
text = …Run Code Online (Sandbox Code Playgroud) 我知道可以使用GenericSetup和一个XML文件注册浏览器层,但我需要以编程方式进行注册.
这可能吗?