• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python elements.and_函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sqlalchemy.sql.elements.and_函数的典型用法代码示例。如果您正苦于以下问题:Python and_函数的具体用法?Python and_怎么用?Python and_使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了and_函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: update_deployments

def update_deployments(refdes, dnum, uid, launch, recover, lat, lon, cruise, depth, session):
    # print
    # print
    # print refdes, dnum, uid, launch, recover, lat, lon, cruise, depth
    deployments = session.query(Deployment).filter(and_(Deployment.sensor_uid == uid,
                                                        Deployment.deployment == dnum)).all()

    deployments += session.query(Deployment).filter(and_(Deployment.mooring_uid == uid,
                                                         Deployment.deployment == dnum)).all()

    # for each in deployments:
    #     print 'depl', each

    if deployments:
        for d in deployments:
            d.launch_date = launch
            d.recover_date = recover
            d.latitude = lat
            d.longitude = lon
            d.cruise = cruise
            d.depth = depth
            session.add(d)

    else:
        d = Deployment(refdes=refdes, deployment=dnum, launch_date=launch, recover_date=recover,
                       latitude=lat, longitude=lon, cruise=cruise, depth=depth, mooring_uid=uid)
        session.add(d)

    session.flush()
开发者ID:danmergens,项目名称:asset-management,代码行数:29,代码来源:create_db.py


示例2: get_advanced_search_query

def get_advanced_search_query(employer_id, params, status):
    skills = params.get('skills')
    locations = params.get('locations')
    role = params.get('role')
    name = params.get('name')
    salary = params.get('salary')

    query = DBSession.query(Candidate.id).filter(Candidate.status == status)

    if employer_id:
        query = query.outerjoin(V_CANDIDATE_CURRENT_EMPLOYERS,
                                and_(V_CANDIDATE_CURRENT_EMPLOYERS.c.candidate_id == Candidate.id,
                                     V_CANDIDATE_CURRENT_EMPLOYERS.c.employer_id == employer_id)) \
            .filter(V_CANDIDATE_CURRENT_EMPLOYERS.c.candidate_id == None)

    if locations:
        query = query.join(PreferredLocation, Candidate.id == PreferredLocation.candidate_id)

        country_filter = set([c['country_iso'] for c in locations])
        city_filter = [and_(City.name == loc['city'], City.country_iso == loc['country_iso']) for loc in locations]
        city_ids = DBSession.query(City.id).filter(or_(*city_filter)).all()

        query = query.filter(or_(PreferredLocation.city_id.in_(city_ids),
                                 PreferredLocation.country_iso.in_(country_filter)))

    if salary or role:
        query = query.join(TargetPosition)
        if salary:
            query = query.filter(TargetPosition.minimum_salary <= salary)
        if role:
            role = get_by_name_or_raise(Role, role)
            query = query.filter(TargetPosition.role_id == role.id)

    if name and employer_id:
        name = name.lower()
        employer_ids = func.array_agg(Offer.employer_id, type_=ARRAY(TEXT)).label('employer_ids')
        offer_query = DBSession.query(Offer.candidate_id, employer_ids).filter(Offer.accepted != None) \
            .group_by(Offer.candidate_id).subquery()
        query = query.outerjoin(offer_query, offer_query.c.candidate_id == Candidate.id).filter(
            or_(cast(Candidate.id, TEXT).startswith(name),
                and_(
                    or_(func.lower(Candidate.first_name).startswith(name),
                        func.lower(Candidate.last_name).startswith(name)),
                    or_(
                        offer_query.c.employer_ids.any(str(employer_id)),
                        Candidate.anonymous == False
                    )
                )
            )
        )

    query = query.group_by(Candidate.id)

    if skills:
        query = query.join(CandidateSkill).join(Skill).filter(Skill.name.in_(skills)) \
            .having(func.count(Skill.name) == len(skills))
    return query
开发者ID:iwein,项目名称:temp,代码行数:57,代码来源:services.py


示例3: _entry_query

    def _entry_query(self, session, entry):
        db_entry = session.query(EntryListEntry).filter(and_(
            EntryListEntry.list_id == self._db_list(session).id,
            or_(
                EntryListEntry.title == entry['title'], and_(
                    EntryListEntry.original_url,
                    EntryListEntry.original_url == entry[
                        'original_url'])))).first()

        return db_entry
