def test_rql_condition_entity(self): with self.admin_access.web_request() as req: selector = rql_condition('X identity U') rset = req.user.as_rset() self.assertEqual(selector(None, req, rset=rset), 1) self.assertEqual(selector(None, req, entity=req.user), 1) self.assertEqual(selector(None, req), 0)
class CompteCommandesTab(EntityView): __select__ = is_instance('Compte') & rql_condition('T compte X, T is Commande') __regid__ = _('commandes_tab') title = _('Commandes') def cell_call(self, row, col): entity = self.cw_rset.complete_entity(row, col) rset = self._cw.execute('Any T ORDERBY P where T is Commande, T numero P, T compte C, C eid %(eid)s', {'eid': entity.eid}) self.wview('myosotis.commande.attributestableview', rset)
class CompteOccasionTab(EntityView): __select__ = is_instance('Compte') & rql_condition('T compte X, T occasion O') __regid__ = _('occasions_tab') title = _('Occasion') def cell_call(self, row, col): entity = self.cw_rset.complete_entity(row, col) rset = self._cw.execute('Any O where O is Occasion, EXISTS (T occasion O, T compte C, C eid %(eid)s)', {'eid': entity.eid}) self.wview('myosotis.occasion.attributestableview', rset)
class CompteChangeTab(EntityView): __select__ = is_instance('Compte') & rql_condition('C is Change, X change C') __regid__ = _('changes_tab') title = _('Changes') def cell_call(self, row, col): entity = self.cw_rset.complete_entity(row, col) rset = self._cw.execute('Any T where T is Change, C change T, C eid %(eid)s', {'eid': entity.eid}) self.wview('myosotis.change.attributestableview', rset)
class CompteTransactionTab2(EntityView): __select__ = is_instance('Compte') & rql_condition('T compte X, T is Transaction') __regid__ = _('transactions_tab') title = _('Transactions') def cell_call(self, row, col): entity = self.cw_rset.complete_entity(row, col) rql = entity.cw_related_rql('compte', 'object', ('Transaction',),) rset = self._cw.execute(rql, {'x': entity.eid}) self.wview('myosotis.transaction.attributestableview', rset)
class ExpenseLineFilesComponent(component.EntityCtxComponent): """display the list of files attached to the expenselines""" __regid__ = 'expenseline.attachments' __select__ = (component.EntityCtxComponent.__select__ & authenticated_user() & is_instance('Expense') & rql_condition('EXISTS(X has_lines Y, Y has_attachment F) ' 'OR EXISTS(X has_attachment F)')) title = _('has_attachment') def render_body(self, w): rset = self._cw.execute( '(Any F WHERE X has_attachment F, X eid %(x)s)' ' UNION ' '(Any F WHERE X has_lines Y, Y has_attachment F, X eid %(x)s)', dict(x=self.entity.eid)) self._cw.view('incontext', rset, 'null', w=w)
def test_rql_condition_user(self): with self.admin_access.web_request() as req: selector = rql_condition('U login "admin"', user_condition=True) self.assertEqual(selector(None, req), 1) selector = rql_condition('U login "toto"', user_condition=True) self.assertEqual(selector(None, req), 0)
class CWETypeRQLAction(Action): __regid__ = 'testaction' __select__ = is_instance('CWEType') & rql_condition('X name "CWEType"') title = 'bla'