Пример #1
0
def create_antibody():
    antibody1 = Antibody(name='Amatuximab',
                         weight=144330,
                         target='Mesothelin',
                         user_id=1)
    session.add(antibody1)
    session.commit()
    antibody2 = Antibody(name='Brentuximab',
                         weight=153000,
                         target='CD30',
                         user_id=2)
    session.add(antibody2)
    session.commit()
    antibody3 = Antibody(name='Gemtuzumab',
                         weight=152000,
                         target='CD33',
                         user_id=3)
    session.add(antibody3)
    session.commit()
    antibody4 = Antibody(name='Trastuzumab',
                         weight=148000,
                         target='HER2/neu',
                         user_id=1)
    session.add(antibody4)
    session.commit()
    antibody5 = Antibody(name='Vorsetuzumab',
                         weight=150000,
                         target='CD70',
                         user_id=2)
    session.add(antibody5)
    session.commit()
Пример #2
0
def create_adc_lot():
    lot = [1, 2, 3, 4, 5]
    for x in range(20):
        error = True
        while error:
            randomlot = choice(lot)
            try:
                id1 = choice(antibody_lot()[randomlot - 1])
                id2 = choice(cytotoxin_lot()[randomlot - 1])
            except IndexError:
                lot.remove(randomlot)
            else:
                error = False
                adclot = AdcLot(date=create_random_date(),
                                aggregate=randint(0, 5) + round(random(), 2),
                                endotoxin=randint(0, 10) + round(random(), 2),
                                concentration=randint(0, 10) +
                                round(random(), 2),
                                vial_volume=choice([1, 0.2, 0.5]),
                                vial_number=randint(1, 100),
                                adc_id=randomlot,
                                antibodylot_id=id1,
                                cytotoxinlot_id=id2,
                                user_id=randint(1, 3))
        session.add(adclot)
        session.commit()
Пример #3
0
def create_adc_lot():
    lot = [1, 2, 3, 4, 5]
    for x in range(20):
        error = True
        while error:
            randomlot = choice(lot)
            try:
                id1 = choice(antibody_lot()[randomlot-1])
                id2 = choice(cytotoxin_lot()[randomlot-1])
            except IndexError:
                lot.remove(randomlot)
            else:
                error = False
                adclot = AdcLot(date=create_random_date(),
                                aggregate=randint(0, 5)+round(random(), 2),
                                endotoxin=randint(0, 10)+round(random(), 2),
                                concentration=randint(0, 10)+round(random(), 2),
                                vial_volume=choice([1, 0.2, 0.5]),
                                vial_number=randint(1, 100),
                                adc_id=randomlot,
                                antibodylot_id=id1,
                                cytotoxinlot_id=id2,
                                user_id=randint(1, 3))
        session.add(adclot)
        session.commit()
Пример #4
0
def create_user(name, email, picture):
    user = User(name=name, email=email)
    session.add(user)
    session.commit()
    new_user_id = session.query(User).filter_by(email=email).one().id
    if picture.startswith("https"):
        attach_picture_url(User, new_user_id, picture)
    else:
        attach_picture(User, new_user_id, picture)
Пример #5
0
def create_user(name, email, picture):
    user = User(name=name, email=email)
    session.add(user)
    session.commit()
    new_user_id = session.query(User).filter_by(email=email).one().id
    if picture.startswith("https"):
        attach_picture_url(User, new_user_id, picture)
    else:
        attach_picture(User, new_user_id, picture)
Пример #6
0
def create_user(login_session):
    """
    Create a new user in the db using user info in the login_session
    """
    new_user = User(name=login_session["username"], email=login_session["email"])
    session.add(new_user)
    session.commit()
    user = session.query(User).filter_by(email=login_session["email"]).one()
    attach_picture_url(User, user.id, login_session["picture"])
    return user.id
Пример #7
0
def create_user(login_session):
    """
    Create a new user in the db using user info in the login_session
    """
    new_user = User(name=login_session['username'],
                    email=login_session['email'])
    session.add(new_user)
    session.commit()
    user = session.query(User).filter_by(email=login_session['email']).one()
    attach_picture_url(User, user.id, login_session['picture'])
    return user.id
