Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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()
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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))
Ejemplo n.º 9
0
 def by_id(cls, file_id):
     return Database.get_one_by(Dianying, Dianying.file_id == file_id)
Ejemplo n.º 10
0
 def by_id(cls, user_id):
     return Database.get_one_by(User, User.id == user_id)
Ejemplo n.º 11
0
 def by_name(cls, username):
     return Database.get_one_by(User, User.username == username)
Ejemplo n.º 12
0
 def get_all_programming(cls):
     return Database.get_many_by(Programming, order_by='-id', limit=3)
Ejemplo n.º 13
0
 def database_cleanup(response):
     Database.remove_session()
     return response
Ejemplo n.º 14
0
 def get_all_dianying(cls):
     # latest update -24:00
     return Database.get_many_by(Dianying, order_by='score', limit=3)
Ejemplo n.º 15
0
 def by_id(cls, poiId):
     return Database.get_one_by(Meishi, Meishi.poiId == poiId)
Ejemplo n.º 16
0
 def by_hash_id(cls, hash_id):
     return Database.get_one_by(Programming, Programming.hash_id == hash_id)
Ejemplo n.º 17
0
 def get_all_meishi(cls):
     # latest update -24:00
     return Database.get_many_by(Meishi, order_by='-id', limit=3)