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

Python util.aliased函数代码示例

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

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



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

示例1: search_user_checkpoints

def search_user_checkpoints(user_obj, search_term):
    """
    Searches both my UserCheckpoints and my friends' with a literal search term.
    Searches a Checkpoint's name, description, and User's (Facebook) name (union)
    """
    from db import UserCheckpoint, db, FacebookUser, User, FriendConnection, Checkpoint
    search_term_with_wildcard = "%"+search_term+"%"
    
    #query that contain my own and my friends' usercheckpoints
    FriendUserCheckpoint, FriendFacebookUser, FriendUser = aliased(UserCheckpoint), aliased(FacebookUser), aliased(User)
    ucp = (db.session.query(UserCheckpoint).
           join(Checkpoint, Checkpoint.id == UserCheckpoint.checkpoint_id).
           join(FriendUser, FriendUser.id == UserCheckpoint.user_id).
           join(FriendFacebookUser, FriendFacebookUser.id == FriendUser.facebook_user_id).
           join(FriendConnection, FriendConnection.fb_user_to == FriendFacebookUser.id).
           join(FacebookUser, FacebookUser.id == FriendConnection.fb_user_from).
           join(User, User.facebook_user_id == FacebookUser.id).
           filter(or_(User.id == user_obj.id, FriendUser.id == user_obj.id)).
           filter(Checkpoint.demo == False)        
           )
    
    name_search = ucp.filter(Checkpoint.name.ilike(search_term_with_wildcard))
    desc_search = ucp.filter(Checkpoint.description.ilike(search_term_with_wildcard))
    fb_name_search = ucp.filter(FriendFacebookUser.name.ilike(search_term_with_wildcard))
    
    result = name_search.union(desc_search).union(fb_name_search)
    
    return result.all()
开发者ID:nubela,项目名称:spawt-backend,代码行数:28,代码来源:user_checkpoint.py


示例2: unwanted_list

def unwanted_list(request):
    who = aliased(User, name="who")
    by = aliased(User, name="by")
    a = DBSession.query(UnWanted, who, by). \
        join(who, UnWanted.user).join(by, UnWanted.by_user). \
        all()
    a = obj_list_join(a, ['', 'user_', 'by_'])
    return {'unwanted': a}
开发者ID:umar93132,项目名称:portal,代码行数:8,代码来源:unwanted.py


示例3: rolesForRbacSQL

    def rolesForRbacSQL(self, rbacId, sql=None):
        """
        @see: IRbacService.rolesForRbacSQL
        """
        child, parent = aliased(RoleNode), aliased(RoleNode)

        sql = sql or self.session().query(RoleMapped)
        sql = sql.join(child, child.role == RoleMapped.Id)
        sql = sql.join(parent, and_(child.left >= parent.left, child.right <= parent.right))
        sql = sql.join(RbacRole, and_(RbacRole.role == parent.role, RbacRole.rbac == rbacId))

        return sql
开发者ID:petrjasek,项目名称:Ally-Py,代码行数:12,代码来源:rbac_service.py


示例4: __init__

 def __init__(self, Acl, AclAccess, Compensate, signatures=None):
     '''
     Construct the compensate service alchemy.
     
     @param AclAccess: class of WithAclAccess
         The ACL access relation mapped class.
     @param Compensate: class of WithCompensate
         The compensate relation mapped class.
     @param signatures: dictionary{string: string|callable(identifier) -> string}
         A dictionary containing as keys the signatures that will be injected and as a value either the marker to be injected
         or a callable that takes the identifier as a parameter and provides the marker string value.
     '''
     assert isinstance(Acl, MappedSupport), 'Invalid mapped class %s' % Acl
     assert issubclass(AclAccess, WithAclAccess), 'Invalid acl access class %s' % AclAccess
     assert issubclass(Compensate, WithCompensate), 'Invalid compensate class %s' % Compensate
     if __debug__:
         if signatures is not None:
             assert isinstance(signatures, dict), 'Invalid fill in signatures %s' % signatures
             for signature, marker in signatures.items():
                 assert isinstance(signature, str), 'Invalid signature %s' % signature
                 assert isinstance(marker, str) or callable(marker), 'Invalid marker %s' % marker
     
     self.Acl = Acl
     self.AclIdentifier = modelId(Acl)
     self.AclAccess = AclAccess
     self.AliasAclAccess = aliased(AclAccess)
     self.Compensate = Compensate
     
     self.signatures = signatures