Пример #8
0
def edit_type_lot(dbtype, item_id):
    """Edit item within the category in the database"""
    # check login status
    if 'email' not in login_session:
        flash('Sorry, the page you tried to access is for members only. '
              'Please sign in first.')
        abort(401)

    # query the item user wants to edit
    edit_item = (session.query(eval(dbtype.capitalize() +
                                    'Lot')).filter_by(id=item_id).one())
    # make sure user is authorized to edit this item
    if login_session['user_id'] != edit_item.user_id:
        flash('You are not authorized to modify items you did not create. '
              'Please create your own item in order to modify it.')
        return redirect(url_for(dbtype))

    # get property names from table, check maximum lot# from ab and cytotoxin
    table = Table('%s_lot' % dbtype, meta, autoload=True, autoload_with=engine)
    max_ab_lot = (session.query(AntibodyLot).order_by(desc(
        AntibodyLot.id)).first().id)
    max_cytotoxin_lot = (session.query(CytotoxinLot).order_by(
        desc(CytotoxinLot.id)).first().id)

    if request.method == 'POST':
        # set date attribute of query object with request form data
        try:
            edit_item.date = (datetime.strptime(
                request.form['date'].replace('-', ' '), '%Y %m %d'))
        # in some cases users can input 6 digit year, catch this error
        except ValueError as detail:
            print 'Handling run-time error: ', detail
            flash('Invalid date detected. Please type the date in '
                  'format: MM/DD/YYYY')
            return redirect(url_for(dbtype))
        for column in table.columns:
            if column.name in ('id', 'date', 'antibody_id', 'cytotoxin_id',
                               'adc_id', 'user_id'):
                pass  # don't modify item identifier
            # set attribute of query object with request form data
            else:
                setattr(edit_item, column.name, request.form[column.name])
        session.add(edit_item)
        session.commit()
        flash('%s Lot Edited' % dbtype.capitalize())
        return redirect(url_for(dbtype))
    else:
        return render_template('edit-type-lot.html',
                               dbtype=dbtype,
                               columns=table.columns,
                               item_id=item_id,
                               edit_item=edit_item,
                               max_ab_lot=max_ab_lot,
                               max_cytotoxin_lot=max_cytotoxin_lot)
Пример #9
0
def create_cytotoxin_lot():
    for x in range(20):
        cytotoxin_lot = CytotoxinLot(date=create_random_date(),
                                    purity=randint(80, 99)+round(random(), 2),
                                    concentration=randint(0, 10)+round(random(), 2),
                                    vial_volume=choice([1, 0.2, 0.5]),
                                    vial_number=randint(1, 100),
                                    cytotoxin_id=randint(1, 5),
                                    user_id=randint(1, 3))
        session.add(cytotoxin_lot)
        session.commit()
Пример #10
0
def create_cytotoxin_lot():
    for x in range(20):
        cytotoxin_lot = CytotoxinLot(
            date=create_random_date(),
            purity=randint(80, 99) + round(random(), 2),
            concentration=randint(0, 10) + round(random(), 2),
            vial_volume=choice([1, 0.2, 0.5]),
            vial_number=randint(1, 100),
            cytotoxin_id=randint(1, 5),
            user_id=randint(1, 3))
        session.add(cytotoxin_lot)
        session.commit()
Пример #11
0
def edit_type_lot(dbtype, item_id):
    """Edit item within the category in the database"""
    # check login status
    if 'email' not in login_session:
        flash('Sorry, the page you tried to access is for members only. '
              'Please sign in first.')
        abort(401)

    # query the item user wants to edit
    edit_item = (session.query(eval(dbtype.capitalize()+'Lot'))
                 .filter_by(id=item_id).one())
    # make sure user is authorized to edit this item
    if login_session['user_id'] != edit_item.user_id:
        flash('You are not authorized to modify items you did not create. '
              'Please create your own item in order to modify it.')
        return redirect(url_for(dbtype))

    # get property names from table, check maximum lot# from ab and cytotoxin
    table = Table('%s_lot' % dbtype, meta, autoload=True, autoload_with=engine)
    max_ab_lot = (session.query(AntibodyLot)
                  .order_by(desc(AntibodyLot.id)).first().id)
    max_cytotoxin_lot = (session.query(CytotoxinLot)
                         .order_by(desc(CytotoxinLot.id)).first().id)

    if request.method == 'POST':
        # set date attribute of query object with request form data
        try:
            edit_item.date = (datetime
                              .strptime(request
                                        .form['date']
                                        .replace('-', ' '), '%Y %m %d'))
        # in some cases users can input 6 digit year, catch this error
        except ValueError as detail:
            print 'Handling run-time error: ', detail
            flash('Invalid date detected. Please type the date in '
                  'format: MM/DD/YYYY')
            return redirect(url_for(dbtype))
        for column in table.columns:
            if column.name in ('id', 'date', 'antibody_id',
                               'cytotoxin_id', 'adc_id', 'user_id'):
                pass  # don't modify item identifier
            # set attribute of query object with request form data
            else:
                setattr(edit_item, column.name, request.form[column.name])
        session.add(edit_item)
        session.commit()
        flash('%s Lot Edited' % dbtype.capitalize())
        return redirect(url_for(dbtype))
    else:
        return render_template('edit-type-lot.html', dbtype=dbtype,
                               columns=table.columns, item_id=item_id,
                               edit_item=edit_item, max_ab_lot=max_ab_lot,
                               max_cytotoxin_lot=max_cytotoxin_lot)
