cwvreg.py
branchtls-sprint
changeset 1263 01152fffd593
parent 1176 0ff3d29e91c9
parent 1254 585f3c476a18
child 1282 272d8ec6f308
equal deleted inserted replaced
1246:76b3cd5d4f31 1263:01152fffd593
     9 from logilab.common.decorators import cached, clear_cache
     9 from logilab.common.decorators import cached, clear_cache
    10 from logilab.common.interface import extend
    10 from logilab.common.interface import extend
    11 
    11 
    12 from rql import RQLHelper
    12 from rql import RQLHelper
    13 
    13 
    14 from cubicweb import Binary, UnknownProperty
    14 from cubicweb import Binary, UnknownProperty, UnknownEid
    15 from cubicweb.vregistry import VRegistry, ObjectNotFound, NoSelectableObject
    15 from cubicweb.vregistry import VRegistry, ObjectNotFound, NoSelectableObject
    16 
    16 
    17 _ = unicode
    17 _ = unicode
    18 
    18 
    19 def use_interfaces(obj):
    19 def use_interfaces(obj):
   350         req.form['value'] = pdef['default'] # XXX hack to pass the default value
   350         req.form['value'] = pdef['default'] # XXX hack to pass the default value
   351         vocab = pdef['vocabulary']
   351         vocab = pdef['vocabulary']
   352         if vocab is not None:
   352         if vocab is not None:
   353             if callable(vocab):
   353             if callable(vocab):
   354                 # list() just in case its a generator function
   354                 # list() just in case its a generator function
   355                 vocabfunc = lambda e: list(vocab(propkey, req))
   355                 vocabfunc = lambda **kwargs: list(vocab(propkey, req))
   356             else:
   356             else:
   357                 vocabfunc = lambda e: vocab
   357                 vocabfunc = lambda **kwargs: vocab
   358             w = StaticComboBoxWidget(self, 'EProperty', self.schema['value'], 'String',
   358             w = StaticComboBoxWidget(self, 'EProperty', self.schema['value'], 'String',
   359                                      vocabfunc=vocabfunc, description=tr(pdef['help']),
   359                                      vocabfunc=vocabfunc, description=tr(pdef['help']),
   360                                      **attrs)
   360                                      **attrs)
   361         else:
   361         else:
   362             w = widget_factory(self, 'EProperty', self.schema['value'], pdef['type'],
   362             w = widget_factory(self, 'EProperty', self.schema['value'], pdef['type'],
   365 
   365 
   366     def parse(self, session, rql, args=None):
   366     def parse(self, session, rql, args=None):
   367         rqlst = self.rqlhelper.parse(rql)
   367         rqlst = self.rqlhelper.parse(rql)
   368         def type_from_eid(eid, session=session):
   368         def type_from_eid(eid, session=session):
   369             return session.describe(eid)[0]
   369             return session.describe(eid)[0]
   370         self.rqlhelper.compute_solutions(rqlst, {'eid': type_from_eid}, args)
   370         try:
       
   371             self.rqlhelper.compute_solutions(rqlst, {'eid': type_from_eid}, args)
       
   372         except UnknownEid:
       
   373             for select in rqlst.children:
       
   374                 select.solutions = []
   371         return rqlst
   375         return rqlst
   372 
   376 
   373     @property
   377     @property
   374     @cached
   378     @cached
   375     def rqlhelper(self):
   379     def rqlhelper(self):