开发者ID:cristidomsa,项目名称:Ally-Py,代码行数:29,代码来源:compensate.py


示例5: date

def date(date, latest=False):
    try:
        if isinstance(date, (str, unicode)):
            date = datetime.strptime(date, "%Y-%m-%d")

        if isinstance(date, datetime):
            date = date.date()

    except:
        abort(404)

    pilot_alias = aliased(User, name='pilot')

    columns = {
        0: (Flight, 'index_score'),
        1: (pilot_alias, 'name'),
        2: (Flight, 'olc_classic_distance'),
        3: (Airport, 'name'),
        4: (Club, 'name'),
        5: (AircraftModel, 'name'),
        6: (Flight, 'takeoff_time'),
        7: (Flight, 'id'),
        8: (Flight, 'num_comments'),
    }

    return _create_list(
        'latest' if latest else 'date',
        request.args, date=date, columns=columns)
开发者ID:bbonamin,项目名称:Skylines,代码行数:28,代码来源:flights.py


示例6: rank

 def rank(self):
     inner_team = aliased(Team)
     return (DBSession.query(func.count('*') + 1).
             select_from(inner_team).
             filter(inner_team.score > Team.score).
             correlate(Team).
             label('rank'))
开发者ID:Immortalem,项目名称:fluxscoreboard,代码行数:7,代码来源:team.py


示例7: date

    def date(self, date, **kw):
        try:
            if isinstance(date, str):
                date = datetime.strptime(date, "%Y-%m-%d")

            if isinstance(date, datetime):
                date = date.date()
        except:
            raise HTTPNotFound

        pilot_alias = aliased(User, name='pilot')

        columns = {
            0: (Flight, 'index_score'),
            1: (pilot_alias, 'display_name'),
            2: (Flight, 'olc_classic_distance'),
            3: (Airport, 'name'),
            4: (Club, 'name'),
            5: (AircraftModel, 'name'),
            6: (Flight, 'takeoff_time'),
            7: (Flight, 'id'),
            8: (Flight, 'num_comments'),
        }

        if kw.get('today', False):
            return self.__do_list('today', kw, date=date, columns=columns)
        else:
            return self.__do_list('date', kw, date=date, columns=columns)
开发者ID:citterio,项目名称:Skylines,代码行数:28,代码来源:flights.py


示例8: getOriginalSource

    def getOriginalSource(self, source):
        originalSource = aliased(SourceMapped, name="original_source")

        sql = self.session().query(originalSource)
        sql = sql.join(SourceMapped, originalSource.URI == SourceMapped.OriginURI)
        sql = sql.filter(SourceMapped.Id == source)

        return sql.one().Id
开发者ID:robchrstr,项目名称:Superdesk,代码行数:8,代码来源:source.py


示例9: get_data

    def get_data(self):
        logging.debug("These queries will take a few mins to run.")

        budget_query = self.session.query(
            self.models.MovieInfo.movie_id,
            func.max(
                cast(
                    func.replace(
                        func.replace(self.models.MovieInfo.info, ",", ""),
                        "$", ""),
                    types.Numeric)
            ).label('budget')
        ).filter(
            self.models.MovieInfo.movie_id.in_(self.movie_ids),
            self.models.MovieInfo.info_type_id.in_([BUDGET_TYPE_ID]),
            self.models.MovieInfo.info.like('$%'),
        ).group_by(self.models.MovieInfo.movie_id
        ).subquery()

        year_query = self.session.query(
            self.models.MovieInfo.movie_id,
            func.min(
                func.substr(self.models.MovieInfo.info, -4)
            ).label('release_year')
        ).filter(
            self.models.MovieInfo.movie_id.in_(self.movie_ids),
            self.models.MovieInfo.info_type_id.in_([RELEASE_DATES_ID]),
            self.models.MovieInfo.info.like('USA:%')
        ).group_by(self.models.MovieInfo.movie_id
        ).subquery()

        budget_alias = aliased(self.models.MovieInfo, budget_query)
        year_alias = aliased(self.models.MovieInfo, year_query)

        return self.session.query(
            budget_query.columns.movie_id,
            budget_query.columns.budget,
            year_query.columns.release_year
        ).join(
            year_alias, year_alias.movie_id == budget_alias.movie_id
        ).distinct(
            self.models.MovieInfo.movie_id
        ).filter(
            self.models.MovieInfo.movie_id.in_(self.movie_ids),
        )
开发者ID:beets,项目名称:cs221-project,代码行数:45,代码来源:standardized_budget.py


示例10: __init__

 def __init__(self, db="", sql_logging=False, schema=None):
     if db == "" or db is None:
         # In-memory SQLite
         connect_url = "sqlite:///"
     if "://" in db:
         # User has provided a full path
         connect_url = db
     else:
         # Assume a SQLite file
         connect_url = "sqlite:///%s" % db
     engine = sqlalchemy.create_engine(connect_url, echo=sql_logging)
     self._orm = _Orm(engine, schema=schema)
     Session = sessionmaker(bind=engine)
     self._session = Session()
     self._stoptime1 = aliased(StopTime, name="first_stop_time")
     self._stoptime2 = aliased(StopTime, name="second_stop_time")
     self._transfer_fromstop = aliased(Stop, name="tr_from_stop")
     self._transfer_tostop = aliased(Stop, name="tr_to_stop")
开发者ID:pailakka,项目名称:gtfslib-python,代码行数:18,代码来源:dao.py


示例11: rightsForRbacSQL

    def rightsForRbacSQL(self, rbacId, sql=None):
        """
        @see: IRbacService.rightsForRbacSQL
        """
        child, parent = aliased(RoleNode), aliased(RoleNode)

        subq = sql or self.session().query(RightMapped)
        subq = subq.join(RbacRight, RbacRight.right == RightMapped.Id)
        subq = subq.join(child, child.role == RbacRight.rbac)
        subq = subq.join(parent, and_(child.left >= parent.left, child.right <= parent.right))
        subq = subq.join(RbacRole, and_(RbacRole.role == parent.role, RbacRole.rbac == rbacId))

        sql = sql or self.session().query(RightMapped)
        sql = sql.join(RbacRight, and_(RbacRight.right == RightMapped.Id, RbacRight.rbac == rbacId))

        sql = sql.union(subq).distinct(RightMapped.Id).order_by(RightMapped.Id)

        return sql
开发者ID:petrjasek,项目名称:Ally-Py,代码行数:18,代码来源:rbac_service.py


示例12: getUnpublishedBySource

    def getUnpublishedBySource(self, sourceId, thumbSize=None, offset=None, limit=None, detailed=False, q=None):
        '''
        @see: IBlogPostService.getUnpublished
        '''
        assert q is None or isinstance(q, QBlogPostUnpublished), 'Invalid query %s' % q
        
        postVerification = aliased(PostVerificationMapped, name='post_verification_filter')
              
        sql = self.session().query(BlogPostMapped)
        sql = sql.filter(BlogPostMapped.Feed == sourceId)
        
        deleted = False
        if q:
            if QBlogPostUnpublished.isDeleted in q:
                deleted = q.isDeleted.value                
            sql = buildQuery(sql, q, BlogPostMapped)
        
        if q:
            if QWithCId.search in q:
                all = self._processLike(q.search.ilike) if q.search.ilike is not None else self._processLike(q.search.like)
                sql = sql.filter(or_(BlogPostMapped.Meta.ilike(all), BlogPostMapped.CreatedOn.ilike(all), \
                                     BlogPostMapped.Content.ilike(all), BlogPostMapped.ContentPlain.ilike(all), \
                                     ))
                
            if QWithCId.status in q or QWithCId.checker in q:
                sql = sql.join(postVerification, postVerification.Id == BlogPostMapped.Id)     
                sql = sql.join(VerificationStatusMapped, VerificationStatusMapped.id == postVerification.statusId) 
                
            if QWithCId.status in q: 
                sql = sql.filter(VerificationStatusMapped.Key == q.status.equal) 
                
            if QWithCId.checker in q: 
                sql = sql.filter(postVerification.Checker == q.checker.equal)
                
            if (QWithCId.cId not in q) or (QWithCId.cId in q and QWithCId.cId.start not in q \
               and QWithCId.cId.end not in q and QWithCId.cId.since not in q and QWithCId.cId.until not in q):
                
                sql = sql.filter(BlogPostMapped.PublishedOn == None) 
                if deleted: sql = sql.filter(BlogPostMapped.DeletedOn != None)
                else: sql = sql.filter(BlogPostMapped.DeletedOn == None)
                
        else: sql = sql.filter((BlogPostMapped.PublishedOn == None) & (BlogPostMapped.DeletedOn == None))     
                                   
        sql = sql.order_by(desc_op(BlogPostMapped.Order))
        sqlLimit = buildLimits(sql, offset, limit)
 
        posts = self._addImages(self._trimPosts(sqlLimit.distinct(), deleted= not deleted, unpublished=False, published=True), thumbSize)
        if detailed:
            posts = IterPost(posts, sql.distinct().count(), offset, limit)
            
            lastCidSql = self.session().query(func.MAX(BlogPostMapped.CId))
            lastCidSql = lastCidSql.join(CollaboratorMapped, BlogPostMapped.Creator == CollaboratorMapped.User)
            lastCidSql = lastCidSql.filter(CollaboratorMapped.Source == sourceId)
            
            posts.lastCId = lastCidSql.scalar()
            
        return posts
开发者ID:robchrstr,项目名称:Superdesk,代码行数:57,代码来源:blog_post.py


示例13: set_recent_outings

def set_recent_outings(waypoint, lang):
    """Set last 10 outings on routes associated to the given waypoint.
    """
    t_outing_route = aliased(Association, name="a1")
    t_route_wp = aliased(Association, name="a2")
    with_query_waypoints = _get_select_children(waypoint)

    recent_outing_ids = get_first_column(
        DBSession.query(Outing.document_id)
        .filter(Outing.redirects_to.is_(None))
        .join(t_outing_route, Outing.document_id == t_outing_route.child_document_id)
        .join(
            t_route_wp,
            and_(
                t_route_wp.child_document_id == t_outing_route.parent_document_id,
                t_route_wp.child_document_type == ROUTE_TYPE,
            ),
        )
        .join(with_query_waypoints, with_query_waypoints.c.document_id == t_route_wp.parent_document_id)
        .order_by(Outing.date_end.desc())
        .limit(NUM_RECENT_OUTINGS)
        .all()
    )

    total = (
        DBSession.query(Outing.document_id)
        .filter(Outing.redirects_to.is_(None))
        .join(t_outing_route, Outing.document_id == t_outing_route.child_document_id)
        .join(
            t_route_wp,
            and_(
                t_route_wp.child_document_id == t_outing_route.parent_document_id,
                t_route_wp.child_document_type == ROUTE_TYPE,
            ),
        )
        .join(with_query_waypoints, with_query_waypoints.c.document_id == t_route_wp.parent_document_id)
        .count()
    )

    waypoint.associations["recent_outings"] = get_documents_for_ids(
        recent_outing_ids, lang, outing_documents_config, total
    )
开发者ID:c2corg,项目名称:v6_api,代码行数:42,代码来源:waypoint.py


示例14: filter_query

        def filter_query(query):
            t_outing_route = aliased(Association, name='a1')
            t_route_wp = aliased(Association, name='a2')
            t_route = aliased(Document, name='r')

            return query. \
                join(
                    t_outing_route,
                    Outing.document_id == t_outing_route.child_document_id). \
                join(
                    t_route,
                    and_(
                        t_outing_route.parent_document_id ==
                        t_route.document_id,
                        t_route.type == ROUTE_TYPE)). \
                join(
                    t_route_wp,
                    and_(
                        t_route_wp.parent_document_id == waypoint_id,
                        t_route_wp.child_document_id == t_route.document_id))
开发者ID:arnaud-morvan,项目名称:v6_api,代码行数:20,代码来源:outing.py


示例15: get_recent_friend_user_checkpoints

def get_recent_friend_user_checkpoints(user_obj, limit = None):
    """
    (faux notification) returns Checkpoints that were recently created by friends
    """
    if limit == None:
        limit = 8
    
    from db import UserCheckpoint, db, FacebookUser, User, FriendConnection, Checkpoint
    
    FriendUserCheckpoint, FriendFacebookUser, FriendUser = aliased(UserCheckpoint), aliased(FacebookUser), aliased(User)
    q = (db.session.query(UserCheckpoint).
         join(Checkpoint, Checkpoint.id == UserCheckpoint.checkpoint_id).
         join(FriendUser, FriendUser.id == UserCheckpoint.user_id).
         join(FriendFacebookUser, FriendFacebookUser.id == FriendUser.facebook_user_id).
         join(FriendConnection, FriendConnection.fb_user_to == FriendFacebookUser.id).
         join(FacebookUser, FacebookUser.id == FriendConnection.fb_user_from).
         join(User, User.facebook_user_id == FacebookUser.id).
         filter(User.id == user_obj.id).
         filter(Checkpoint.creator == FriendUser.id).
         filter(Checkpoint.demo == False)
         )
    
    return q.order_by(desc(Checkpoint.date_created)).limit(limit).all()
开发者ID:nubela,项目名称:spawt-backend,代码行数:23,代码来源:user_checkpoint.py


示例16: get_friends

def get_friends(user_obj, exclude_self=None):
    """
    returns a list of <<User>> objects, if exclude_self is True, it will not consider the current
    user as a friend.
    """
    if exclude_self == None:
        exclude_self = False
    
    from db import db, User, FriendConnection, FacebookUser
    
    FriendFacebookUser, FriendUser = aliased(FacebookUser), aliased(User)
    friends_q = (db.session.query(User, FriendUser).
               join(FacebookUser, FacebookUser.id == User.facebook_user_id).
               join(FriendConnection, FriendConnection.fb_user_from == FacebookUser.id).
               join(FriendFacebookUser, FriendConnection.fb_user_to == FriendFacebookUser.id).
               join(FriendUser, FriendUser.facebook_user_id == FriendFacebookUser.id)
               )
    friends_q = friends_q.filter(User.id == user_obj.id)
    
    friends = [f[1] for f in friends_q.all()]
    if not exclude_self:
        friends += [user_obj]
    
    return friends
开发者ID:nubela,项目名称:spawt-backend,代码行数:24,代码来源:user.py


示例17: club

def club(id):
    club = get_requested_record(Club, id)
    pilot_alias = aliased(User, name='pilot')

    columns = {
        0: (Flight, 'date_local'),
        1: (Flight, 'index_score'),
        2: (pilot_alias, 'name'),
        3: (Flight, 'olc_classic_distance'),
        4: (Airport, 'name'),
        5: (AircraftModel, 'name'),
        6: (Flight, 'takeoff_time'),
        7: (Flight, 'id'),
        8: (Flight, 'num_comments'),
    }

    return _create_list('club', request.args, club=club, columns=columns)
开发者ID:bbonamin,项目名称:Skylines,代码行数:17,代码来源:flights.py