Пример #12
0
def create_type_lot(dbtype, item_id):
    """Create new item within the category in the database"""
    # check login status
    if 'email' not in login_session:
        flash('Sorry, the page you tried to access is for members only. '
              'Please sign in first.')
        return redirect(url_for(dbtype))

    # get property names from table, check maximum lot# from ab and cytotoxin
    table = Table('%s_lot' % dbtype, meta, autoload=True, autoload_with=engine)
    max_ab_lot = (session.query(AntibodyLot)
                  .order_by(desc(AntibodyLot.id)).first().id)
    max_cytotoxin_lot = (session.query(CytotoxinLot)
                         .order_by(desc(CytotoxinLot.id)).first().id)
    origin_id = (session.query(eval(dbtype.capitalize()))
                 .filter_by(id=item_id).one().user_id)
    user_id = get_user_id(login_session['email'])

    if request.method == 'POST':
        # instantiate new object
        new = eval(dbtype.capitalize()+'Lot')()
        for field in request.form:
            # set date attribute of new object with request form data
            if field == 'date':
                try:
                    setattr(new,
                            field,
                            (datetime
                             .strptime(request
                                       .form[field]
                                       .replace('-', ' '), '%Y %m %d')))
                # in some cases users can input 6 digit year, catch this error
                except ValueError as detail:
                    print 'Handling run-time error: ', detail
                    flash('Invalid date detected. Please type the date in '
                          'format: MM/DD/YYYY')
                    return redirect(url_for(dbtype))
            # set attribute of new object with request form data
            if hasattr(new, field):
                setattr(new, field, request.form[field])
        setattr(new, dbtype+'_id', item_id)
        setattr(new, 'user_id', user_id)
        session.add(new)
        session.commit()
        flash('%s Lot Created' % dbtype.capitalize())
        return redirect(url_for(dbtype))
    else:
        return render_template('create-type-lot.html', dbtype=dbtype,
                               columns=table.columns, item_id=item_id,
                               max_ab_lot=max_ab_lot,
                               max_cytotoxin_lot=max_cytotoxin_lot,
                               origin_id=origin_id,
                               user_id=get_user_id(login_session['email']))
Пример #13
0
def create_antibody_lot():
    for x in range(20):
        antibody_lot = AntibodyLot(
            date=create_random_date(),
            aggregate=randint(0, 5) + round(random(), 2),
            endotoxin=randint(0, 10) + round(random(), 2),
            concentration=randint(0, 10) + round(random(), 2),
            vial_volume=choice([1, 0.2, 0.5]),
            vial_number=randint(1, 100),
            antibody_id=randint(1, 5),
            user_id=randint(1, 3))
        session.add(antibody_lot)
        session.commit()
Пример #14
0
def create_antibody_lot():
    for x in range(20):
        antibody_lot = AntibodyLot(
                      date=create_random_date(),
                      aggregate=randint(0, 5)+round(random(), 2),
                      endotoxin=randint(0, 10)+round(random(), 2),
                      concentration=randint(0, 10)+round(random(), 2),
                      vial_volume=choice([1, 0.2, 0.5]),
                      vial_number=randint(1, 100),
                      antibody_id=randint(1, 5),
                      user_id=randint(1, 3))
        session.add(antibody_lot)
        session.commit()