开发者ID:AnthonyGuerreiro,项目名称:Flexget,代码行数:10,代码来源:entry_list.py


示例4: _to_bool_clause

def _to_bool_clause(constraint):
    if constraint is not None:
        if isinstance(constraint, dict):
            return and_(column(k) == v for k, v in constraint.items())
        else:
            return or_(and_(_convert_predicate(predicate)
                            for predicate in conjunction_clause)
                       for conjunction_clause in constraint)
    else:
        return text('')
开发者ID:Greyvend,项目名称:pyro,代码行数:10,代码来源:db.py


示例5: filter_query_for_content_label_as_path

    def filter_query_for_content_label_as_path(
            self,
            query: Query,
            content_label_as_file: str,
            is_case_sensitive: bool = False,
    ) -> Query:
        """
        Apply normalised filters to found Content corresponding as given label.
        :param query: query to modify
        :param content_label_as_file: label in this
        FILE version, use Content.get_label_as_file().
        :param is_case_sensitive: Take care about case or not
        :return: modified query
        """
        file_name, file_extension = os.path.splitext(content_label_as_file)

        label_filter = Content.label == content_label_as_file
        file_name_filter = Content.label == file_name
        file_extension_filter = Content.file_extension == file_extension

        if not is_case_sensitive:
            label_filter = func.lower(Content.label) == \
                           func.lower(content_label_as_file)
            file_name_filter = func.lower(Content.label) == \
                               func.lower(file_name)
            file_extension_filter = func.lower(Content.file_extension) == \
                                    func.lower(file_extension)

        return query.filter(or_(
            and_(
                Content.type == ContentType.File,
                file_name_filter,
                file_extension_filter,
            ),
            and_(
                Content.type == ContentType.Thread,
                file_name_filter,
                file_extension_filter,
            ),
            and_(
                Content.type == ContentType.Page,
                file_name_filter,
                file_extension_filter,
            ),
            and_(
                Content.type == ContentType.Folder,
                label_filter,
            ),
        ))
开发者ID:buxx,项目名称:tracim,代码行数:49,代码来源:content.py


示例6: __real_base_query

    def __real_base_query(self, workspace: Workspace=None):
        result = self.get_canonical_query()

        # Exclude non displayable types
        if not self._force_show_all_types:
            result = result.filter(Content.type.in_(self.DISPLAYABLE_CONTENTS))

        if workspace:
            result = result.filter(Content.workspace_id==workspace.workspace_id)

        # Security layer: if user provided, filter
        # with user workspaces privileges
        if self._user and not self._disable_user_workspaces_filter:
            user = DBSession.query(User).get(self._user_id)
            # Filter according to user workspaces
            workspace_ids = [r.workspace_id for r in user.roles \
                             if r.role>=UserRoleInWorkspace.READER]
            result = result.filter(or_(
                Content.workspace_id.in_(workspace_ids),
                # And allow access to non workspace document when he is owner
                and_(
                    Content.workspace_id == None,
                    Content.owner_id == self._user_id,
                )
            ))

        return result
开发者ID:buxx,项目名称:tracim,代码行数:27,代码来源:content.py


示例7: _find_entry

 def _find_entry(self, entry, session=None):
     """Finds `MovieListMovie` corresponding to this entry, if it exists."""
     for id_name in SUPPORTED_IDS:
         if entry.get(id_name):
             log.debug('trying to match movie based off id %s: %s', id_name, entry[id_name])
             res = (self._db_list(session).movies.join(MovieListMovie.ids).filter(
                 and_(
                     MovieListID.id_name == id_name,
                     MovieListID.id_value == entry[id_name]))
                    .first())
             if res:
                 log.debug('found movie %s', res)
                 return res
     # Fall back to title/year match
     if entry.get('movie_name') and entry.get('movie_year'):
         name, year = entry['movie_name'], entry['movie_year']
     else:
         name, year = split_title_year(entry['title'])
     if not name:
         log.verbose('no movie name to match, skipping')
         return
     log.debug('trying to match movie based of name: %s and year: %d', name, year)
     res = (self._db_list(session).movies.filter(func.lower(MovieListMovie.title) == name.lower())
            .filter(MovieListMovie.year == year).first())
     if res:
         log.debug('found movie %s', res)
     return res
开发者ID:kevmegforest,项目名称:Flexget,代码行数:27,代码来源:movie_list.py


示例8: get_movie_by_id

