2

Plone 4.1.2で、Dexterityを使用してmyContentTypeを作成しました。3つzope.schema.Choiceのフィールドがあります。それらのうちの2つは、ハードコードされた語彙から値を取得し、もう1つは動的な語彙から取得します。どちらの場合も、スペイン語のアクセントのある値を選択すると、追加フォームを保存すると、選択が失われ、ビューフォームに表示されません(エラーメッセージは表示されません)。しかし、アクセントのない値を選択すると、すべてが正常に機能します。

この問題を解決する方法について何かアドバイスはありますか?

(デイヴィッド;これがあなたが私に求めたものであることを願っています)

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

from five import grok
from zope import schema
from plone.directives import form, dexterity

from zope.component import getMultiAdapter
from plone.namedfile.interfaces import IImageScaleTraversable
from plone.namedfile.field import NamedBlobFile, NamedBlobImage

from plone.formwidget.contenttree import ObjPathSourceBinder
from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
from zope.schema.interfaces import IVocabularyFactory

from z3c.formwidget.query.interfaces import IQuerySource
from zope.component import queryUtility

from plone.formwidget.masterselect import (
    _,
    MasterSelectField,
    MasterSelectBoolField,
)

from plone.app.textfield.interfaces import ITransformer
from plone.indexer import indexer

from oaxaca.newcontent import ContentMessageFactory as _
from oaxaca.newcontent.config import OAXACA

from types import UnicodeType
_default_encoding = 'utf-8'

def _encode(s, encoding=_default_encoding):
    try:
        return s.encode(encoding)
    except (TypeError, UnicodeDecodeError, ValueError):
        return s

def _decode(s, encoding=_default_encoding):
    try:
        return unicode(s, encoding)
    except (TypeError, UnicodeDecodeError, ValueError):
        return s
        view = view.encode('utf-8')


def getSlaveVocab(master):
    results = []
    if master in OAXACA:
        results = sorted(OAXACA[master])
    return SimpleVocabulary.fromValues(results)


class IFicha(form.Schema, IImageScaleTraversable):
    """Describes a ficha
    """

    tipoMenu = schema.Choice(
            title=_(u"Tipo de evento"),
            description=_(u"Marque la opción que aplique o "
                           "seleccione otro si ninguna aplica"),
            values=(
                u'Manifestación en lugar público',
                u'Toma de instalaciones municipales',
                u'Toma de instalaciones estatales',
                u'Toma de instalaciones federales',
                u'Bloqueo de carretera municipal',
                u'Bloqueo de carretera estatal',
                u'Bloqueo de carretera federal',
                u'Secuestro de funcionario',
                u'Otro',),
            required=False,
        )

    tipoAdicional = schema.TextLine(
            title=_(u"Registre un nuevo tipo de evento"),
            description=_(u"Use este campo solo si marcó otro en el menú de arriba"),
            required=False
        )

    fecha = schema.Date(
            title=_(u"Fecha"),
            description=_(u"Seleccione el día en que ocurrió el evento"),
            required=False
        )

    municipio = MasterSelectField(
            title=_(u"Municipio"),
            description=_(u"Seleccione el municipio donde ocurrió el evento"),
            required=False,
            vocabulary="oaxaca.newcontent.municipios",
            slave_fields=(
                {'name': 'localidad',
                 'action': 'vocabulary',
                 'vocab_method': getSlaveVocab,
                 'control_param': 'master',
                },
            )
        )

    localidad = schema.Choice(
        title=_(u"Localidad"),
        description=_(u"Seleccione la localidad donde ocurrió el evento."),
        values=[u'',],
        required=False,
    )

    actores = schema.Text(
            title=_(u"Actores"),
            description=_(u"Liste las agrupaciones y los individuos que participaron en el evento"),
            required=False,
        )

    demandas = schema.Text(
            title=_(u"Demandas"),
            description=_(u"Liste las demandas o exigencias de los participantes"),
            required=False
        )

    depResponsable = schema.Text(
            title=_(u"Dependencias"),
            description=_(u"Liste las dependencias gubernamentales responsables de atender las demandas"),
            required=False
        )

    seguimiento = schema.Text(
            title=_(u"Acciones de seguimiento"),
            description=_(u"Anote cualquier accion de seguimiento que se haya realizado"),
            required=False
        )

    modulo = schema.Choice(
            title=_(u"Informa"),
            description=_(u"Seleccione el módulo que llena esta ficha"),
            values=(
                u'M1',
                u'M2',
                u'M3',
                u'M4',
                u'M5',
                u'M6',
                u'M7',
                u'M8',
                u'M9',
                u'M10',
                u'M11',
                u'M12',
                u'M13',
                u'M14',
                u'M15',
                u'M16',
                u'M17',
                u'M18',
                u'M19',
                u'M20',
                u'M21',
                u'M22',
                u'M23',
                u'M24',
                u'M25',
                u'M26',
                u'M27',
                u'M28',
                u'M29',
                u'M30',),
            required=False
        )

    imagen1 = NamedBlobImage(
            title=_(u"Imagen 1"),
            description=_(u"Subir imagen 1"),
            required=False
        )

    imagen2 = NamedBlobImage(
            title=_(u"Imagen 2"),
            description=_(u"Subir imagen 2"),
            required=False
        )

    anexo1 = NamedBlobFile(
            title=_(u"Anexo 1"),
            description=_(u"Subir archivo 1"),
            required=False
        )

    anexo2 = NamedBlobFile(
            title=_(u"Anexo 2"),
            description=_(u"Subir archivo 2"),
            required=False
        )


@indexer(IFicha)
def textIndexer(obj):
    """SearchableText contains fechaFicha, actores, demandas, municipio and localidad as plain text.
"""
    transformer = ITransformer(obj)
    text = transformer(obj.text, 'text/plain')
    return '%s %s %s %s %s' % (obj.fecha,
                            obj.actores,
                            obj.demandas,
                            obj.municipio,
                            obj.localidad)
grok.global_adapter(textIndexer, name='SearchableText')


class View(grok.View):
    """Default view (called "@@view"") for a ficha.
    The associated template is found in ficha_templates/view.pt.
    """

    grok.context(IFicha)
    grok.require('zope2.View')
    grok.name('view')
4

3 に答える 3

2

数ヶ月前、collective.nitfの初期の開発で同じ問題を発見しました。

語彙のトークンは正規化する必要があります。これが私がそれを解決した方法です:

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

import unicodedata

…

class SectionsVocabulary(object):
    """Creates a vocabulary with the sections stored in the registry; the
    vocabulary is normalized to allow the use of non-ascii characters.
    """
    grok.implements(IVocabularyFactory)

    def __call__(self, context):
        registry = getUtility(IRegistry)
        settings = registry.forInterface(INITFSettings)
        items = []
        for section in settings.sections:
            token = unicodedata.normalize('NFKD', section).encode('ascii', 'ignore').lower()
            items.append(SimpleVocabulary.createTerm(section, token, section))
        return SimpleVocabulary(items)

grok.global_utility(SectionsVocabulary, name=u'collective.nitf.Sections')
于 2012-01-24T07:00:40.767 に答える
0

Ploneはgettext国際化に使用します。防弾アプローチは、カスタム機能を英語で実装localesし、特定の言語で使用することです。これがどのように行われるかについては、コミュニティマニュアルの関連部分を参照してください。すでに設定しているので、MessageFactoryたとえばzettwerk.i18nduderのようなツールを使用して、メッセージ文字列をすばやく抽出することもできます。

于 2012-01-23T09:51:54.210 に答える
0

私はここで部分的な説明/解決策を見つけました。次の場合、ビューフォームでスペイン語の文字を取得できます。

---コーディング:utf- 8 ---

plone.directivesからのインポートフォーム5からのインポートgrokからzopeからのインポートスキーマplone.directivesからのインポートスキーマ、zope.schema.vocabularyからの器用さimport SimpleVocabulary

myVocabulary = SimpleVocabulary.fromItems(((u "Foo"、 "id_foó")、(u "Baroo"、 "id_baroó")))

クラスIPrueba(form.Schema):

tipoMenu = schema.Choice(
        title=_(u"Tipo de evento"),
        description=_(u"Marque la opción que aplique o "
                       "seleccione otro si ninguna aplica"),
        vocabulary=myVocabulary,
        required=False,
    )   
于 2012-01-24T05:46:46.283 に答える