示例#1
0
def get_associated_user_ids(xreport_id):
    associated_user_ids = get_first_column(
        DBSession.query(User.id).join(
            Association, Association.parent_document_id == User.id).filter(
                Association.child_document_id == xreport_id).group_by(
                    User.id).all())
    return associated_user_ids
示例#2
0
文件: waypoint.py 项目: c2corg/v6_api
def set_linked_routes(waypoint, lang):
    """
    Set associated routes for the given waypoint including associated routes
    of child and grandchild waypoints.
    Note that this function returns a dict and not a list!
    """
    with_query_waypoints = _get_select_children(waypoint)

    route_ids = get_first_column(
        DBSession.query(Route.document_id)
        .select_from(with_query_waypoints)
        .join(Association, with_query_waypoints.c.document_id == Association.parent_document_id)
        .join(Route, Association.child_document_id == Route.document_id)
        .filter(Route.redirects_to.is_(None))
        .order_by(with_query_waypoints.c.priority.desc(), Route.document_id.desc())
        .limit(NUM_ROUTES)
        .all()
    )

    total = (
        DBSession.query(Route.document_id)
        .select_from(with_query_waypoints)
        .join(Association, with_query_waypoints.c.document_id == Association.parent_document_id)
        .join(Route, Association.child_document_id == Route.document_id)
        .filter(Route.redirects_to.is_(None))
        .count()
    )

    waypoint.associations["all_routes"] = get_documents_for_ids(route_ids, lang, route_documents_config, total)
示例#3
0
def set_linked_routes(waypoint, lang):
    """
    Set associated routes for the given waypoint including associated routes
    of child and grandchild waypoints.
    Note that this function returns a dict and not a list!
    """
    with_query_waypoints = _get_select_children(waypoint)

    route_ids = get_first_column(
        DBSession.query(
            Route.document_id).select_from(with_query_waypoints).join(
                Association, with_query_waypoints.c.document_id ==
                Association.parent_document_id).join(
                    Route,
                    Association.child_document_id == Route.document_id).filter(
                        Route.redirects_to.is_(None)).order_by(
                            with_query_waypoints.c.priority.desc(),
                            Route.document_id.desc()).limit(NUM_ROUTES).all())

    total = DBSession.query(Route.document_id). \
        select_from(with_query_waypoints). \
        join(
            Association,
            with_query_waypoints.c.document_id ==
            Association.parent_document_id). \
        join(
            Route,
            Association.child_document_id == Route.document_id). \
        filter(Route.redirects_to.is_(None)). \
        count()

    waypoint.associations['all_routes'] = get_documents_for_ids(
        route_ids, lang, route_documents_config, total)
示例#4
0
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)
示例#5
0
文件: waypoint.py 项目: c2corg/v6_api
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
    )
示例#6
0
    def set_recent_outings(route, lang):
        """Set last 10 outings on the given route.
        """
        recent_outing_ids = get_first_column(
            DBSession.query(Outing.document_id).filter(
                Outing.redirects_to.is_(None)).join(
                    Association,
                    Outing.document_id == Association.child_document_id).
            filter(
                Association.parent_document_id == route.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(
                Association,
                Outing.document_id == Association.child_document_id). \
            filter(Association.parent_document_id == route.document_id). \
            count()

        route.associations['recent_outings'] = get_documents_for_ids(
            recent_outing_ids, lang, outing_documents_config, total)
示例#7
0
文件: route.py 项目: c2corg/v6_api
    def set_recent_outings(route, lang):
        """Set last 10 outings on the given route.
        """
        recent_outing_ids = get_first_column(
            DBSession.query(Outing.document_id).
            filter(Outing.redirects_to.is_(None)).
            join(
                Association,
                Outing.document_id == Association.child_document_id).
            filter(Association.parent_document_id == route.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(
                Association,
                Outing.document_id == Association.child_document_id). \
            filter(Association.parent_document_id == route.document_id). \
            count()

        route.associations['recent_outings'] = get_documents_for_ids(
            recent_outing_ids, lang, outing_documents_config, total)