예제 #1
0
def get_all_new_orders():
    session = Db.instance().session
    # First we create a subquery for retrieving the last state of each order
    subquery = session.query(Order_state.order_id, func.max(
        Order_state.date)).group_by(Order_state.order_id).subquery()
    # Filter orders by checking which ones have a last state with state 0
    return Order().queryObject().join(Order_state).filter(
        and_(
            tuple_(Order_state.order_id, Order_state.date).in_(subquery),
            Order_state.state == Order_state._STATES[0])).order_by(
                desc(Order_state.date)).all()
예제 #2
0
def get_all_new_orders():
    session = Db.instance().session
    # First we create a subquery for retrieving the last state of each order
    subquery = session.query(
        Order_state.order_id, func.max(Order_state.date)
    ).group_by(Order_state.order_id).subquery()
    # Filter orders by checking which ones have a last state with state 0
    return Order().queryObject().join(Order_state).filter(and_(
        tuple_(Order_state.order_id, Order_state.date).in_(subquery),
        Order_state.state == Order_state._STATES[0])).order_by(
        desc(Order_state.date)).all()
예제 #3
0
def get_all_orders(email=None):
    session = Db.instance().session
    # Create subquery for retrieving the last state of each order
    subquery = session.query(Order_state.order_id, func.max(
        Order_state.date)).group_by(Order_state.order_id).subquery()
    if email != None:
        return Order().queryObject().join(Order_state).filter(and_(
        tuple_(Order_state.order_id, Order_state.date).in_(subquery),
        Order.user.has(email=email))).order_by(Order_state.state,\
        desc(Order_state.date)).all()
    else:
        return Order().queryObject().join(Order_state).filter(
        tuple_(Order_state.order_id, Order_state.date).in_(subquery)).\
        order_by(Order_state.state, desc(Order_state.date)).all()
예제 #4
0
def get_all_orders(email=None):
    session = Db.instance().session
    # Create subquery for retrieving the last state of each order
    subquery = session.query(
        Order_state.order_id, func.max(Order_state.date)
    ).group_by(Order_state.order_id).subquery()
    if email != None:
        return Order().queryObject().join(Order_state).filter(and_(
        tuple_(Order_state.order_id, Order_state.date).in_(subquery),
        Order.user.has(email=email))).order_by(Order_state.state,\
        desc(Order_state.date)).all()
    else:
        return Order().queryObject().join(Order_state).filter(
        tuple_(Order_state.order_id, Order_state.date).in_(subquery)).\
        order_by(Order_state.state, desc(Order_state.date)).all()
예제 #5
0
def get_all_processed_orders(login=None):
    session = Db.instance().session
    # Create subquery for retrieving the last state of each order
    subquery = session.query(
        Order_state.order_id, func.max(Order_state.date)
    ).group_by(Order_state.order_id).subquery()
    if login != None:
        return Order().queryObject().join(Order_state).filter(and_(
        tuple_(Order_state.order_id, Order_state.date).in_(subquery),
        Order.user.has(login=login), Order_state.state == Order_state._STATES
        [len(Order_state._STATES) - 1])).order_by(Order_state.state,\
        desc(Order_state.date)).all()
    else:
        return Order().queryObject().join(Order_state).filter(and_(
        tuple_(Order_state.order_id, Order_state.date).in_(subquery)),
        Order_state.state == Order_state._STATES[len(Order_state._STATES)\
        - 1]).order_by(Order_state.state, desc(Order_state.date)).all()
예제 #6
0
class Entity():

    session = Db.instance().session
    srid = Config.get_string_value('config.viewer_proj')
    '''

    This is a baseclass with delivers all basic database operations

    '''
    def save(self):

        self.session.add(self)

        self.session.flush()

    def saveMultiple(self, objects=[]):

        self.session.add_all(objects)

        self.session.flush()

    def update(self):

        self.session.merge(self)

        self.session.flush()

    def delete(self):

        self.session.delete(self)

        self.session.flush()

    def queryObject(self):

        return self.session.query(self.__class__)