__init__.py 1.16 KB
Newer Older
Sylvain's avatar
Sylvain committed
1
"""template-specific forms/views/actions/components"""
2
3
from logilab.common.decorators import monkeypatch

Nsukami Patrick's avatar
Nsukami Patrick committed
4
5
from cubicweb.web import formwidgets as fw
from cubicweb.web.views import uicfg, basecontrollers
6

7
8
_afs = uicfg.autoform_section
_affk = uicfg.autoform_field_kwargs
Sylvain Thénault's avatar
Sylvain Thénault committed
9
10
_afs.tag_subject_of(('Expense', 'spent_for', '*'), 'main', 'attributes')
_afs.tag_subject_of(('Expense', 'spent_for', '*'), 'muledit', 'attributes')
11
_affk.tag_subject_of(('Expense', 'spent_for', '*'),
12
13
14
15
16
                     {'widget': fw.LazyRestrictedAutoCompletionWidget(
            autocomplete_initfunc='get_concerned_by',
            autocomplete_settings={'limit': 100,
                                   'delay': 300}),
                      })
17
18
19
20
21


@monkeypatch(basecontrollers.JSonController)
@basecontrollers.jsonize
def js_get_concerned_by(self):
22
23
24
25
26
27
    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})]