Python 链接z3c表单
我希望能够在Plone中一个接一个地链接几个z3c表单。例如,一旦表单#1完成处理并完成错误检查,它就会将结果(最好通过GET变量)传递到表单#2,表单#2反过来也会传递到表单#3等。。。我也希望能够使用相同的网址为所有的形式 我当前的实现是拥有一个浏览器视图,然后分派相应的表单,即DispatcherView检查self.request变量,然后确定调用表单1、表单2、表单3中的哪一个 我有这段代码,但似乎z3c表单被抽象为对BrowserView的几个调用,并试图触发从它到z3c的多个调用。表单会干扰对后者的处理。例如,当用户按一次“提交”按钮时,表单#1会进行错误检查,当我尝试下面示例中的解决方案时,表单#2返回,显示所有必需字段都不正确,这意味着表单#2从表单#1接收到值。我试图从不同的地方触发表单#2,比如DispatcherView(BrowserView)调用()方法,调用表单#1的()方法,也触发后者的update()和render(),但所有这些重写都会导致相同的问题 哪里是合适的位置来承载连续的呼叫,这样就可以工作,还是我需要创建单独的页面并使用self.request.RESPONSE.redicrt显式重定向到彼此Python 链接z3c表单,python,forms,plone,z3c.form,Python,Forms,Plone,Z3c.form,我希望能够在Plone中一个接一个地链接几个z3c表单。例如,一旦表单#1完成处理并完成错误检查,它就会将结果(最好通过GET变量)传递到表单#2,表单#2反过来也会传递到表单#3等。。。我也希望能够使用相同的网址为所有的形式 我当前的实现是拥有一个浏览器视图,然后分派相应的表单,即DispatcherView检查self.request变量,然后确定调用表单1、表单2、表单3中的哪一个 我有这段代码,但似乎z3c表单被抽象为对BrowserView的几个调用,并试图触发从它到z3c的多个调用。
from Products.Five import BrowserView
from zope import interface, schema
from z3c.form import form, field, group, button
from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
countries = SimpleVocabulary([SimpleTerm(value="not_selected", title=_("Chose your region")),
SimpleTerm(value="canada", title=_("Canada")),
SimpleTerm(value="us", title=_("United States")),
SimpleTerm(value="belgium", title=_("Belgium"))])
products = SimpleVocabulary([SimpleTerm(value="product1", title=_("Product1")),
SimpleTerm(value="product2", title=_("Product2")),
SimpleTerm(value="product3", title=_("Product2"))
])
class DispatcherView(BrowserView):
def __call__(self):
if 'form.widgets.region' in self.request.keys():
step2 = Step2(self.context, self.request)
return step2.__call__()
else:
step1 = Step1(self.context, self.request)
return step1.__call__()
def update(self):
pass
class IStep1(interface.Interface):
region = schema.Choice(title=_("Select your region"),
vocabulary=countries, required=True,
default="not_selected")
class IStep2(interface.Interface):
product = schema.Choice(title=_("Pick a product"),
vocabulary=products, required=True)
class Step1(form.Form):
fields = field.Fields(IStep1)
def __init__(self,context, request):
self.ignoreContext = True
super(self.__class__, self).__init__(context, request)
def update(self):
super(self.__class__, self).update()
@button.buttonAndHandler(u'Next >>')
def handleNext(self, action):
data, errors = self.extractData()
if errors:
print "Error occured"
class Step2(form.Form):
fields = field.Fields(IStep2)
def __init__(self,context, request):
self.ignoreContext = True
super(self.__class__, self).__init__(context, request)
def update(self):
super(self.__class__, self).update()
@button.buttonAndHandler(_('<< Previous'))
def handleBack(self, action):
data, errors = self.extractData()
if errors:
print "Error occured"
#handle input errors here
@button.buttonAndHandler(_('Next >>'))
def handleNext(self, action):
data, errors = self.extractData()
if errors:
print "Error occured"
也不要忘记浏览器:在configure.zcml中查看slug:
<browser:page
name="view"
for="Products.myproduct.DispatcherView"
class=".file.DispatcherView"
permission="zope2.View"
/>
我想你在找这个:
谢谢,这非常接近我的需要。一个简单的问题,是否可以保留会话,然后有一个自定义的最终页面,用户可以从该页面转到任何步骤并编辑它们,然后直接返回到最终页面?顺便问一下,是否可以有条件的步骤,或者我需要大量修改向导以添加此功能?
<browser:page
name="view"
for="Products.myproduct.DispatcherView"
class=".file.DispatcherView"
permission="zope2.View"
/>