コード例 #1
0
 def load_or_create(cls, poiId, frontImg, title, avgScore, allCommentNum,
                    address, avgPrice, dealList):
     meishi_obj = cls.by_id(poiId)
     if meishi_obj:
         return meishi_obj
     meishi_obj = cls(
         poiId=poiId,
         frontImg=frontImg,
         title=title,
         avgScore=avgScore,
         allCommentNum=allCommentNum,
         address=address,
         avgPrice=avgPrice,
         dealList=dealList,
     )
     try:
         Database.add(meishi_obj)
         Database.commit()
         return meishi_obj
     #TODO(weiming liu) cache sqlalchemy for not cache base exception
     except Exception as e:
         log.error(str(e))
         Database.rollback()
         # TODO(weiming liu) raise error for not return None
         return None
コード例 #2
0
 def load_or_create(cls, hash_id, title, url):
     programming_obj = cls.by_hash_id(hash_id)
     if programming_obj:
         return programming_obj
     programming_obj = cls(
         hash_id=hash_id,
         title=title,
         url=url,
     )
     try:
         Database.add(programming_obj)
         Database.commit()
         return programming_obj
     #TODO(weiming liu) cache sqlalchemy for not cache base exception
     except Exception as e:
         Database.rollback()
         log.error(str(e))
         # TODO(weiming liu) raise error for not return None
         return None
コード例 #3
0
 def load_or_create(cls, username, password):
     user_obj = cls.by_name(username)
     if user_obj:
         if user_obj.password == password:
             return user_obj
         else:
             raise ArgsError('unmatch password')
     user_obj = cls(
         username=username,
         password=password,
     )
     try:
         Database.add(user_obj)
         Database.commit()
         return user_obj
     #TODO(weiming liu) cache sqlalchemy error for not cache base exception
     except Exception as e:
         log.error(str(e))
         Database.rollback()
         raise DatabaseError('can not create user {username}'.format(username=username))