I'm working on a content type that needs to select among different values on a field to display different vocabularies on some other using MasterSelectWidget:

slave_fields = (
    {'name': 'program',
     'action': 'vocabulary',
     'vocab_method': 'getProgramVocab',
     'control_param': 'master',
    },
    {'name': 'semester',
     'action': 'vocabulary',
     'vocab_method': 'getSemesterVocab',
     'control_param': 'master',
    },
    )

schema = BaseActivitySchema + atapi.Schema((

    atapi.StringField('level',
        default=LEVEL_BACHELOR,
        required=True,
        storage=atapi.AnnotationStorage(),
        widget=MasterSelectWidget(
            slave_fields=slave_fields,
            label=_(u'Level'),
            description=_(u'Select from the list.'),
            ),
vocabulary=[LEVEL_BACHELOR, LEVEL_SPECIALIZATION, LEVEL_MASTER, LEVEL_PHD],
            )),
        ),

    atapi.StringField('program',
        storage=atapi.AnnotationStorage(),
        widget=atapi.SelectionWidget(
            format='select',
            label=_(u'Programo'),
            description=_(u'Select from the list.'),
            ),
        ),

    atapi.StringField('semester',
        required=True,
        storage=atapi.AnnotationStorage(),
        widget=atapi.SelectionWidget(
            format='select',
            label=_(u'Semester'),
            description=_(u'Select from the list.'),
            ),
        ),

    ...

))

finalizeATCTSchema(schema, moveDiscussion=False)

class EducationalProgram(BaseActivity):
    implements(IEducationalProgram)

    security = ClassSecurityInfo()
    meta_type = 'EducationalProgram'
    schema = schema

    _at_rename_after_creation = True

    title = atapi.ATFieldProperty('title')
    description = atapi.ATFieldProperty('description')
    level = atapi.ATFieldProperty('level')
    program = atapi.ATFieldProperty('program')
    semester = atapi.ATFieldProperty('semester')
    ...

    security.declarePublic('getProgramVocab')

    def getProgramVocab(self, master):
        if master == LEVEL_BACHELOR:
            return vocabProgramBachelor
        elif master == LEVEL_SPECIALIZATION:
            return vocabProgramSpecializations

    security.declarePublic('getSemesterVocab')

    def getSemesterVocab(self, master):
        if master == LEVEL_BACHELOR:
            return vocabSemesterBachelor
        elif master == LEVEL_SPECIALIZATION:
            return vocabSemesterSpecialization
        elif master == LEVEL_MASTER:
            return vocabSemesterMaster
        elif master == LEVEL_PHD:
            return vocabSemesterPHD

    ...

atapi.registerType(EducationalProgram, PROJECTNAME)

the vocabularies are never called.

what I'm doing wrong?

also, why we don't use .copy() in the schema declaration?

best regards
--
Héctor Velarde

Attachment: smime.p7s
Description: Firma criptográfica S/MIME

_______________________________________________
Product-Developers mailing list
[email protected]
https://lists.plone.org/mailman/listinfo/plone-product-developers

Reply via email to