Пример #15
0
def create_type_lot(dbtype, item_id):
    """Create new item within the category in the database"""
    # check login status
    if 'email' not in login_session:
        flash('Sorry, the page you tried to access is for members only. '
              'Please sign in first.')
        return redirect(url_for(dbtype))

    # get property names from table, check maximum lot# from ab and cytotoxin
    table = Table('%s_lot' % dbtype, meta, autoload=True, autoload_with=engine)
    max_ab_lot = (session.query(AntibodyLot).order_by(desc(
        AntibodyLot.id)).first().id)
    max_cytotoxin_lot = (session.query(CytotoxinLot).order_by(
        desc(CytotoxinLot.id)).first().id)
    origin_id = (session.query(eval(
        dbtype.capitalize())).filter_by(id=item_id).one().user_id)
    user_id = get_user_id(login_session['email'])

    if request.method == 'POST':
        # instantiate new object
        new = eval(dbtype.capitalize() + 'Lot')()
        for field in request.form:
            # set date attribute of new object with request form data
            if field == 'date':
                try:
                    setattr(new, field, (datetime.strptime(
                        request.form[field].replace('-', ' '), '%Y %m %d')))
                # in some cases users can input 6 digit year, catch this error
                except ValueError as detail:
                    print 'Handling run-time error: ', detail
                    flash('Invalid date detected. Please type the date in '
                          'format: MM/DD/YYYY')
                    return redirect(url_for(dbtype))
            # set attribute of new object with request form data
            if hasattr(new, field):
                setattr(new, field, request.form[field])
        setattr(new, dbtype + '_id', item_id)
        setattr(new, 'user_id', user_id)
        session.add(new)
        session.commit()
        flash('%s Lot Created' % dbtype.capitalize())
        return redirect(url_for(dbtype))
    else:
        return render_template('create-type-lot.html',
                               dbtype=dbtype,
                               columns=table.columns,
                               item_id=item_id,
                               max_ab_lot=max_ab_lot,
                               max_cytotoxin_lot=max_cytotoxin_lot,
                               origin_id=origin_id,
                               user_id=get_user_id(login_session['email']))
Пример #16
0
def edit_type(dbtype, item_id):
    """Edit the category (within 3 pre-defined type) in the database"""
    # check login status
    if 'email' not in login_session:
        flash('Sorry, the page you tried to access is for members only. '
              'Please sign in first.')
        abort(401)

    # query the item user wants to edit
    edit_item = (session.query(eval(
        dbtype.capitalize())).filter_by(id=item_id).one())
    # make sure user is authorized to edit this item
    if login_session['user_id'] != edit_item.user_id:
        flash('You are not authorized to modify items you did not create. '
              'Please create your own item in order to modify it.')
        return redirect(url_for(dbtype))

    # get property names from table
    table = Table(dbtype, meta, autoload=True, autoload_with=engine)

    if request.method == 'POST':
        for column in table.columns:
            if column.name in ('id', 'user_id'):
                pass  # don't modify item id# and user_id#
            else:
                # set attribute of query object with request form data
                setattr(edit_item, column.name, request.form[column.name])
        session.add(edit_item)
        session.commit()
        flash('%s Edited' % dbtype.capitalize())

        # upload image
        image = request.files['picture']
        if image and allowed_file(image.filename):
            with store_context(fs_store):
                edit_item.picture.from_file(image)
        # prevent user uploading unsupported file type
        elif image and not allowed_file(image.filename):
            flash('Unsupported file detected. No image has been uploaded.')
        return redirect(url_for(dbtype))
    else:
        return render_template('edit-type.html',
                               dbtype=dbtype,
                               columns=table.columns,
                               item_id=item_id,
                               edit_item=edit_item)
