如何修复 Python 敏捷类型中的 unicode 错误?

how I fix unicode error in Python Dexterity Type?

我使用 python 创建了一种敏捷类型,代码是:

# -*- coding: utf-8 -*-
from plone.app.textfield import RichText
from plone.autoform import directives
from plone.namedfile import field as namedfile
from plone.supermodel.directives import fieldset
from plone.supermodel import model
from z3c.form.browser.radio import RadioFieldWidget
from zope import schema
from zope.schema.vocabulary import SimpleVocabulary
from zope.schema.vocabulary import SimpleTerm
from DateTime import DateTime

from projetime.ged import MessageFactory as _

TipoDeDocumentoVocabulary = SimpleVocabulary(
    [SimpleTerm(value=u'processo', title=_(u'Processos')),
     SimpleTerm(value=u'contratos', title=_(u'Contratos')),
     SimpleTerm(value=u'outros', title=_(u'Outros'))]
)

TipoDeUploadVocabulary = SimpleVocabulary(
    [SimpleTerm(value=u'sim', title=_(u'Sim')),
     SimpleTerm(value=u'nao', title=_(u'Não'))]
)

agora = DateTime()

class IDigitalFile(model.Schema):
    """Dexterity-Schema
    """

    directives.widget(TipoDeDocumento=RadioFieldWidget)
    TipoDeDocumento = schema.Choice(
        title=_(u"Tipo de Documento"),
        vocabulary=TipoDeDocumentoVocabulary,
        required=True
    )

    titulo = schema.TextLine(
        title=_(u"Título"),
        required=True
    )

    codDoDocumento = schema.TextLine(
        title=_(u"Cód. do Documento"),
        required=False
    )

    CpfCnpj = schema.TextLine(
        title=_(u"CPF/CNPJ"),
        required=False
    )

    Assunto = schema.TextLine(
        title=_(u"Assunto"),
        required=True
        )

    Tipo = schema.TextLine(
        title=_(u"Tipo"),
        required=False
    )

    Descricao = schema.Text(
        title=_(u"Descrição"),
        required=True
    )

    fieldset('File', fields['Arquivo'] )
    Arquivo = namedfile.NamedBlobFile(
        title=_(u"Arquivo Digitalizado"),
        required=True
    )

    directives.omitted(['Automatico', 'uploded_at'])
    directives.read_permission(Automatico="cmf.ManagePortal")
    directives.write_permission(Automatico="cmf.ManagePortal")
    directives.widget(Automatico=RadioFieldWidget)
    Automatico = schema.Bool(
        Title=_(u"Upload via Script?"),
        vocabulary=TipoDeUploadVocabulary,
        required=True,
        default=u"Não"
    )

    directives.read_permission(uploded_at="cmf.ManagePortal")
    directives.write_permission(uploded_at="cmf.ManagePortal")
    uploded_at = schema.Datetime(
        title=_(u"Data de Upload"),
        required=True,
        default=agora
    )

错误是:

WrongType: (<zope.i18nmessageid.message.MessageFactory object at 0x7f118f168890>, <type 'unicode'>, 'title')

我在第一行设置:

# -*- coding: utf-8 -*-

但错误仍然存​​在。

解决方案是更改第 13 行:

from projetime.ged import MessageFactory as _

至:

from projetime.ged import _

点赞看这里https://github.com/plone/Products.CMFPlone/issues/386