我正在尝试制作一个在上下文之外存储值的表单。存储已完成并且运行良好,但现在我希望更新方法在渲染过程中填充表单。所以我以这种方式重写 Form 类的更新方法:
def update(self):
super(ConfigurationForm,self).update()
form = self.request.form
if not form:
#We are on a rendering process
provider = self.getProvider()
settings = provider.get()
#TODO: update widget values !?
Run Code Online (Sandbox Code Playgroud)
settings 是一个字典,其中键等于接口字段的名称。
所以我尝试了很多方法来更新小部件值:
实现这一目标的好方法是什么?(支持所有领域?)
我编写了自己的PyramidISession 接口实现,它将会话存储在数据库中。一切都工作得很好,但不知怎的却pyramid_tm出现了问题。一旦激活它就会这样说:
DetachedInstanceError: Instance <Session at 0x38036d0> is not bound to a Session;
attribute refresh operation cannot proceed
Run Code Online (Sandbox Code Playgroud)
(这里不要混淆:这<Session ...>是模型的类名,“... to a Session”很可能指的是 SQLAlchemy 的 Session(我称之为DBSession以避免混淆)。
我查看了邮件列表,似乎每当有人遇到问题时,他们都会
transaction.commit()这两件事我都不做。然而,这里的特点是,我的会话经常被金字塔传递。首先我这样做DBSession.add(session),然后return session。之后我可以处理会话、闪现新消息等。
但是,似乎一旦请求完成,我就会收到此异常。这是完整的回溯:
Traceback (most recent call last):
File "/home/javex/data/Arbeit/libraries/python/web_projects/pyramid/lib/python2.7/site-packages/waitress-0.8.1-py2.7.egg/waitress/channel.py", line 329, in service
task.service()
File "/home/javex/data/Arbeit/libraries/python/web_projects/pyramid/lib/python2.7/site-packages/waitress-0.8.1-py2.7.egg/waitress/task.py", line 173, in service
self.execute()
File "/home/javex/data/Arbeit/libraries/python/web_projects/pyramid/lib/python2.7/site-packages/waitress-0.8.1-py2.7.egg/waitress/task.py", line 380, in execute
app_iter = self.channel.server.application(env, start_response)
File "/home/javex/data/Arbeit/libraries/python/web_projects/pyramid/lib/python2.7/site-packages/pyramid/router.py", line 251, in __call__ …Run Code Online (Sandbox Code Playgroud) 我有一个金字塔应用程序,它有这条线
from zope.sqlalchemy import ZopeTransactionExtension
Run Code Online (Sandbox Code Playgroud)
它可以正常工作
但是,如果我用命令行尝试相同的方法,我会得到
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named sqlalchemy
Run Code Online (Sandbox Code Playgroud)
和
from zope.sqlalchemy.datamanager import ZopeTransactionExtension
ImportError: No module named sqlalchemy.datamanager
Run Code Online (Sandbox Code Playgroud)
我不确定为什么会这样。文档有相同的行,似乎至少对他们有用
我正在尝试检查 Plone Products.PythonScript 中变量的类型。我尝试了这段代码:
if isinstance(var, list):
do(sth)
Run Code Online (Sandbox Code Playgroud)
不幸的是,“list”和“type”在 PythonScript 中受到限制。我收到这个错误:
TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types
Run Code Online (Sandbox Code Playgroud)
是否有可能检查我的变量的类型?
我打算做一些大型项目(1 000 000用户,大约500请求前秒 - 在炎热时间).为了性能,我将不使用关系dbms(每个请求可能会花费很多关于dbms的关系dbms中的指令) - 所以我不能使用DAL.
我的问题是:
你能告诉我一下吗?
我注意到Twisted依赖于Zope.我发现当我尝试安装Zope时,运行后,./ configure它告诉我我需要使用python2.4(而不是我希望使用的python 2.5+).
但是,我已经看到一些教程和指南建议使用python 2.5 for Twisted.所以我一般都很困惑.有没有人设置这个并运行一些使用zope的twsited web示例?你用的是什么版本的python?你有什么安装指南吗?
我使用以下PLone + urllib代码通过BrowserView代理来自其他服务器的响应
req = urllib2.Request(full_url)
try:
# Important or if the remote server is slow
# all our web server threads get stuck here
# But this is UGLY as Python does not provide per-thread
# or per-socket timeouts thru urllib
orignal_timeout = socket.getdefaulttimeout()
try:
socket.setdefaulttimeout(10)
response = urllib2.urlopen(req)
finally:
# restore orignal timeoout
socket.setdefaulttimeout(orignal_timeout)
# XXX: How to stream respone through Zope
# AFAIK - we cannot do it currently
return response.read()
Run Code Online (Sandbox Code Playgroud)
我的问题是,当第一个字节到达时,我怎么能使这个功能不阻止并立即开始通过Zope流式传输代理响应?当接口,对象或模式用于制作流式Zope响应时?
有这个代码:
>>> class Foo:
... zope.interface.implements(IFoo)
...
... def __init__(self, x=None):
... self.x = x
...
... def bar(self, q, r=None):
... return q, r, self.x
...
... def __repr__(self):
... return "Foo(%s)" % self.x
Run Code Online (Sandbox Code Playgroud)
Obviously, the call of zope.interface.implements in some way alters the properties and behavior of the class Foo.
How does this happen? How do I use this approach in my code?
Example code is the part of zope.interface module.
我将Plone安装升级到4.2.5有些困难.
旧的Plone/zope安装在Ubuntu 8.04上运行.我将操作系统升级到12.04,并重新安装了plone和zope.
我按照http://plone.org/documentation/manual/upgrade-guide/minor-version-upgrades上的说明 进行升级.
12.04安装成功,当我将旧配置和数据复制到新安装中时出现问题.
当我在复制后运行bin/buildout时,我收到消息:
错误:Buildout现在包含'buildout-versions'(以及旧版'buildout.dumppickedversions'的一部分).从配置中删除扩展,并查看buildout文档中的"show-picked-versions"选项.
我尝试删除扩展,这允许bin/buildout完成而不会出错,但是当我启动zope时,我收到以下错误:
文件"/home/plone/Plone/buildout-cache/eggs/ZODB3-3.10.5-py2.7-linux-x86_64.egg/persistent/ 初始化 py"为19行,从cPersistence进口持续,GHOST,UPTODATE ,CHANGED,STICKY ImportError:/home/plone/Plone/buildout-cache/eggs/ZODB3-3.10.5-py2.7-linux-x86_64.egg/persistent/cPersistence.so: undefined symbol:PyUnicodeUCS2_AsEncodedString