def get_movie_by_id(list_id, movie_id, session=None):
    log.debug('fetching movie with id %d from list id %d', movie_id, list_id)
    return (
        session.query(MovieListMovie)
        .filter(and_(MovieListMovie.id == movie_id, MovieListMovie.list_id == list_id))
        .one()
    )
开发者ID:Flexget,项目名称:Flexget,代码行数:7,代码来源:db.py


示例9: value_combo_exists

def value_combo_exists(value, **kwargs):
    """ Queries the database for any values in the unique store that alrdeady exist with given value and metadata combo
    """
    kwargs['unique_value'] = {kwargs['field_name']: value}
    del kwargs['field_name']
    filters = [(getitem(Unique, arg_name) == arg_val) for arg_name, arg_val in kwargs.items()]
    return DB.session.query(Unique.query.exists().where(and_(*filters))).scalar()
开发者ID:tresbailey,项目名称:towsack,代码行数:7,代码来源:unique.py


示例10: get_entry_by_id

def get_entry_by_id(list_id, entry_id, session=None):
    log.debug('fetching entry with id %d from list id %d', entry_id, list_id)
    return (
        session.query(EntryListEntry)
        .filter(and_(EntryListEntry.id == entry_id, EntryListEntry.list_id == list_id))
        .one()
    )
开发者ID:Flexget,项目名称:Flexget,代码行数:7,代码来源:db.py


示例11: _entry_query

 def _entry_query(self, session, entry, approved=None):
     query = session.query(PendingListEntry).filter(PendingListEntry.list_id == self._db_list(session).id). \
         filter(or_(PendingListEntry.title == entry['title'],
                    and_(PendingListEntry.original_url, PendingListEntry.original_url == entry['original_url'])))
     if approved:
         query = query.filter(PendingListEntry.approved == True)
     return query.first()
开发者ID:BackSlasher,项目名称:Flexget,代码行数:7,代码来源:pending_list.py


示例12: _find_entry

 def _find_entry(self, entry, session=None):
     """Finds `MovieListMovie` corresponding to this entry, if it exists."""
     for id_name in MovieListBase().supported_ids:
         if entry.get(id_name):
             log.verbose('trying to match movie based off id %s: %s', id_name, entry[id_name])
             res = (self._db_list(session).movies.join(MovieListMovie.ids).filter(
                 and_(
                     MovieListID.id_name == id_name,
                     MovieListID.id_value == entry[id_name]))
                    .first())
             if res:
                 log.verbose('found movie %s', res)
                 return res
     # Fall back to title/year match
     if not entry.get('movie_name'):
         self._parse_title(entry)
     if entry.get('movie_name'):
         name = entry['movie_name']
         year = entry.get('movie_year') if entry.get('movie_year') else None
     else:
         log.warning('Could not get a movie name, skipping')
         return
     log.verbose('trying to match movie based of name: %s and year: %s', name, year)
     res = (self._db_list(session).movies.filter(func.lower(MovieListMovie.title) == name.lower())
            .filter(MovieListMovie.year == year).first())
     if res:
         log.verbose('found movie %s', res)
     return res
开发者ID:AlinaKay,项目名称:Flexget,代码行数:28,代码来源:movie_list.py


示例13: find_deployment

def find_deployment(refdes, deployment):
    # print 'find_deployment(%r, %r)' % (refdes, deployment)
    # attempt to find an exact match
    record = session.query(Deployment).filter(and_(Deployment.refdes == refdes,
                                                   Deployment.deployment == deployment)).first()
    if record:
        # print 'found exact'
        return record

    parts = refdes.split('-', 2)
    mooring = parts[0]
    node = None
    if len(parts) > 1:
        node = parts[1]

    # no exact match, attempt to find the node
    if node is not None:
        record = session.query(Deployment).filter(Deployment.refdes == '-'.join((mooring, node))).first()
        if record:
            # print 'found node'
            return record

    # no node, find the mooring
    record = session.query(Deployment).filter(Deployment.refdes == mooring).first()
    # if record:
    #     print 'found mooring'
    return record
开发者ID:danmergens,项目名称:asset-management,代码行数:27,代码来源:make_deploy.py


示例14: get_questions

