Beispiel #1
0
 def func_(*args, **kwargs):
     returned = func(*args, **kwargs)
     session = DBSession()#.using_bind(bind)
     try:
         session.commit()
     except SQLAlchemyError as e:
         session.rollback()
         raise_server_exc(DATABASE_UNKNOWN_ERROR, exc=e)
     return returned
Beispiel #2
0
 def func_(*args, **kwargs):
     returned = func(*args, **kwargs)
     session = DBSession()  #.using_bind(bind)
     try:
         session.commit()
     except SQLAlchemyError as e:
         session.rollback()
         raise_server_exc(DATABASE_UNKNOWN_ERROR, exc=e)
     return returned
Beispiel #3
0
def walis_session(commit=False):
    session = DBSession()
    try:
        yield session
        if commit:
            session.commit()
    except Exception as e:
        session.rollback()
        raise_server_exc(DATABASE_MYSQL_ERROR, exc=e)
    finally:
        session.close()
Beispiel #4
0
 def wrapper(*args, **kwargs):
     ret = func(*args, **kwargs)
     session = Session()
     # tmp
     session._model_changes = {}
     try:
         session.commit()
     except SQLAlchemyError as se:
         session.rollback()
         raise_server_exc(DATABASE_UNKNOWN_ERROR, exc=se)
     finally:
         session.close()
     return ret
Beispiel #5
0
 def wrapper(*args, **kwargs):
     ret = func(*args, **kwargs)
     session = Session()
     # tmp
     session._model_changes = {}
     try:
         session.commit()
     except SQLAlchemyError as se:
         session.rollback()
         raise_server_exc(DATABASE_UNKNOWN_ERROR, exc=se)
     finally:
         session.close()
     return ret
Beispiel #6
0
 def wrapper(*args, **kwargs):
     session = DBSession()
     func.func_globals['session'] = session
     try:
         ret = func(*args, **kwargs)
     except SQLAlchemyError as se:
         session.rollback()
         raise_server_exc(DATABASE_MYSQL_ERROR, exc=se)
     except Exception as e:
         session.rollback()
         raise_server_exc(DATABASE_MYSQL_ERROR, exc=e)
     finally:
         session.close()
         func.func_globals.pop('session')
     return ret
Beispiel #7
0
def put(food_id):
    food_id = int(food_id)
    with thrift_client('fuss') as fuss:
        image_file = request.files['image']
        # image_file_name = secure_filename(image_file.filename)
        #todo fix it...中文文件名错误
        image_file_name = image_file.filename
        ext = os.path.splitext(image_file_name)[1]
        ext = ext.lstrip('.')
        fuss_file = thirdparty_svc.fuss.FussFile()
        fuss_file.content = image_file.stream.read()
        fuss_file.extension = ext
        sizes = [(640, 480), (240, 180), (190, 142)]
        image_hash = fuss.file_upload_sized_with_watermarker(fuss_file, sizes)
        #todo temp
        if not image_hash:
            raise_server_exc(IMAGE_UPLOAD_ERR)
    with thrift_client('ers') as ers:
        food = thirdparty_svc.ers.TFood()
        food.image_hash = image_hash
        food_id = ers.save_food(food_id, food)
    return ''
Beispiel #8
0
def put(food_id):
    food_id = int(food_id)
    with thrift_client('fuss') as fuss:
        image_file = request.files['image']
        # image_file_name = secure_filename(image_file.filename)
        #todo fix it...中文文件名错误
        image_file_name = image_file.filename
        ext = os.path.splitext(image_file_name)[1]
        ext = ext.lstrip('.')
        fuss_file = thirdparty_svc.fuss.FussFile()
        fuss_file.content = image_file.stream.read()
        fuss_file.extension = ext
        sizes = [(640, 480), (240, 180), (190, 142)]
        image_hash = fuss.file_upload_sized_with_watermarker(fuss_file,
                                                            sizes)
        #todo temp
        if not image_hash:
            raise_server_exc(IMAGE_UPLOAD_ERR)
    with thrift_client('ers') as ers:
        food = thirdparty_svc.ers.TFood()
        food.image_hash = image_hash
        food_id = ers.save_food(food_id,food)
    return ''
Beispiel #9
0
 def validate_source(self, key, source):
     if source is not None and source not in self.sources:
         raise_server_exc(DATABASE_VALIDATION_ERROR, key=key, value=source)
     return source
Beispiel #10
0
 def validate_user_type(self, key, user_type):
     if user_type is not None and user_type not in self.user_types:
         raise_server_exc(DATABASE_VALIDATION_ERROR,
                          key=key,
                          value=user_type)
     return user_type
Beispiel #11
0
 def validate_priority(self, key, priority):
     if priority is not None and priority not in self.priorities:
         raise_server_exc(DATABASE_VALIDATION_ERROR,
                          key=key,
                          value=priority)
     return priority
Beispiel #12
0
 def validate_status(self, key, status):
     if status is not None and status not in self.statuses:
         raise_server_exc(DATABASE_VALIDATION_ERROR, key=key, value=status)
     return status