Exemple #1
0
def setup():
    Database.init()
    CORS(app, supports_credentials=True)
    app.config['SECRET_KEY'] = config.SECRET_KEY
    app.config['JSON_AS_ASCII'] = config.JSON_AS_ASCII
    app.config['JSON_SORT_KEYS'] = config.JSON_SORT_KEYS
    app.config["SESSION_COOKIE_HTTPONLY"] = config.SESSION_COOKIE_HTTPONLY
    setup_error_handler()
    setup_blueprint()
    setup_hook(app)
Exemple #2
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
Exemple #3
0
 def del_by_id(cls, poiId):
     try:
         Database.delete_one_by(Meishi, Meishi.poiId == poiId)
         Database.commit()
         return True
     except Exception as e:
         Database.rollback()
Exemple #4
0
 def del_by_id(cls, file_id):
     try:
         Database.delete_one_by(Dianying, Dianying.file_id == file_id)
         Database.commit()
         return True
     except Exception as e:
         Database.rollback()
         return False
Exemple #5
0
 def del_by_hash_id(cls, hash_id):
     try:
         Database.delete_one_by(Programming, Programming.hash_id == hash_id)
         Database.commit()
         return True
     except Exception as e:
         Database.rollback()
         return False
Exemple #6
0
 def del_by_id(cls, user_id):
     try:
         Database.delete_one_by(User, User.id == user_id)
         Database.commit()
         return True
     except Exception as e:
         Database.rollback()
         return False
Exemple #7
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
Exemple #8
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))
Exemple #9
0
 def by_id(cls, file_id):
     return Database.get_one_by(Dianying, Dianying.file_id == file_id)
Exemple #10
0
 def by_id(cls, user_id):
     return Database.get_one_by(User, User.id == user_id)
Exemple #11
0
 def by_name(cls, username):
     return Database.get_one_by(User, User.username == username)
Exemple #12
0
 def get_all_programming(cls):
     return Database.get_many_by(Programming, order_by='-id', limit=3)
Exemple #13
0
 def database_cleanup(response):
     Database.remove_session()
     return response
Exemple #14
0
 def get_all_dianying(cls):
     # latest update -24:00
     return Database.get_many_by(Dianying, order_by='score', limit=3)
Exemple #15
0
 def by_id(cls, poiId):
     return Database.get_one_by(Meishi, Meishi.poiId == poiId)
Exemple #16
0
 def by_hash_id(cls, hash_id):
     return Database.get_one_by(Programming, Programming.hash_id == hash_id)
Exemple #17
0
 def get_all_meishi(cls):
     # latest update -24:00
     return Database.get_many_by(Meishi, order_by='-id', limit=3)