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)
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
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()
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
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
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
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
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))
def by_id(cls, file_id): return Database.get_one_by(Dianying, Dianying.file_id == file_id)
def by_id(cls, user_id): return Database.get_one_by(User, User.id == user_id)
def by_name(cls, username): return Database.get_one_by(User, User.username == username)
def get_all_programming(cls): return Database.get_many_by(Programming, order_by='-id', limit=3)
def database_cleanup(response): Database.remove_session() return response
def get_all_dianying(cls): # latest update -24:00 return Database.get_many_by(Dianying, order_by='score', limit=3)
def by_id(cls, poiId): return Database.get_one_by(Meishi, Meishi.poiId == poiId)
def by_hash_id(cls, hash_id): return Database.get_one_by(Programming, Programming.hash_id == hash_id)
def get_all_meishi(cls): # latest update -24:00 return Database.get_many_by(Meishi, order_by='-id', limit=3)