Пример #17
0
def edit_type(dbtype, item_id):
    """Edit the category (within 3 pre-defined type) in the database"""
    # check login status
    if 'email' not in login_session:
        flash('Sorry, the page you tried to access is for members only. '
              'Please sign in first.')
        abort(401)

    # query the item user wants to edit
    edit_item = (session.query(eval(dbtype.capitalize()))
                 .filter_by(id=item_id).one())
    # make sure user is authorized to edit this item
    if login_session['user_id'] != edit_item.user_id:
        flash('You are not authorized to modify items you did not create. '
              'Please create your own item in order to modify it.')
        return redirect(url_for(dbtype))

    # get property names from table
    table = Table(dbtype, meta, autoload=True, autoload_with=engine)

    if request.method == 'POST':
        for column in table.columns:
            if column.name in ('id', 'user_id'):
                pass  # don't modify item id# and user_id#
            else:
                # set attribute of query object with request form data
                setattr(edit_item, column.name, request.form[column.name])
        session.add(edit_item)
        session.commit()
        flash('%s Edited' % dbtype.capitalize())

        # upload image
        image = request.files['picture']
        if image and allowed_file(image.filename):
            with store_context(fs_store):
                edit_item.picture.from_file(image)
        # prevent user uploading unsupported file type
        elif image and not allowed_file(image.filename):
            flash('Unsupported file detected. No image has been uploaded.')
        return redirect(url_for(dbtype))
    else:
        return render_template('edit-type.html', dbtype=dbtype,
                               columns=table.columns, item_id=item_id,
                               edit_item=edit_item)
Пример #18
0
def create_antibody():
    antibody1 = Antibody(name='Amatuximab', weight=144330,
                         target='Mesothelin', user_id=1)
    session.add(antibody1)
    session.commit()
    antibody2 = Antibody(name='Brentuximab', weight=153000,
                         target='CD30', user_id=2)
    session.add(antibody2)
    session.commit()
    antibody3 = Antibody(name='Gemtuzumab', weight=152000,
                         target='CD33', user_id=3)
    session.add(antibody3)
    session.commit()
    antibody4 = Antibody(name='Trastuzumab', weight=148000,
                         target='HER2/neu', user_id=1)
    session.add(antibody4)
    session.commit()
    antibody5 = Antibody(name='Vorsetuzumab', weight=150000,
                         target='CD70', user_id=2)
    session.add(antibody5)
    session.commit()
Пример #19
0
def create_type(dbtype):
    """
    Create new category (within 3 pre-defined type) in the database
    """
    # check login status
    if 'email' not in login_session:
        flash('Sorry, the page you tried to access is for members only. '
              'Please sign in first.')
        return redirect(url_for(dbtype))

    # get property names from table
    table = Table(dbtype, meta, autoload=True, autoload_with=engine)
    user_id = get_user_id(login_session['email'])

    if request.method == 'POST':
        # instantiate new object
        new = eval(dbtype.capitalize())()
        for field in request.form:
            # set attribute of new object with request form data
            if hasattr(new, field):
                setattr(new, field, request.form[field])
        setattr(new, 'user_id', user_id)
        session.add(new)
        session.commit()
        flash('%s Created' % dbtype.capitalize())

        # upload image
        image = request.files['picture']
        if image and allowed_file(image.filename):
            with store_context(fs_store):
                new.picture.from_file(image)
        # prevent user uploading unsupported file type
        elif image and not allowed_file(image.filename):
            flash('Unsupported file detected. No image has been uploaded.')
        return redirect(url_for(dbtype))
    else:
        return render_template('create-type.html',
                               columns=table.columns,
                               dbtype=dbtype)
Пример #20
0
def create_type(dbtype):
    """
    Create new category (within 3 pre-defined type) in the database
    """
    # check login status
    if 'email' not in login_session:
        flash('Sorry, the page you tried to access is for members only. '
              'Please sign in first.')
        return redirect(url_for(dbtype))

    # get property names from table
    table = Table(dbtype, meta, autoload=True, autoload_with=engine)
    user_id = get_user_id(login_session['email'])

    if request.method == 'POST':
        # instantiate new object
        new = eval(dbtype.capitalize())()
        for field in request.form:
            # set attribute of new object with request form data
            if hasattr(new, field):
                setattr(new, field, request.form[field])
        setattr(new, 'user_id', user_id)
        session.add(new)
        session.commit()
        flash('%s Created' % dbtype.capitalize())

        # upload image
        image = request.files['picture']
        if image and allowed_file(image.filename):
            with store_context(fs_store):
                new.picture.from_file(image)
        # prevent user uploading unsupported file type
        elif image and not allowed_file(image.filename):
            flash('Unsupported file detected. No image has been uploaded.')
        return redirect(url_for(dbtype))
    else:
        return render_template('create-type.html',
                               columns=table.columns, dbtype=dbtype)
Пример #21
0
 def save(self):
     session.add(self)
     session.commit()