cwvreg.py
branchtls-sprint
changeset 1309 a4eb20f86cb0
parent 1282 272d8ec6f308
child 1357 e5a97779c7fc
equal deleted inserted replaced
1308:3d01229d9f6a 1309:a4eb20f86cb0
   337                              'from the database)', ex)
   337                              'from the database)', ex)
   338             except UnknownProperty, ex:
   338             except UnknownProperty, ex:
   339                 self.warning('%s (you should probably delete that property '
   339                 self.warning('%s (you should probably delete that property '
   340                              'from the database)', ex)
   340                              'from the database)', ex)
   341 
   341 
   342 
       
   343     def property_value_widget(self, propkey, req=None, **attrs):
       
   344         """return widget according to key's type / vocab"""
       
   345         from cubicweb.web.widgets import StaticComboBoxWidget, widget_factory
       
   346         if req is None:
       
   347             tr = unicode
       
   348         else:
       
   349             tr = req._
       
   350         try:
       
   351             pdef = self.property_info(propkey)
       
   352         except UnknownProperty, ex:
       
   353             self.warning('%s (you should probably delete that property '
       
   354                          'from the database)', ex)
       
   355             return widget_factory(self, 'EProperty', self.schema['value'], 'String',
       
   356                                   description=u'', **attrs)
       
   357         req.form['value'] = pdef['default'] # XXX hack to pass the default value
       
   358         vocab = pdef['vocabulary']
       
   359         if vocab is not None:
       
   360             if callable(vocab):
       
   361                 # list() just in case its a generator function
       
   362                 vocabfunc = lambda **kwargs: list(vocab(propkey, req))
       
   363             else:
       
   364                 vocabfunc = lambda **kwargs: vocab
       
   365             w = StaticComboBoxWidget(self, 'EProperty', self.schema['value'], 'String',
       
   366                                      vocabfunc=vocabfunc, description=tr(pdef['help']),
       
   367                                      **attrs)
       
   368         else:
       
   369             w = widget_factory(self, 'EProperty', self.schema['value'], pdef['type'],
       
   370                                description=tr(pdef['help']), **attrs)
       
   371         return w
       
   372 
       
   373     def parse(self, session, rql, args=None):
   342     def parse(self, session, rql, args=None):
   374         rqlst = self.rqlhelper.parse(rql)
   343         rqlst = self.rqlhelper.parse(rql)
   375         def type_from_eid(eid, session=session):
   344         def type_from_eid(eid, session=session):
   376             return session.describe(eid)[0]
   345             return session.describe(eid)[0]
   377         try:
   346         try: