def or_regex(self, field: str, pattern: str, case_insensitive: bool = False, multiline: bool = False, dot_all: bool = False, verbose: bool = False): """Shortcut """ return self.add( qu.Or( qu.Regex(field, pattern, case_insensitive, multiline, dot_all, verbose)))
def _get_query(self) -> query.Query: q = query.Query() if not auth.get_current_user().is_admin: q.add(query.Eq('status', 'active')) q.add(query.Eq('is_public', True)) search = self.arg('q') if search: q.add(query.Or([ query.Regex('first_name', search, True), query.Regex('last_name', search, True), ])) return q
def exec(self) -> list: uids = self.arg('uids') exclude = self.arg('exclude') search = self.arg('search') or self.arg('q') r = [] if uids: for uid in self.arg('uids'): try: user = auth.get_user(uid=uid) json = user.as_jsonable() events.fire('auth_http_api@get_user', user=user, json=json) r.append(json) except Exception as e: # Any exception is ignored due to safety reasons logger.warn(e) elif search and reg.get('auth_http_api.search', False): q = query.Query() q.add( query.Or([ query.Regex('first_name', '^{}'.format(search), True), query.Regex('last_name', '^{}'.format(search), True), ])) if not auth.get_current_user().is_admin: q.add(query.Eq('is_public', True)) if exclude: q.add(query.Nin('uid', exclude)) for user in auth.find_users(q, limit=self.arg('limit'), skip=self.arg('skip')): r.append(user.as_jsonable()) return r
def or_text(self, search: str, language: str = None): """Shortcut """ return self.add(qu.Or(qu.Text(search, language)))
def or_ninc(self, field: str, arg): """Shortcut """ return self.add(qu.Or(qu.Nin(field, arg)))
def or_lte(self, field: str, arg): """Shortcut """ return self.add(qu.Or(qu.Lte(field, arg)))
def or_gt(self, field: str, arg): """Shortcut """ return self.add(qu.Or(qu.Gt(field, arg)))
def or_eq(self, field: str, arg): """Shortcut """ return self.add(qu.Or(qu.Eq(field, arg)))