예제 #1
0
def table_delete(table, row_id):
    table_class = tables.get(table)
    if table_class:
        with table_class() as table:
            return json_response(STATUS_SUCCESS, table.delete(row_id))
    else:
        raise NotFound(f'Unknown table: {table}')
예제 #2
0
def bom_summary():
    bomid = request.args.get('id')
    display = request.args.get('display', 'full')
    query = BillOfMaterials.query
    query = query.filter(BillOfMaterials.id == bomid)
    bom = query.first()
    form = BOMActionForm()
    if bom is not None:
        if form.update.data:
            populate_parts(bom)
        elif form.download.data:
            with open(bom.zip_file, 'rb') as f:
                response = make_response(f.read())
            fname = sanitize_filename(bom.name, ext="zip")
            disposition = "attachment; filename={}".format(fname)
            response.headers['Content-Disposition'] = disposition
            return response
        if display == 'condensed':
            parts_table = BOMPartTableShort(bom.bomparts)
        else:
            parts_table = BOMPartTableFull(bom.bomparts)
        return render_template('bom_summary.html',
                               form=form,
                               bom=bom,
                               parts_table=parts_table)
    else:
        raise NotFound()
예제 #3
0
def table_list(table):
    table_class = tables.get(table)
    if table_class:
        with table_class() as table:
            return json_response(STATUS_SUCCESS, table.list())
    else:
        raise NotFound(f'Unknown table: {table}')
예제 #4
0
def delete(file_name):

    try:
        service.delete_file(file_name)
    except FileNotFoundError:
        return NotFound(f"File {file_name} was not found.")

    return f"File {file_name} was deleted."
예제 #5
0
def table_post(table):
    parameters = RequestParameters().get_all_parameters()
    table_class = tables.get(table)
    if table_class:
        with table_class() as table:
            values = {
                name: value
                for name, value in parameters.items()
                if name in table.column_names
            }
            return json_response(STATUS_SUCCESS, table.create(**values))
    else:
        raise NotFound(f'Unknown table: {table}')
예제 #6
0
def file_info(id):
    """ Returns the file info given a file id. """

    repo = get_db()

    file_info = repo.get_by_id(id)

    if not file_info:
        return NotFound(f"File Id {id} does not exist.")

    file_info["download_url"] = service.build_download_url(
        file_info["file_path"])
    file_info["upload_url"] = service.build_upload_url(file_info["file_path"])

    return file_info
예제 #7
0
def main(username=None):
    koji = request.args.get('koji')
    if koji == 'centos':
        kojiurl = 'https://cbs.centos.org/'
    elif koji == 'rpmfuison':
        kojiurl = 'http://koji.rpmfusion.org/'
    else:
        kojiurl = None
    try:
        lines = (
            '{} {}'.format(*s)
            for s in status(username, session=app.session(), kojiurl=kojiurl))
    except HTTPError:
        # This is most likely due to not existing username, so return 404
        # But it might also be a Koji problem, because it just gives 500
        raise NotFound()
    return Response('\n'.join(lines), mimetype='text/plain')
예제 #8
0
def write(file_path):

    # TODO handle missing header
    content_range, content_total = common.get_content_metadata(
        request.headers.get("Content-Range")
    )

    if file_path is None:
        return NotFound("File path required.")

    # file: FileStorage = request.files["file"]
    # TODO add buffer to protect memory
    # content = file.stream.read()
    content = request.data

    insert_position = int(content_range.split("-")[0])

    file_size = service.put_file(file_path, insert_position, content)
    return {"file_size": file_size}
예제 #9
0
def order_summary():
    orderid = request.args.get('id')
    query = Order.query
    query = query.filter(Order.id == orderid)
    order = query.first()
    if order is None:
        raise NotFound()
    parts_table = OrderPartTable(order)
    form = parts_table.f
    if form.validate_on_submit():
        if form.update.data:
            counts = parts_table.get_counts()
            for part in order.vendorparts:
                part.number_ordered = counts[part.id]
            db.session.commit()
        elif form.export_unl_requisition.data:
            req = UNLRequisition(order)
            filename, req_data = req.get_form()
            response = make_response(req_data)
            disposition = "attachment; filename={}".format(filename)
            response.headers['Content-Disposition'] = disposition
            return response
        elif form.export_digikey.data:
            cart = DigikeyCart(order)
            filename, cart_data = cart.get_form()
            response = make_response(cart_data)
            disposition = "attachment; filename={}".format(filename)
            response.headers['Content-Disposition'] = disposition
            return response
        elif form.export_mouser.data:
            flash("Mouser not implemented", category="warning")
            return redirect(url_for('index'))
        elif form.archive.data:
            order.archived = True
            db.session.commit()
    parts_table.render()

    return render_template('order_summary.html',
                           order=order,
                           parts_table=parts_table,
                           form=form)
예제 #10
0
def get_document_handler(doc_id):
    result = get_document('document', doc_id)
    if result is None:
        logging.warning('Failed to fetch document for %r', doc_id)
        raise NotFound()
    return jsonpify(result)