简体   繁体   English

如何解决架构中的敏捷Plone 4错误?

[英]How I Fix in Dexterity Plone 4 error in Schema?

I'm writing this code for Dexterity in Plone 4, the code is simple, however, it causes a certain error, below we see the code and then an image of the error, there I explain what I did. 我在Plone 4中为敏捷编写了此代码,该代码很简单,但是,它会导致一定的错误,下面我们看到该代码,然后是该错误的图像,在此我说明了自己的所作所为。

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"))

When I will create in Plone the object called DigitalFile, I start to fill in the fields, when all fields are filled, I have this error before clicking submit: 当我将在Plone中创建名为DigitalFile的对象时,我开始填写字段,当所有字段都填写完毕后,在单击提交之前出现此错误:

DocumentTypeInvariantModule中的模块projetime.ged.content.digitalfile,第87行; __getattr__;中的z3c.form.validator,第164行; AttributeError:说明

How I fix it? 我该如何解决?

The invariant is defined in the schema and the Description Field is not in this schema, thus you cannot access it in the invariant. invariant是在schema定义的,“ Description字段” 不在此模式中,因此您无法在不变式中访问它。

You need something that take in account, that the Description field is defined in a different schema. 您需要考虑一些因素,即“描述”字段是在其他架构中定义的。

You can solve your problem with a Form validator : http://docs.plone.org/develop/addons/schema-driven-forms/customising-form-behaviour/validation.html#validating-in-action-handlers 您可以使用Form validator解决问题: http : //docs.plone.org/develop/addons/schema-driven-forms/customising-form-b​​ehaviour/validation.html#validating-in-action-handlers

For this you need to register a custom edit/add form: Check: http://docs.plone.org/external/plone.app.dexterity/docs/advanced/custom-add-and-edit-forms.html 为此,您需要注册一个自定义的编辑/添加表单:检查: http : //docs.plone.org/external/plone.app.dexterity/docs/advanced/custom-add-and-edit-forms.html

This is all very well documented, for plone 4 and plone 5. 对于针座4和针座5,所有这些都有很好的记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM