Esempio n. 1
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)
Esempio n. 2
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)
Esempio n. 3
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']))
Esempio n. 4
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']))
Esempio n. 5
0
def set_category(dbtype):
    """Provide category/item data to pass onto html templates"""
    # define object and object lots
    obj = eval(dbtype.capitalize())
    items = eval(dbtype.capitalize() + "Lot")

    # query the object items and object lots items
    cat = session.query(obj).order_by(obj.name).all()
    lots = session.query(items).all()

    # create a dict to associate object id with its respective object lot items
    lot_dict = {}
    for x in range(1, session.query(obj).count() + 1):
        lot_dict[x] = session.query(items).filter(getattr(items, dbtype + "_id") == x).order_by(items.date).all()
    return (cat, lot_dict, lots)
Esempio n. 6
0
def cytotoxin_lot_json():
    """
    Create an JSON endpoint with all items within the cytotoxin
    categories
    """
    lots = session.query(CytotoxinLot).all()
    return jsonify(cytotoxin_lots=[i.serialize for i in lots])
Esempio n. 7
0
def antibody_lot_json():
    """
    Create an JSON endpoint with all items within the antibody
    categories
    """
    lots = session.query(AntibodyLot).all()
    return jsonify(antibody_lots=[i.serialize for i in lots])
Esempio n. 8
0
def get_user_id(email):
    """Get user's id in the db using its e-mail address"""
    try:
        user = session.query(User).filter_by(email=email).one()
        return user.id
    except:
        return None
Esempio n. 9
0
def set_category(dbtype):
    """Provide category/item data to pass onto html templates"""
    # define object and object lots
    obj = eval(dbtype.capitalize())
    items = eval(dbtype.capitalize() + 'Lot')

    # query the object items and object lots items
    cat = session.query(obj).order_by(obj.name).all()
    lots = session.query(items).all()

    # create a dict to associate object id with its respective object lot items
    lot_dict = {}
    for x in range(1, session.query(obj).count() + 1):
        lot_dict[x] = (session.query(items).filter(
            getattr(items, dbtype + '_id') == x).order_by(items.date).all())
    return (cat, lot_dict, lots)
Esempio n. 10
0
def get_user_id(email):
    """Get user's id in the db using its e-mail address"""
    try:
        user = session.query(User).filter_by(email=email).one()
        return user.id
    except:
        return None
Esempio n. 11
0
def antibody_lot_json():
    """
    Create an JSON endpoint with all items within the antibody
    categories
    """
    lots = session.query(AntibodyLot).all()
    return jsonify(antibody_lots=[i.serialize for i in lots])
Esempio n. 12
0
def cytotoxin_lot_json():
    """
    Create an JSON endpoint with all items within the cytotoxin
    categories
    """
    lots = session.query(CytotoxinLot).all()
    return jsonify(cytotoxin_lots=[i.serialize for i in lots])
Esempio n. 13
0
def collection_lots(dbtype):
    """
    Create an XML endpoint with all items within the categories
    available
    """
    collections = session.query(eval(dbtype.capitalize()+'Lot')).all()
    return render_template('collections-lot.xml', dbtype=dbtype,
                           collections=collections)
Esempio n. 14
0
def collection_lots(dbtype):
    """
    Create an XML endpoint with all items within the categories
    available
    """
    collections = session.query(eval(dbtype.capitalize() + 'Lot')).all()
    return render_template('collections-lot.xml',
                           dbtype=dbtype,
                           collections=collections)
Esempio n. 15
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)
Esempio n. 16
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)
Esempio n. 17
0
def cytotoxin_lot():
    total = []
    for x in range(1, 6):
        lotlist = []
        cytotoxins = (session.query(CytotoxinLot).filter(
            CytotoxinLot.cytotoxin_id == x).all())
        for cytotoxin in cytotoxins:
            lotlist.append(cytotoxin.id)
        total.append(lotlist)
    return total
Esempio n. 18
0
def antibody_lot():
    total = []
    for x in range(1, 6):
        lotlist = []
        antibodies = (session.query(AntibodyLot).filter(
            AntibodyLot.antibody_id == x).all())
        for antibody in antibodies:
            lotlist.append(antibody.id)
        total.append(lotlist)
    return total
Esempio n. 19
0
def antibody_lot():
    total = []
    for x in range(1, 6):
        lotlist = []
        antibodies = (session.query(AntibodyLot)
                             .filter(AntibodyLot.antibody_id == x).all())
        for antibody in antibodies:
            lotlist.append(antibody.id)
        total.append(lotlist)
    return total
