def add_description(cls, _id, description): user = session.query(cls).filter(cls.id == int(_id)).update( {cls.description: description}) session.commit() return user
def admins_telegram_keys(cls): return { user.telegram_id: user.as_dict() for user in session.query(cls).filter(cls.admin).all() }
def delete(cls, _id): user = session.query(cls).filter(cls.id == int(_id)).update( {cls.deleted: True}) session.commit() return user
def first_paginate(cls, first=0, last=0): return PaginateQuery( session.query(cls).filter(cls.deleted == False, cls.admin == None), cls.id, PAGINATE_MAX_LEN + 1, first, last).next()
def users_telegram_keys(cls): return { user.telegram_id: user.as_dict() for user in session.query(cls).all() }
def get(cls, _id): return session.query(cls).filter(cls.id == _id).first()
def paginate_right(cls, first, last): return PaginateQuery( session.query(cls).filter(cls.deleted == False, cls.admin == None), cls.id, PAGINATE_PAGE_LEN, first, last).next()
def all(cls): return session.query(cls).filter(cls.deleted == False).all()
def get_token(cls, token): return session.query(cls).filter( cls.token == token, cls.used == False, cls.fresh_until > datetime.datetime.now()).first()
def get_unused_tokens(cls): return session.query(cls).filter( cls.used == False, cls.fresh_until > datetime.datetime.now()).all()
def first_paginate(cls, user_id, first=0, last=0): return PaginateQuery( session.query(cls).filter(cls.user_id == int(user_id)), cls.id, PAGINATE_MAX_LEN + 1, first, last, True).next(True)
def paginate_right(cls, user_id, first, last): return PaginateQuery( session.query(cls).filter(cls.user_id == int(user_id)), cls.id, PAGINATE_PAGE_LEN, first, last, True).next()