示例18: airport

    def airport(self, id, **kw):
        airport = get_requested_record(Airport, id)
        pilot_alias = aliased(User, name='pilot')

        columns = {
            0: (Flight, 'date_local'),
            1: (Flight, 'index_score'),
            2: (pilot_alias, 'display_name'),
            3: (Flight, 'olc_classic_distance'),
            4: (Club, 'name'),
            5: (AircraftModel, 'name'),
            6: (Flight, 'takeoff_time'),
            7: (Flight, 'id'),
            8: (Flight, 'num_comments'),
        }

        return self.__do_list('airport', kw, airport=airport, columns=columns)
开发者ID:citterio,项目名称:Skylines,代码行数:17,代码来源:flights.py


示例19: getUnpublished

    def getUnpublished(self, blogId, typeId=None, creatorId=None, authorId=None, thumbSize=None, offset=None, limit=None,
                       detailed=False, q=None):
        '''
        @see: IBlogPostService.getUnpublished
        '''
        assert q is None or isinstance(q, QBlogPostUnpublished), 'Invalid query %s' % q
        
        postVerification = aliased(PostVerificationMapped, name='post_verification_filter')
        
        sql = self._filterQuery(blogId, typeId, creatorId, authorId, q)

        deleted = False
        if q:
            if QBlogPostUnpublished.isDeleted in q:
                deleted = q.isDeleted.value  
                
            if QWithCId.cId in q and q.cId:
                sql = sql.filter(BlogPostMapped.CId != None)
            sql = buildQuery(sql, q, BlogPostMapped)
            
            if QWithCId.status in q or QWithCId.checker in q:
                sql = sql.join(postVerification, postVerification.Id == BlogPostMapped.Id)     
                sql = sql.join(VerificationStatusMapped, VerificationStatusMapped.id == postVerification.statusId) 
                
            if QWithCId.status in q: 
                sql = sql.filter(VerificationStatusMapped.Key == q.status.equal) 
                
            if QWithCId.checker in q: 
                sql = sql.filter(postVerification.Checker == q.checker.equal)
                
            if QWithCId.cId not in q:
                sql = sql.filter(BlogPostMapped.PublishedOn == None) 
                if deleted: sql = sql.filter(BlogPostMapped.DeletedOn != None)
                else: sql = sql.filter(BlogPostMapped.DeletedOn == None)
                
        else: sql = sql.filter((BlogPostMapped.PublishedOn == None) & (BlogPostMapped.DeletedOn == None))    

        sql = sql.order_by(desc_op(BlogPostMapped.Order))
        
        sqlLimit = buildLimits(sql, offset, limit)
        posts = self._addImages(self._trimPosts(sqlLimit.distinct(), unpublished=False, published=True), thumbSize)
        if detailed:
            posts = IterPost(posts, sql.distinct().count(), offset, limit)
            posts.lastCId = self.session().query(func.MAX(BlogPostMapped.CId)).filter(BlogPostMapped.Blog == blogId).scalar()
        return posts
开发者ID:robchrstr,项目名称:Superdesk,代码行数:45,代码来源:blog_post.py


示例20: pilot

def pilot(id):
    pilot = get_requested_record(User, id)
    pilot_alias = aliased(User, name='pilot')

    mark_flight_notifications_read(pilot)

    columns = {
        0: (Flight, 'date_local'),
        1: (Flight, 'index_score'),
        2: (pilot_alias, 'name'),
        3: (Flight, 'olc_classic_distance'),
        4: (Airport, 'name'),
        5: (AircraftModel, 'name'),
        6: (Flight, 'takeoff_time'),
        7: (Flight, 'id'),
        8: (Flight, 'num_comments'),
    }

    return _create_list('pilot', request.args, pilot=pilot, columns=columns)
开发者ID:bbonamin,项目名称:Skylines,代码行数:19,代码来源:flights.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python util.class_mapper函数代码示例发布时间:2022-05-27
下一篇:
Python sync.source_modified函数代码示例发布时间: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