def get_questions(connection: Connection,
                  survey_id: str,
                  auth_user_id: [str, None]=None,
                  email: [str, None]=None) -> ResultProxy:
    """
    Get all the questions for a survey identified by survey_id ordered by
    sequence number restricted by auth_user.

    :param connection: a SQLAlchemy Connection
    :param survey_id: the UUID of the survey
    :param auth_user_id: the UUID of the user
    :param email: the user's e-mail address
    :return: an iterable of the questions (RowProxy)
    """

    table = question_table.join(survey_table)
    conds = [question_table.c.survey_id == survey_id]

    if auth_user_id is not None:
        if email is not None:
            raise TypeError('You cannot specify both auth_user_id and email')
        conds.append(survey_table.c.auth_user_id == auth_user_id)
    elif email is not None:
        table = table.join(auth_user_table)
        conds.append(auth_user_table.c.email == email)
    else:
        raise TypeError('You must specify either auth_user_id or email')

    questions = connection.execute(
        select([question_table]).select_from(table).where(
            and_(*conds)).order_by('sequence_number asc'))
    return questions
开发者ID:juniorsilver,项目名称:dokomoforms,代码行数:32,代码来源:question.py


示例15: get_users_with_filters

def get_users_with_filters(*filters):
    general_filters = [User.login_enabled == True,
                       User.roles_rel.any(
                           and_(RoleXUser.role_name == RolesTypes.founder, RoleXUser.is_primary == True))]
    notif_filters = filters[0]
    if len(filters) > 1:
        notif_filters = or_(*filters)
    return DBSession.query(User).filter(*(general_filters + [notif_filters])).all()
开发者ID:RaHus,项目名称:portal,代码行数:8,代码来源:emails.py


示例16: get_movie_identifier

def get_movie_identifier(identifier_name, identifier_value, movie_id=None, session=None):
    db_movie_id = session.query(MovieListID).filter(
        and_(MovieListID.id_name == identifier_name,
             MovieListID.id_value == identifier_value,
             MovieListID.movie_id == movie_id)).first()
    if db_movie_id:
        log.debug('fetching movie identifier %s: %s', db_movie_id.id_name, db_movie_id.id_value)
        return db_movie_id
开发者ID:AlinaKay,项目名称:Flexget,代码行数:8,代码来源:movie_list.py


示例17: get_entry_by_title

def get_entry_by_title(list_id, title, session=None):
    entry_list = get_list_by_id(list_id=list_id, session=session)
    if entry_list:
        return (
            session.query(EntryListEntry)
            .filter(and_(EntryListEntry.title == title, EntryListEntry.list_id == list_id))
            .first()
        )
开发者ID:Flexget,项目名称:Flexget,代码行数:8,代码来源:db.py


示例18: get_movie_by_title

def get_movie_by_title(list_id, title, session=None):
    movie_list = get_list_by_id(list_id=list_id, session=session)
    if movie_list:
        log.debug('searching for movie %s in list %d', title, list_id)
        return session.query(MovieListMovie).filter(
            and_(
                func.lower(MovieListMovie.title) == title.lower(),
                MovieListMovie.list_id == list_id)
        ).first()
开发者ID:AlinaKay,项目名称:Flexget,代码行数:9,代码来源:movie_list.py


示例19: delete

def delete(id):
    user = g.user
    post = models.Post.query.filter(and_(models.Post.id == id ,models.Post.author == user)).all()
    if post == None :
        flash('Post not found')
        return redirect(url_for('index'))
    db.session.delete(post[0])
    db.session.commit()
    flash('Your post has been delete')
    return redirect(url_for('managerpost'))
开发者ID:liubbn,项目名称:flask_web,代码行数:10,代码来源:views.py


示例20: list

    def list(self):
        candidate_count = func.count(Candidate.id).label("candidate_count")
        last_used = func.max(Candidate.created).label("last_used")
        codes_query = DBSession.query(InviteCode.code, InviteCode.description, InviteCode.created, candidate_count,
                                      last_used).outerjoin(Candidate, and_(Candidate.invite_code_id == InviteCode.id)) \
            .group_by(InviteCode.code, InviteCode.description, InviteCode.created)

        def serializer(result):
            return [r._asdict() for r in result]

        return run_paginated_query(self.request, codes_query, serializer=serializer)
开发者ID:iwein,项目名称:temp,代码行数:11,代码来源:views.py



注:本文中的sqlalchemy.sql.elements.and_函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python elements.quoted_name函数代码示例发布时间:2022-05-27
下一篇:
Python sql.update函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap