Exemple #1
0
def get_user_first():
    session=db.NewSession()
    try:
        user = session.query(db.Users).first()
        return user
    except Exception,ex:
        log.error(str(ex))
        return None
def AddComments(dicItem):
    session = db.NewSession()
    try:
        model = db.Comments(dicItem)
        session.add(model)
        session.commit()
        return model.id
    except Exception,ex:
        log.error(str(ex))
        return None
Exemple #3
0
def InitDB():
    result=False
    while not result:
        try:
            Base.metadata.create_all(engine)
            result=True
        except Exception,ex:
            log.error(str(ex))
            log.debug('wait 5 seconds for retry...')
            time.sleep(5)       
def GetCommentsList(pageNumber,pageSize):
    session=db.NewSession()
    try:
        if pageNumber is None:
            pageNumber=1
        pos=pageSize * (pageNumber-1)
        lst=session.query(db.Comments).order_by(desc(db.Comments.like)).slice(pos,pos+pageSize).all()
        return lst
    except Exception,ex:
        log.error(str(ex))
        return None
Exemple #5
0
def get_user_list(page_no,page_size):
    session=db.NewSession()
    try:
        if page_no is None:
            page_no=1
        lst_count=session.query(db.Users).count()
        page_info=get_page_info(page_no,page_size,lst_count)
        lst=session.query(db.Users).order_by(desc(db.Users.create_date)).slice(page_info[1],page_info[1]+page_size).all()
        return (page_info,lst)
    except Exception,ex:
        log.error(str(ex))
        return None
Exemple #6
0
def add_user():
    session=db.NewSession()
    try:
        user = db.Users(username=time.time(),password='******',email='*****@*****.**')
        session.add(user)
        session.commit()
        return user.id
        #return user
    except Exception,ex:
        log.error(str(ex))
        print str(ex)
        return None