Plone 4.1.4를 사용하고 있으며 스키마의 동적 소스를 가져 오려고합니다. 선택하려면 작동하도록 선택하고, 차례로 국가 목록을 채워야합니다. 컨텍스트 개체에 따라 다릅니다. IContextSourceBinder, 예를 들어, 빈 사전이 아닌 실제 상황에 맞는 객체의 경우 http://plone.org/products/dexterity/documentation/manual/developer-manual/advanced/vocabulariesz3c.forms 동적 소스 공급자가 컨텍스트 개체로 빈 사전을 반환합니다.
가 반환됩니다 :
나는이 예제를 사용하고
from zope import interface
from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
from zope.schema.interfaces import IContextSourceBinder
import zope.schema
from z3c.form import form
class CountryGenerator(object):
interface.implements(IContextSourceBinder)
def __call__(self, context):
#context is == {}
import pdb; pdb.set_trace()
return SimpleVocabulary([
SimpleTerm(value="not_selected", title=_("Country Not Selected"))
])
class IStep(interface.Interface):
region = schema.Choice(title=_("Select your country"),
required=True,
source=CountryGenerator,
default="not_selected")
class Step(form.Form):
fields = field.Fields(IStep)
label = _("Step")
description = _("Select your country")
점을 디버깅하는 것은 CountryGenerator .__ 전화 내부에 타격 __ () 메서드를 사용하고 컨텍스트 개체를 검사합니다. 후자는 빈 사전으로 판명됩니다.
위에서 언급 한 기사에서 명명 된 유틸리티 예제를 사용하려고하면 비슷한 일이 발생하지만 상황도 {}가 있습니다.
아무도 내가 잘못했을지도 모른다고 지적 할 수 있습니까? 양식을 호출하는 형태 랩퍼
UPDATE
ZCML는 허가 나 탐색 문제가 될 수 RegionClass 폼 래퍼에서 상속
<browser:page
name="view"
for="Products.oldproduct.MyFolderishClass"
class=".file.RegionClass"
permission="zope2.View"
/>
입니까? 소스 클래스이기 때문에
처음에는 그렇게하면 객체가 동시에 초기화되고 호출 될 것이라고 생각했지만 실제로 그렇지는 않습니다. 방금 같은 결과로 다시 시도했습니다. 컨텍스트는 여전히 빈 사전입니다. ChoiceTerms (컨텍스트, 요청, 양식, 필드, 위젯)를 정의하기 위해 스택으로 올라갔습니다. 적절한 요청 객체를 얻었지만 컨텍스트가 비어 있습니다. ZCML 슬러그에 문제가 될 수 있습니까? (내 업데이트 참조) –
폼에'__parent__' 포인터가 있습니까? –
예! 그것은 맥락이라고 생각되는 대상입니다. 어떻게 된거야? –