1141 lookup / score rules according to the input context. |
1141 lookup / score rules according to the input context. |
1142 """ |
1142 """ |
1143 def __init__(self, expression, once_is_enough=False): |
1143 def __init__(self, expression, once_is_enough=False): |
1144 super(rql_condition, self).__init__(once_is_enough) |
1144 super(rql_condition, self).__init__(once_is_enough) |
1145 if 'U' in frozenset(split_expression(expression)): |
1145 if 'U' in frozenset(split_expression(expression)): |
1146 rql = 'Any X WHERE X eid %%(x)s, U eid %%(u)s, %s' % expression |
1146 rql = 'Any COUNT(X) WHERE X eid %%(x)s, U eid %%(u)s, %s' % expression |
1147 else: |
1147 else: |
1148 rql = 'Any X WHERE X eid %%(x)s, %s' % expression |
1148 rql = 'Any COUNT(X) WHERE X eid %%(x)s, %s' % expression |
1149 self.rql = rql |
1149 self.rql = rql |
1150 |
1150 |
1151 def __repr__(self): |
1151 def __repr__(self): |
1152 return u'<rql_condition "%s" at %x>' % (self.rql, id(self)) |
1152 return u'<rql_condition "%s" at %x>' % (self.rql, id(self)) |
1153 |
1153 |
1154 def score(self, req, rset, row, col): |
1154 def score(self, req, rset, row, col): |
1155 try: |
1155 try: |
1156 return len(req.execute(self.rql, {'x': rset[row][col], |
1156 return req.execute(self.rql, {'x': rset[row][col], |
1157 'u': req.user.eid})) |
1157 'u': req.user.eid})[0][0] |
1158 except Unauthorized: |
1158 except Unauthorized: |
1159 return 0 |
1159 return 0 |
1160 |
1160 |
1161 |
1161 |
1162 class is_in_state(score_entity): |
1162 class is_in_state(score_entity): |