Did I find the right examples for you? yes no

All Samples(3)  |  Call(2)  |  Derive(0)  |  Import(1)
Given parsed_query and max_timestamp, find the resulting ItemVersion ids,
in the right order.

        def query_itemversions(session, model, parsed_query, max_timestamp=None):
    """Given parsed_query and max_timestamp, find the resulting ItemVersion ids,
    in the right order."""

    from sqlalchemy.sql import select, and_, or_, not_, func

    # find view ordering
    view_orderings = (session.query(ViewOrdering)

    if view_orderings:
        have_view_ordering = len(view_orderings[0].entries) != 0
        have_view_ordering = False

    # compose base set: the current versions of all items
    from_obj = get_current_itemversions_join(model, max_timestamp)

    if have_view_ordering:
        # if we have an ordering, we must also join the viewordering_entries table
        # so we can order by weight

        vo_entries = (

        from_obj = from_obj.outerjoin(vo_entries,

    from synoptic.datamodel import SQLifyQueryVisitor
    visitor = SQLifyQueryVisitor(session)

    conditions = [
            model.itemversions.c.contents != None,

    if visitor.use_hide_until:
        from time import time
                or_(ItemVersion.hide_until < time(),
                    ItemVersion.hide_until == None))

    where = and_(*conditions)

    result = select([model.itemversions], from_obj=[from_obj]).where(where)

    if visitor.sort_by_date:
        result = result.order_by(ItemVersion.start_date)
    elif have_view_ordering:
        # add the ordering clause
        result = result.order_by(vo_entries.c.weight)
        result = result.order_by(model.itemversions.c.timestamp.desc())

    return result.group_by(model.itemversions.c.item_id)

src/s/y/synoptic-2013.1/synoptic/__init__.py   synoptic(Download)
from synoptic.datamodel import \
        Item, ItemVersion, Tag, ViewOrdering, ViewOrderingEntry, \
        store_itemversion,  \
        get_current_itemversions_join, \
                    session, model, parsed_query, max_timestamp)))
    def get_json_items(self, session, model, parsed_query, max_timestamp):
        if parsed_query is not None:
            itemversions_q = query_itemversions(session, model,
                    parsed_query, max_timestamp)