【发布时间】:2016-12-20 17:10:44
【问题描述】:
我正在为 Plone 4 中的 Dexterity 编写此代码,代码很简单,但是,它会导致一定的错误,下面我们看到代码,然后是错误的图像,我解释了我做了什么。
from plone.autoform import directives
from plone.namedfile import field as namedfile
from plone.supermodel import model
from z3c.form.browser.radio import RadioFieldWidget
from zope import schema
from zope.interface import invariant, Invalid
from zope.schema.vocabulary import SimpleVocabulary
from zope.schema.vocabulary import SimpleTerm
from datetime import datetime
from projetime.ged import _
VocabularyDocumentType = SimpleVocabulary(
[SimpleTerm(value=u'lawsuits', title=_(u'Lawsuits')),
SimpleTerm(value=u'contracts', title=_(u'Contracts')),
SimpleTerm(value=u'another', title=_(u'Another Docs'))]
)
def nowDateTime():
return datetime.today()
class IDigitalFile(model.Schema):
"""Dexterity-Schema
"""
directives.widget(documentType=RadioFieldWidget)
documentType = schema.Choice(
title=_(u"Document Type"),
vocabulary=VocabularyDocumentType,
required=True,
)
documentCod = schema.TextLine(
title=_(u"Document Cod."),
description=_(u"The Document Cod must be have xxxx/yyyy"),
required=False,
)
identification = schema.TextLine(
title=_(u"Identification"),
description=_(u"Enter your indetification"),
min_length = 11,
required=False,
)
subject = schema.TextLine(
title=_(u"Subject"),
required=True,
)
typeOf = schema.TextLine(
title=_(u"Type of Document"),
required=False,
)
file = namedfile.NamedBlobFile(
title=_(u"Digital Archive"),
required=True,
)
directives.mode(auto="hidden")
auto = schema.Bool(
title=_(u"Upload via Script?"),
required=True,
default=False,
)
@invariant
def DocumentTypeInvariant(data):
if data.documentType == 'lawsuits':
if not data.documentCod or not data.identification or not data.typeOf or not data.Description:
raise Invalid(_(u"You choose Lawsuits, all fields are required!"))
elif data.documentType == 'contracts':
if not data.documentCod or not data.identification or not data.Description:
raise Invalid(_(u"You choose Contracts, All fields with EXCEPTION of Type of Document are required"))
当我将在 Plone 中创建名为 DigitalFile 的对象时,我开始填写字段,当所有字段都填写完毕后,点击提交前出现此错误:
我该如何解决?
【问题讨论】:
标签: python schema plone dexterity plone-4.x