Exemple #1
0
def main():
    if not engine.dialect.has_table(engine, 'wine_attributes'):
        Base.metadata.create_all(engine)

        try:
            file_name = "wine_attributes.csv"
            data = load_data(file_name)

            for i in data:
                record = WineAttribute(
                    **{
                        'japanese_title': i[1],
                        'english_title': i[2],
                        'step': float(i[3]),
                        'max_value': float(i[4]),
                        'min_value': float(i[5])
                    })
                session.add(record)

            session.commit()
        except Exception as e:
            print(e)
            session.rollback()
        finally:
            session.close()
Exemple #2
0
 def save(param):
     try:
         # 创建新User对象:
         new_user =IDC( name=param['name'],prefix=param['prefix'])
         session.add(new_user)
         session.commit()
     except:
         session.rollback()
Exemple #3
0
    def save(param):
        try:
            new_sys_op_ship=sys_op_ship( asset_id=param['asset_id'], game_id=0 , cluster_id = 0, services_id =0, ip_id = param['ip_id'])
            session.add(new_sys_op_ship)
            session.flush()
            session.commit()

            return new_sys_op_ship.id
        except:
            session.rollback()
Exemple #4
0
    def save(param):
        try:
            # 创建新User对象:
            new_ip =IP( outer_ip=param['outer_ip'],inner_ip=param['inner_ip'],idc_id =param['idc_id'])
            session.add(new_ip)
            session.flush()
            session.commit()

            return new_ip.id
        except:
            session.rollback()
Exemple #5
0
    def save(param):
        try:
            # 创建新User对象:
            new_asset =Asset( sn=param['wxsn'], purchase_date=param['purchase_date'], idc_id =param['idc_id'], is_virtual =1)
            session.add(new_asset)
            session.flush()
            session.commit()

            return new_asset.id
        except:
            session.rollback()
Exemple #6
0
    def save(param):
        try:
            # 创建新User对象:
            new_idc_op_ship =idc_op_ship( asset_id=param['asset_id'],cabinet_id= 0 , game_id=0 , cluster_id = 0, idc_id =param['idc_id'], ip_id = param['ip_id'])
            session.add(new_idc_op_ship)
            session.flush()
            session.commit()

            return new_idc_op_ship.id
        except:
            session.rollback()
Exemple #7
0
def add_book():
    # Validate method and not null fields for the book
    if request.method == 'POST' and request.form['title'] and request.form[
            'author']:
        book = Book(title=request.form['title'],
                    author=request.form['author'],
                    genres=request.form['genres'])
        session.add(book)
        session.commit()
        return redirect(url_for('show_books'))
    else:
        return render_template('add_book.html')
Exemple #8
0
def update_book(book_id):
    book = session.query(Book).filter_by(id=book_id).one()
    # Validate method and not null fields for the book
    if request.method == 'POST' and request.form['title'] and request.form[
            'author']:
        book.title = request.form['title']
        book.author = request.form['author']
        book.genres = request.form['genres']
        session.add(book)
        session.commit()
        return redirect(url_for('show_books'))
    else:
        return render_template('update_book.html', book=book)
Exemple #9
0
def add_book():
    #request.json['title']
    title = request.args.get('title', '')
    author = request.args.get('author', '')
    genres = request.args.get('genres', '')
    # Validate not null fields for the book
    if title and author:
        book = Book(title=title, author=author, genres=genres)
        session.add(book)
        session.commit()
        # Return a key called 'book' that contains the added book
        return jsonify(book=book.serialize)
    else:
        return 'Error trying to add a book! Please, check the params..'
Exemple #10
0
    def save(param):
        try:
            # 创建新User对象:
            new_asset =Asset( sn=param['wxsn'], purchase_date= '0000-00-00', idc_id =param['idc_id'], is_virtual =1)
            session.add(new_asset)
            session.flush()
            session.commit()
            param['asset_id'] = new_asset.id


            new_ip =IP( outer_ip=param['outer_ip'],idc_id =param['idc_id'],is_balancer = 1)
            session.add(new_ip)
            session.flush()
            session.commit()
            param['ip_id'] = new_ip.id

            new_idc_op_ship =idc_op_ship( asset_id=param['asset_id'],cabinet_id= 0 , game_id=0 , cluster_id = 0, idc_id =param['idc_id'], ip_id = param['ip_id'])
            session.add(new_idc_op_ship)


            new_sys_op_ship=sys_op_ship( asset_id=param['asset_id'], game_id=0 , cluster_id = 0, services_id =0, ip_id = param['ip_id'])
            session.add(new_sys_op_ship)

            session.flush()
            session.commit()
        except:
            session.rollback()
Exemple #11
0
def update_book(book_id):
    #request.json['title']
    title = request.args.get('title', '')
    author = request.args.get('author', '')
    genres = request.args.get('genres', '')
    book = session.query(Book).filter_by(id=book_id).one_or_none()
    # Validate book and not null fields for it
    if book is not None and title and author:
        book.title = title
        book.author = author
        book.genres = genres
        session.add(book)
        session.commit()
        # Return a key called 'book' that contains the updated book
        return jsonify(book=book.serialize)
    else:
        return 'Error trying to update the book! Please, check the params..'