def unread_posts(session, user, threads): thread_ids = [t.id for t in threads] if not thread_ids: return [] post_selection = select([LastRead.c.thread_id, LastRead.c.post_number]).where( and_(LastRead.c.user_id == user.id, in_op(LastRead.c.thread_id, thread_ids)) ) return session.execute(post_selection).fetchall()
def unread_posts(session, user, threads): thread_ids = [t.id for t in threads] if not thread_ids: return [] post_selection = select([LastRead.c.thread_id, LastRead.c.post_number]).where( and_(LastRead.c.user_id == user.id, in_op(LastRead.c.thread_id, thread_ids))) return session.execute(post_selection).fetchall()
def get_results(self): query = select([ label('user_id', self.sql_table.c.owner_id), label('count', func.count(self.sql_table.c.doc_id)) ]).where(and_( self.sql_table.c.type != self.cc_case_type, self.sql_table.c.closed == 0, operators.in_op(self.sql_table.c.owner_id, self.users_needing_data), )).group_by( self.sql_table.c.owner_id ) return self._run_query(query)
def get_results(self, start_date, end_date): query = select([ label('user_id', self.sql_table.c.user_id), label('count', func.count(self.sql_table.c.doc_id)) ]).where( and_( operators.ge(self.sql_table.c.time_end, start_date), operators.lt(self.sql_table.c.time_end, end_date), operators.in_op(self.sql_table.c.user_id, self.users_needing_data))).group_by( self.sql_table.c.user_id) return self._run_query(query)
def get_results(self, start_date, end_date): query = select([ label('user_id', self.sql_table.c.user_id), label('count', func.count(self.sql_table.c.doc_id)) ]).where(and_( operators.ge(self.sql_table.c.time_end, start_date), operators.lt(self.sql_table.c.time_end, end_date), operators.in_op(self.sql_table.c.user_id, self.users_needing_data) )).group_by( self.sql_table.c.user_id ) return self._run_query(query)
def get_permission_for_user(user_id, resource_name, privilege, is_owner): from sqlalchemy import and_, or_ from sqlalchemy.sql.operators import in_op roles = AclUserRole.get_roles_for(user_id=user_id, is_owner=is_owner) return AclRoleResource.query.filter( and_( or_(AclRoleResource.resource_name == "*", AclRoleResource.resource_name == resource_name), AclRoleResource._privilege.op("&")(privilege) > 0, in_op(AclRoleResource.role_id, roles), ) ).all()
def get_permission_for_user(user_id, resource_name, privilege, is_owner): from sqlalchemy import and_, or_ from sqlalchemy.sql.operators import in_op roles = AclUserRole.get_roles_for(user_id=user_id, is_owner=is_owner) return AclRoleResource.query.filter( and_( or_( AclRoleResource.resource_name == '*', AclRoleResource.resource_name == resource_name, ), AclRoleResource._privilege.op('&')(privilege) > 0, in_op(AclRoleResource.role_id, roles))).all()
def _build_query(self, include_type_in_result, limit_types, where_clauses, distinct_docs=False): standard_where = [ self.type_filter(limit_types), operators.in_op(self.owner_column, self.owners_needing_data), ] all_where = where_clauses + standard_where query = select( self.columns(include_type_in_result, distinct_docs=distinct_docs) ).where(and_( *all_where )).group_by( *self.group_by(include_type_in_result) ) return query
def get_results(self, xmlns, indicator_type, start_date, end_date): if indicator_type == TYPE_DURATION: aggregation = func.avg(self.sql_table.c.duration) else: aggregation = func.count(self.sql_table.c.doc_id) query = select([ label('user_id', self.sql_table.c.user_id), label('count', aggregation) ]).where(and_( operators.ge(self.sql_table.c.time_end, start_date), operators.lt(self.sql_table.c.time_end, end_date), operators.in_op(self.sql_table.c.user_id, self.users_needing_data), self.sql_table.c.xmlns == xmlns, )).group_by( self.sql_table.c.user_id ) return self._run_query(query)
def get_results(self, xmlns, indicator_type, start_date, end_date): if indicator_type == TYPE_DURATION: aggregation = func.avg(self.sql_table.c.duration) else: aggregation = func.count(self.sql_table.c.doc_id) query = select([ label('user_id', self.sql_table.c.user_id), label('count', aggregation) ]).where( and_( operators.ge(self.sql_table.c.time_end, start_date), operators.lt(self.sql_table.c.time_end, end_date), operators.in_op(self.sql_table.c.user_id, self.users_needing_data), self.sql_table.c.xmlns == xmlns, )).group_by(self.sql_table.c.user_id) return self._run_query(query)
def get_banner_list(date_start=None, date_finish=None, app_codes=None): # noqa: E501 """Получить список активных баннеров # noqa: E501 :param date_start: Дата начала работ :type date_start: str :param date_finish: Дата окончания работ :type date_finish: str :param app_codes: Системы на которые вешается баннер :type app_codes: List[str] :rtype: List[Banner] """ date_start = util.deserialize_datetime(date_start) if date_start else datetime.datetime.min date_finish = util.deserialize_datetime(date_finish) if date_finish else datetime.datetime.max filtered = and_(Banner.date_start >= date_start, Banner.date_finish <= date_finish) if app_codes: filtered = and_(in_op(Banner.app_code, app_codes), filtered) return Banner.query.filter(filtered) \ .order_by(Banner.date_start) \ .all()
def type_filter(self, limit_types): if limit_types: return operators.in_op(self.type_column, limit_types) else: return self.type_column != self.cc_case_type
def build_expression(self, table): assert isinstance(self.parameter, collections.Iterable) return operators.in_op( get_column(table, self.column_name), tuple(bindparam(param) for param in self.parameter))
def build_expression(self): assert isinstance(self.parameter, collections.Iterable) return operators.in_op( column(self.column_name), tuple(bindparam(param) for param in self.parameter) )