當前位置: 首頁>>代碼示例>>Python>>正文


Python expression.or_方法代碼示例

本文整理匯總了Python中sqlalchemy.sql.expression.or_方法的典型用法代碼示例。如果您正苦於以下問題:Python expression.or_方法的具體用法?Python expression.or_怎麽用?Python expression.or_使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sqlalchemy.sql.expression的用法示例。


在下文中一共展示了expression.or_方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: feed_shelf

# 需要導入模塊: from sqlalchemy.sql import expression [as 別名]
# 或者: from sqlalchemy.sql.expression import or_ [as 別名]
def feed_shelf(book_id):
    off = request.args.get("offset") or 0
    if current_user.is_anonymous:
        shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.is_public == 1,
                                                  ub.Shelf.id == book_id).first()
    else:
        shelf = ub.session.query(ub.Shelf).filter(or_(and_(ub.Shelf.user_id == int(current_user.id),
                                                           ub.Shelf.id == book_id),
                                                      and_(ub.Shelf.is_public == 1,
                                                           ub.Shelf.id == book_id))).first()
    result = list()
    # user is allowed to access shelf
    if shelf:
        books_in_shelf = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == book_id).order_by(
            ub.BookShelf.order.asc()).all()
        for book in books_in_shelf:
            cur_book = calibre_db.get_book(book.book_id)
            result.append(cur_book)
    pagination = Pagination((int(off) / (int(config.config_books_per_page)) + 1), config.config_books_per_page,
                            len(result))
    return render_xml_template('feed.xml', entries=result, pagination=pagination) 
開發者ID:janeczku,項目名稱:calibre-web,代碼行數:23,代碼來源:opds.py

示例2: get_replica_locks

# 需要導入模塊: from sqlalchemy.sql import expression [as 別名]
# 或者: from sqlalchemy.sql.expression import or_ [as 別名]
def get_replica_locks(scope, name, nowait=False, restrict_rses=None, session=None):
    """
    Get the active replica locks for a file

    :param scope:          Scope of the did.
    :param name:           Name of the did.
    :param nowait:         Nowait parameter for the FOR UPDATE statement.
    :param restrict_rses:  Possible RSE_ids to filter on.
    :param session:        The db session.
    :return:               List of dicts {'rse': ..., 'state': ...}
    :raises:               NoResultFound
    """

    query = session.query(models.ReplicaLock).filter_by(scope=scope, name=name)
    if restrict_rses is not None:
        rse_clause = []
        for rse_id in restrict_rses:
            rse_clause.append(models.ReplicaLock.rse_id == rse_id)
        if rse_clause:
            query = query.filter(or_(*rse_clause))

    return query.with_for_update(nowait=nowait).all() 
開發者ID:rucio,項目名稱:rucio,代碼行數:24,代碼來源:lock.py

示例3: get_user

# 需要導入模塊: from sqlalchemy.sql import expression [as 別名]
# 或者: from sqlalchemy.sql.expression import or_ [as 別名]
def get_user( session, broker_id, username=None, email=None, user_id=None ):
    if username:
      username = username.lower().strip()
    if email:
      email = email.lower().strip()


    if user_id:
      filter_obj = or_(User.id == user_id)
    elif username and email:
      filter_obj = or_( func.lower(User.username)==username, func.lower(User.email)==email )
    elif username:
      filter_obj = or_( func.lower(User.username)==username )
    elif email:
      filter_obj = or_( func.lower(User.email)==email )
    else:
      return  None
    user = session.query(User).filter(User.broker_id == broker_id).filter(filter_obj).first()
    if user:
      return  user
    return None 
開發者ID:bitex-coin,項目名稱:backend,代碼行數:23,代碼來源:models.py

示例4: get_list

# 需要導入模塊: from sqlalchemy.sql import expression [as 別名]
# 或者: from sqlalchemy.sql.expression import or_ [as 別名]
def get_list(session, broker_id, status_list, country = None, state=None, client_id=None,  page_size = None, offset = None, sort_column = None, sort_order='ASC'):
    query = session.query(User).filter( User.verified.in_( status_list ) ).filter(User.broker_id==broker_id)

    if country:
      query = query.filter(User.country_code == country)
    if state:
      query = query.filter(User.state == state)

    if client_id:
      query = query.filter( or_( User.username.like(client_id), User.email.like('%' + client_id + '%'), User.verification_data.like( '%'  + client_id + '%') ) )


    if page_size:
      query = query.limit(page_size)
    if offset:
      query = query.offset(offset)
    if sort_column:
      if sort_order == 'ASC':
        query = query.order(sort_column)
      else:
        query = query.order(sort_column).desc()
    return query 
開發者ID:bitex-coin,項目名稱:backend,代碼行數:24,代碼來源:models.py

示例5: search

# 需要導入模塊: from sqlalchemy.sql import expression [as 別名]
# 或者: from sqlalchemy.sql.expression import or_ [as 別名]
def search(cls, querystr, sqlalchemy_query=None, user_name=None):
        '''Search name, fullname, email and openid. '''
        if sqlalchemy_query is None:
            query = meta.Session.query(cls)
        else:
            query = sqlalchemy_query
        qstr = '%' + querystr + '%'
        filters = [
            cls.name.ilike(qstr),
            cls.fullname.ilike(qstr),
            cls.openid.ilike(qstr),
        ]
        # sysadmins can search on user emails
        import ckan.authz as authz
        if user_name and authz.is_sysadmin(user_name):
            filters.append(cls.email.ilike(qstr))

        query = query.filter(or_(*filters))
        return query 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:21,代碼來源:user.py

示例6: sort_rses

# 需要導入模塊: from sqlalchemy.sql import expression [as 別名]
# 或者: from sqlalchemy.sql.expression import or_ [as 別名]
def sort_rses(rses, session=None):
    """
    Sort a list of RSES by free space (ascending order).

    :param rses: List of RSEs.
    :param session: The database session in use.

    :returns: Sorted list of RSEs
    """
    if not rses:
        raise exception.InputValidationError('The list rses should not be empty!')

    if len(rses) == 1:
        return rses

    false_value = False
    query = session.query(models.RSE.rse, models.RSE.staging_area, models.RSEUsage.rse_id).\
        filter(models.RSEUsage.source == 'storage').\
        filter(models.RSEUsage.rse_id == models.RSE.id).\
        filter(models.RSE.deleted == false_value)
    condition = []
    for rse in rses:
        condition.append(models.RSE.id == rse['id'])
    query = query.filter(or_(*condition)).order_by(models.RSEUsage.free.asc())
    return [{'rse': rse, 'staging_area': staging_area, 'id': rse_id} for rse, staging_area, rse_id in query]
    # return sample(rses, len(rses)) 
開發者ID:rucio,項目名稱:rucio,代碼行數:28,代碼來源:rse.py

示例7: get_local_account_limits

# 需要導入模塊: from sqlalchemy.sql import expression [as 別名]
# 或者: from sqlalchemy.sql.expression import or_ [as 別名]
def get_local_account_limits(account, rse_ids=None, session=None):
    """
    Returns the account limits for the account on the list of rses.

    :param account:  Account to check the limit for.
    :param rse_ids:  List of RSE ids to check the limit for.
    :param session:  Database session in use.
    :return:         Dictionary {'rse_id': bytes, ...}.
    """

    account_limits = {}
    if rse_ids:
        rse_id_clauses = []
        for rse_id in rse_ids:
            rse_id_clauses.append(and_(models.AccountLimit.rse_id == rse_id, models.AccountLimit.account == account))
        rse_id_clause_chunks = [rse_id_clauses[x:x + 10] for x in range(0, len(rse_id_clauses), 10)]
        for rse_id_chunk in rse_id_clause_chunks:
            tmp_limits = session.query(models.AccountLimit).filter(or_(*rse_id_chunk)).all()
            for limit in tmp_limits:
                if limit.bytes == -1:
                    account_limits[limit.rse_id] = float("inf")
                else:
                    account_limits[limit.rse_id] = limit.bytes
    else:
        account_limits_tmp = session.query(models.AccountLimit).filter(models.AccountLimit.account == account).all()
        for limit in account_limits_tmp:
            if limit.bytes == -1:
                account_limits[limit.rse_id] = float("inf")
            else:
                account_limits[limit.rse_id] = limit.bytes
    return account_limits 
開發者ID:rucio,項目名稱:rucio,代碼行數:33,代碼來源:account_limit.py

示例8: compile_expression

# 需要導入模塊: from sqlalchemy.sql import expression [as 別名]
# 或者: from sqlalchemy.sql.expression import or_ [as 別名]
def compile_expression(self):
        # So, this is what we expect here
        # self.operator_str: $and, $or, $nor, $not
        # self.value: list[FilterExpressionBase], or just FilterExpressionBase for $not
        #   This means `value` is a list of (column, operator, value), wrapped into an object.
        #   For example: (`age`, ">=", 18)
        #   And the current boolean clause puts it together.

        if self.operator_str == '$not':
            # This operator accepts a FilterExpressionBase, not a list.
            criterion = self.sql_anded_together([
                c.compile_expression()
                for c in self.value
            ])
            return not_(criterion)
        else:
            # Those operators share some steps, so they've been put into one section

            # Their argument (self.value) is a list[FilterExpressionBase].
            # Compile it
            criteria = [self.sql_anded_together([c.compile_expression() for c in cs])
                        for cs in self.value]

            # Build an expression for the boolean operator
            if self.operator_str in ('$or', '$nor'):
                cc = or_(*criteria)
                # for $nor, it will be negated later
            elif self.operator_str == '$and':
                cc = and_(*criteria)
            else:
                raise NotImplementedError('Unknown operator: {}'.format(self.operator_str))

            # Put parentheses around it when there are multiple clauses
            cc = cc.self_group() if len(criteria) > 1 else cc

            # for $nor, we promised to negate the result
            if self.operator_str == '$nor':
                return ~cc
            # Done
            return cc 
開發者ID:kolypto,項目名稱:py-mongosql,代碼行數:42,代碼來源:filter.py

示例9: _find_zone_transfer_requests

# 需要導入模塊: from sqlalchemy.sql import expression [as 別名]
# 或者: from sqlalchemy.sql.expression import or_ [as 別名]
def _find_zone_transfer_requests(self, context, criterion, one=False,
                                     marker=None, limit=None, sort_key=None,
                                     sort_dir=None):

        table = tables.zone_transfer_requests

        ljoin = tables.zone_transfer_requests.join(
            tables.zones,
            tables.zone_transfer_requests.c.zone_id == tables.zones.c.id)

        query = select(
            [table, tables.zones.c.name.label("zone_name")]
        ).select_from(ljoin)

        if not context.all_tenants:
            query = query.where(or_(
                table.c.tenant_id == context.project_id,
                table.c.target_tenant_id == context.project_id))

        return self._find(
            context, table, objects.ZoneTransferRequest,
            objects.ZoneTransferRequestList,
            exceptions.ZoneTransferRequestNotFound,
            criterion,
            one=one, marker=marker, limit=limit, sort_dir=sort_dir,
            sort_key=sort_key, query=query, apply_tenant_criteria=False
        ) 
開發者ID:openstack,項目名稱:designate,代碼行數:29,代碼來源:__init__.py

示例10: get_trade

# 需要導入模塊: from sqlalchemy.sql import expression [as 別名]
# 或者: from sqlalchemy.sql.expression import or_ [as 別名]
def get_trade(session, trade_id=None):
        if trade_id:
            filter_obj = or_(Trade.id == trade_id)
        else:
            return None
        trade = session.query(Trade).filter(filter_obj).first()
        if trade:
            return trade
        return None 
開發者ID:bitex-coin,項目名稱:backend,代碼行數:11,代碼來源:models.py

示例11: get

# 需要導入模塊: from sqlalchemy.sql import expression [as 別名]
# 或者: from sqlalchemy.sql.expression import or_ [as 別名]
def get(cls, user_reference):
        # double slashes in an openid often get turned into single slashes
        # by browsers, so correct that for the openid lookup
        corrected_openid_user_ref = cls.DOUBLE_SLASH.sub('://\\1',
                                                         user_reference)
        query = meta.Session.query(cls).autoflush(False)
        query = query.filter(or_(cls.name == user_reference,
                                 cls.openid == corrected_openid_user_ref,
                                 cls.id == user_reference))
        return query.first() 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:12,代碼來源:user.py

示例12: user_ids_for_name_or_id

# 需要導入模塊: from sqlalchemy.sql import expression [as 別名]
# 或者: from sqlalchemy.sql.expression import or_ [as 別名]
def user_ids_for_name_or_id(self, user_list=[]):
        '''
        This function returns a list of ids from an input that can be a list of
        names or ids
        '''
        query = meta.Session.query(self.id)
        query = query.filter(or_(self.name.in_(user_list),
                                 self.id.in_(user_list)))
        return [user.id for user in query.all()] 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:11,代碼來源:user.py

示例13: forward

# 需要導入模塊: from sqlalchemy.sql import expression [as 別名]
# 或者: from sqlalchemy.sql.expression import or_ [as 別名]
def forward(cls, subjecttype_id, from_date, to_date, whole_time_required):
        q = select([t_subjects.c.id, ]).where(t_subjects.c.subjecttype_id == subjecttype_id)
        if from_date != None and to_date != None:
            if whole_time_required:
                q = q.where(and_(
                    t_subjects.c.created_at <= from_date
                    #or_(
                    #    t_subjects.c.deleted_at == None,
                    #    t_subjects.c.deleted_at >= to_date
                    #)
                ))
            else:
                q = q.where(or_(
                    and_(
                        t_subjects.c.created_at <= from_date,
                        #or_(
                        #    t_subjects.c.deleted_at >= from_date,
                        #    t_subjects.c.deleted_at == None,
                        #)
                    ),
                    and_(
                        t_subjects.c.created_at >= from_date,
                        t_subjects.c.created_at <= to_date,
                    )
                ))
        return [x.id for x in DBSession.execute(q).fetchall()]

    #@classmethod
    #def reverse(cls):
    #    return cls.forward() 
開發者ID:ActiDoo,項目名稱:gamification-engine,代碼行數:32,代碼來源:leaderboard.py

示例14: complete

# 需要導入模塊: from sqlalchemy.sql import expression [as 別名]
# 或者: from sqlalchemy.sql.expression import or_ [as 別名]
def complete(format='json'):
    if not current_user.is_authenticated():
        msg = _("You are not authorized to see that page")
        return jsonify({'status': 'error', 'message': msg}, status=403)

    query = db.session.query(Account)
    filter_string = request.args.get('q', '') + '%'
    query = query.filter(or_(Account.name.ilike(filter_string),
                             Account.fullname.ilike(filter_string)))
    return jsonify(Pager(query)) 
開發者ID:openspending,項目名稱:spendb,代碼行數:12,代碼來源:account.py

示例15: all_by_account

# 需要導入模塊: from sqlalchemy.sql import expression [as 別名]
# 或者: from sqlalchemy.sql.expression import or_ [as 別名]
def all_by_account(cls, account, order=True):
        """ Query available datasets based on dataset visibility. """
        from spendb.model.account import Account
        has_user = account and account.is_authenticated()
        has_admin = has_user and account.admin
        q = db.session.query(cls)
        if not has_admin:
            criteria = [cls.private == False]  # noqa
            if has_user:
                criteria.append(cls.managers.any(Account.id == account.id))
            q = q.filter(or_(*criteria))

        if order:
            q = q.order_by(cls.label.asc())
        return q 
開發者ID:openspending,項目名稱:spendb,代碼行數:17,代碼來源:dataset.py


注:本文中的sqlalchemy.sql.expression.or_方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。