[Product-Developers] MasterSelectWidget and slave_fields vocabularies

Héctor Velarde hector.velarde at gmail.com
Fri Jul 8 18:25:40 UTC 2011


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4024 bytes
Desc: Firma criptogr??fica S/MIME
URL: <http://lists.plone.org/pipermail/plone-product-developers/attachments/20110708/c31c81df/attachment.p7s>


More information about the Product-Developers mailing list