Il 13/11/2013 08:57, Luca Fabbri ha scritto:
On Tue, Nov 12, 2013 at 1:45 PM, Natale Tarantino
<ntarant...@regione.sicilia.it> wrote:


Il 12/11/2013 13:36, Luca Fabbri ha scritto:

On Tue, Nov 12, 2013 at 1:03 PM, Natale Tarantino
<ntarant...@regione.sicilia.it> wrote:

Ciao,
sto scrivendo un  prodotto, basato su Archetypes, e vorrei usare la 
MasterSelectWidget con Plone 4.2.4
Premesso che la demo della widget funziona posto il codice:

slave_fields2 = (
     #Controls the vocabulary of subcategory
     {'name': 'subcategory',
      'action': 'vocabulary',
      'vocab_method':'subcategoryVocab',
      'control_param':'master',
     },
)

ATTicketSchema = folder.ATFolderSchema.copy() + atapi.Schema((
.....
     atapi.StringField('category',
         searchable=0,
         required=0,
         vocabulary='categoryVocab',
         widget=MasterSelectWidget(
             slave_fields=slave_fields2,
             description="Master",
         ),
     ),

     atapi.StringField('subcategory',
         searchable=0,
         required=0,
         default='',
         vocabulary='subcategoryVocab',
         widget=atapi.SelectionWidget(
             format='select',
             label=_(u'subcategory_label', default=u'Sub Category'),
             description=_(u'subcategory_help', default=u"Select helpdesk request 
sub type"),
             ),
     ),
.......
     security.declarePublic('categoryVocab')
     def categoryVocab(self):
         """ """
         categories = DisplayList()
         categories.add('', _(u'-- not specified --'))
         for category in self.aq_parent.getCategory_list():
             categories.add(category, category)
         return categories

     security.declarePublic('subcategoryVocab')
     def subcategoryVocab(self, master):
         subcategories = DisplayList()
         subcategories.add('', _(u'-- not specified --'))
         for subcategory in self.aq_parent.getSubcategory_list():
             #if subcategory[0] == master[0]:
                 subcategories.add(subcategory, subcategory)
         return subcategories

ma sembra non trovare il valore di master

Error
Module zope.pagetemplate.pagetemplate, line 113, in pt_render
Warning: Macro expansion failed
Warning: <type 'exceptions.KeyError'>: 'macro'
......
URL: 
file:/usr/local/Plone/buildout-cache/eggs/Products.Archetypes-1.8.6-py2.7.egg/Products/Archetypes/skins/archetypes/widgets/selection.pt
Line 36, Column 12
Expression: <PythonExpr field.Vocabulary(context)>
Names:
.......

   Module Products.Archetypes.utils, line 125, in mapply

TypeError: subcategoryVocab() takes exactly 2 arguments (1 given)
.......

Sbaglio o dovrei vedere con firebug una chiamata a masterselect.js?

Qualche idea?

Sembra sbagliata la definizione di subcategoryVocab. Cos'è "master"?



master dovrebbe essere il parametro passato da category


Nella definizione di "vocabulary" di Archetypes non esiste un
parametro aggiuntivo, nella tua definizione invece c'è ed è
obbligatorio.

Secondo me hai male interpretato come usare MasterSelectWidget


Sì, c'è un problema nel codice.

Natale, basta differenziare il vocabolario archetypes da quello che si occupa di filtrare le voci in base alla selezione del master.
C'è un parametro di troppo.

Ciao,

davide

--
Davide Moro
Technical Development Manager
http://linkedin.com/in/davidemoro82

Redomino Srl
http://redomino.com
HQ Largo Valgioie 14, Turin IT
Phone +39 0117499875

_______________________________________________
Plone-IT mailing list
plone...@lists.plone.org
https://lists.plone.org/mailman/listinfo/plone-plone-it
http://plone-regional-forums.221720.n2.nabble.com/Plone-Italy-f221721.html

Rispondere a