[widgets] use LazyRestrictedAutoCompletionWidget instead of RestirectedAUtoCompletionWidget
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Thu, 21 Oct 2010 16:22:05 +0200
changeset 45 57a92eae8941
parent 44 ab6783fd3a15
child 49 b3e20c6aae6e
[widgets] use LazyRestrictedAutoCompletionWidget instead of RestirectedAUtoCompletionWidget
views/__init__.py
--- a/views/__init__.py	Thu Apr 15 19:02:41 2010 +0200
+++ b/views/__init__.py	Thu Oct 21 16:22:05 2010 +0200
@@ -9,10 +9,19 @@
 _afs.tag_subject_of(('Expense', 'spent_for', '*'), 'main', 'attributes')
 _afs.tag_subject_of(('Expense', 'spent_for', '*'), 'muledit', 'attributes')
 _affk.tag_subject_of(('Expense', 'spent_for', '*'),
-                     {'widget': fw.RestrictedAutoCompletionWidget(autocomplete_initfunc='get_concerned_by')})
+                     {'widget': fw.LazyRestrictedAutoCompletionWidget(
+            autocomplete_initfunc='get_concerned_by',
+            autocomplete_settings={'limit': 100,
+                                   'delay': 300}),
+                      })
 
 
 @monkeypatch(basecontrollers.JSonController)
 @basecontrollers.jsonize
 def js_get_concerned_by(self):
-    return self._cw.execute('DISTINCT Any W,R ORDERBY R WHERE W ref R').rows
+    term = self._cw.form['q']
+    limit = self._cw.form.get('limit', 50)
+    return [{'value': eid, 'label': ref}
+            for eid, ref in self._cw.execute('DISTINCT Any W,R ORDERBY R LIMIT %s WHERE W ref R,'
+                                             'W ref ILIKE %%(term)s' % limit,
+                                             {'term': u'%%%s%%' % term})]