z3c.Forms 동적 소스 공급자는 빈 사전을 컨텍스트 객체로 반환합니다.
문제
나는 좌석 4.1.4를 사용하고 있고, 나는 스키마에 대한 동적 소스를 얻으려고 노력하고있다. 쇼핑을 위해서는, 차례로 컨텍스트 객체에 의존하는 국가 목록을 채워야한다.
이 예제를 사용하고 있습니다. http://plone.org/products/dexterity/documentation/manual. / 개발자 - 수동 / 고급 / 어휘
icontextsourceBinder의 경우 실제 컨텍스트 개체 대신 빈 사전이 반환됩니다.
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")
.
디버깅 포인트가 컨텐트 생성자 안에 닿을 때 __ () 메서드를 묶고 컨텍스트 객체를 검사하고, 후자는 단지 빈 사전으로 바뀝니다.
위에서 언급 한 기사에서 명명 된 유틸리티 예제를 사용하려고하면 비슷한 일이 발생하면 {}도 있습니다.
누구든지 내가 뭘 잘못 할지를 지적 할 수 있습니까?
업데이트
폼을 호출하는 폼 래퍼에 대한 zcml은 입니다.
.
<browser:page
name="view"
for="Products.oldproduct.MyFolderishClass"
class=".file.RegionClass"
permission="zope2.View"
/>
래핑 래퍼는 래퍼를 상속하는 경우, 허가 또는 탐색 문제가 될 수 있습니까?
해결책
소스가 클래스이므로 인스턴스화해야합니다.
class IStep(interface.Interface):
region = schema.Choice(title=_("Select your country"),
required=True,
source=CountryGenerator(),
default="not_selected")
.
서브 양식 또는 복합 양식 위젯 (목록 선택을위한 위젯 내의 위젯)을 사용하는 것과 같은 특정 상황에서는 PLONE 컨텍스트로 돌아가는 적절한 외부 컨텍스트로 __parent__
포인터를 따라야합니다.