Esempio n. 20
0
def query_questions(subject_list):
    """
            Такое сложное условие фильтра, потому что SQLAlchemy
            не поддерживает фильтрацию по релейшнам и нельзя сделать:
            session.query(Question).filter(subject.in_(subject_list)).all()
    """
    return [
        *session.query(Question).filter(
            Question.subject_id.in_(subj.id for subj in subject_list)).all()
    ]
Esempio n. 21
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
Esempio n. 22
0
def cytotoxin_lot():
    total = []
    for x in range(1, 6):
        lotlist = []
        cytotoxins = (session.query(CytotoxinLot)
                             .filter(CytotoxinLot.cytotoxin_id == x).all())
        for cytotoxin in cytotoxins:
            lotlist.append(cytotoxin.id)
        total.append(lotlist)
    return total
Esempio n. 23
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
Esempio n. 24
0
def get_picture_url(dbtype, item_id):
    """
    Redirect stored image url within the db to an organized url for
    Antibody/Cytotoxin/Adc.html to access
    """
    item = session.query(eval(dbtype.capitalize())).filter_by(id=item_id).one()
    with store_context(fs_store):
        try:
            picture_url = item.picture.locate()
        except IOError:
            print "No picture found for lot# %s" % str(item_id)
            picture_url = ''
    return render_template('img.html', item=item,
                           picture_url=picture_url, dbtype=dbtype)
Esempio n. 25
0
def get_picture_url(dbtype, item_id):
    """
    Redirect stored image url within the db to an organized url for
    Antibody/Cytotoxin/Adc.html to access
    """
    item = session.query(eval(dbtype.capitalize())).filter_by(id=item_id).one()
    with store_context(fs_store):
        try:
            picture_url = item.picture.locate()
        except IOError:
            print "No picture found for lot# %s" % str(item_id)
            picture_url = ''
    return render_template('img.html',
                           item=item,
                           picture_url=picture_url,
                           dbtype=dbtype)
Esempio n. 26
0
def save_answer_result(current_subject, score):
    """
        Берёт первого(и единственного) ученика в бд
        Переводит строку его оценок в питоновский дикт
        Добавляет к значениям оценки и ответов в целом для
        выбранного предмета 0/1 и 1 соответсвенно
    """
    current_pupil = session.query(Pupil).first()

    previous_score = ast.literal_eval(current_pupil.scores)
    previous_score[current_subject.name] = {
        "score": previous_score[current_subject.name].get("score", 0) + score,
        "answers": previous_score[current_subject.name].get("answers", 0) + 1
    }

    current_pupil.scores = str(previous_score)
    session.commit()
Esempio n. 27
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)
Esempio n. 28
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)
Esempio n. 29
0
def attach_picture(table, item_id, location):
    """
    A helper function used in populator.py to upload picture to the db
    Args:
        table: The category which the picture belongs to
        item_id: The category's id number which the picture should be
                 uploaded to
        location: local directory of where the picture is found
    Returns:
        None
    """
    try:
        item = session.query(table).filter_by(id=item_id).one()
        with store_context(fs_store):
            with open(location, "rb") as f:
                item.picture.from_file(f)
                session.commit()
    except Exception:
        session.rollback()
        raise
Esempio n. 30
0
def attach_picture(table, item_id, location):
    """
    A helper function used in populator.py to upload picture to the db
    Args:
        table: The category which the picture belongs to
        item_id: The category's id number which the picture should be
                 uploaded to
        location: local directory of where the picture is found
    Returns:
        None
    """
    try:
        item = session.query(table).filter_by(id=item_id).one()
        with store_context(fs_store):
            with open(location, 'rb') as f:
                item.picture.from_file(f)
                session.commit()
    except Exception:
        session.rollback()
        raise
Esempio n. 31
0
def delete(dbtype, item_id):
    """Delete either the item or 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 delete
    delete_item = (session.query(eval(dbtype[0].upper()+dbtype[1:]))
                   .filter_by(id=item_id).one())

    # make sure user is authorized to delete this item
    if login_session['user_id'] != delete_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))

    if request.method == 'POST':
        try:
            session.delete(delete_item)
            session.commit()
        # handling legacy error when delete invovled cascade-delete
        except IntegrityError as detail:
            print 'Handling run-time error: ', detail
            session.rollback()
            flash('Delete Operation Failed')
            return redirect(url_for('home'))
        if dbtype.endswith('Lot'):
            flash('%s Lot Deleted' % dbtype[:-3].capitalize())
            return redirect(url_for(dbtype[:-3]))
        else:
            flash('%s  Deleted' % dbtype.capitalize())
            return redirect(url_for(dbtype))
    else:
        pass
Esempio n. 32
0
def delete(dbtype, item_id):
    """Delete either the item or 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 delete
    delete_item = (session.query(eval(dbtype[0].upper() +
                                      dbtype[1:])).filter_by(id=item_id).one())

    # make sure user is authorized to delete this item
    if login_session['user_id'] != delete_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))

    if request.method == 'POST':
        try:
            session.delete(delete_item)
            session.commit()
        # handling legacy error when delete invovled cascade-delete
        except IntegrityError as detail:
            print 'Handling run-time error: ', detail
            session.rollback()
            flash('Delete Operation Failed')
            return redirect(url_for('home'))
        if dbtype.endswith('Lot'):
            flash('%s Lot Deleted' % dbtype[:-3].capitalize())
            return redirect(url_for(dbtype[:-3]))
        else:
            flash('%s  Deleted' % dbtype.capitalize())
            return redirect(url_for(dbtype))
    else:
        pass
Esempio n. 33
0
def antibody_json():
    """Create an JSON endpoint with all antibody categories"""
    antibodies = session.query(Antibody).all()
    return jsonify(antibodies=[i.serialize for i in antibodies])
Esempio n. 34
0
def cytotoxin_json():
    """Create an JSON endpoint with all cytotoxin categories"""
    cytotoxins = session.query(Cytotoxin).all()
    return jsonify(cytotoxins=[i.serialize for i in cytotoxins])
Esempio n. 35
0
def get_user_info(user_id):
    """Get user object in the db using its user_id"""
    user = session.query(User).filter_by(id=user_id).one()
    return user
Esempio n. 36
0
def adc_json():
    """Create an JSON endpoint with all ADC categories"""
    adcs = session.query(Adc).all()
    return jsonify(adcs=[i.serialize for i in adcs])
Esempio n. 37
0
def adc_lot_json():
    """
    Create an JSON endpoint with all items within the ADC categories
    """
    lots = session.query(AdcLot).all()
    return jsonify(adc_lots=[i.serialize for i in lots])
Esempio n. 38
0
def get_pupil_scores():
    return session.query(Pupil).first().scores
Esempio n. 39
0
File: link.py Progetto: tizac/hntop
 def get_by_id(cls, id):
     tt = session.query(cls).filter_by(id=id).first()
     return tt
Esempio n. 40
0
def adc_json():
    """Create an JSON endpoint with all ADC categories"""
    adcs = session.query(Adc).all()
    return jsonify(adcs=[i.serialize for i in adcs])
Esempio n. 41
0
def antibody_json():
    """Create an JSON endpoint with all antibody categories"""
    antibodies = session.query(Antibody).all()
    return jsonify(antibodies=[i.serialize for i in antibodies])
Esempio n. 42
0
def collections(dbtype):
    """Create an XML endpoint with all categories"""
    collections = session.query(eval(dbtype.capitalize())).all()
    return render_template('collections.xml', dbtype=dbtype,
                           collections=collections)
Esempio n. 43
0
def get_user_info(user_id):
    """Get user object in the db using its user_id"""
    user = session.query(User).filter_by(id=user_id).one()
    return user
Esempio n. 44
0
File: link.py Progetto: tizac/hntop
 def where(cls, **kw):
     ret = []
     for tt in session.query(cls).filter_by(**kw).order_by("id").all():
         ret.append(tt)
     return ret
Esempio n. 45
0
def query_subjects():
    return session.query(Subject).all()
Esempio n. 46
0
def cytotoxin_json():
    """Create an JSON endpoint with all cytotoxin categories"""
    cytotoxins = session.query(Cytotoxin).all()
    return jsonify(cytotoxins=[i.serialize for i in cytotoxins])
Esempio n. 47
0
def query_answers(question_key):
    return session.query(Answer).filter_by(question=question_key).all()
Esempio n. 48
0
File: link.py Progetto: tizac/hntop
 def get_by_url_and_name(cls, url, name):
     tt = session.query(cls).filter_by(url=url, name=name).first()
     if not tt:
         tt = cls(name, url)
         tt.save()
     return tt
Esempio n. 49
0
def find_answer_by_id(answer_id):
    return session.query(Answer).get(answer_id)
Esempio n. 50
0
def adc_lot_json():
    """
    Create an JSON endpoint with all items within the ADC categories
    """
    lots = session.query(AdcLot).all()
    return jsonify(adc_lots=[i.serialize for i in lots])
Esempio n. 51
0
def collections(dbtype):
    """Create an XML endpoint with all categories"""
    collections = session.query(eval(dbtype.capitalize())).all()
    return render_template('collections.xml',
                           dbtype=dbtype,
                           collections=collections)