Esempio n. 1
0
def catalog_by_supplier(supplier_id):
    """catalog page filtered by supplier id
    """
    return render_page("catalog", parts=db_session.query(Part, Supplier) \
        .join(Supplier).filter(Supplier.id == supplier_id) \
        .order_by(asc(Part.id)).all(), \
        suppliers=db_session.query(Supplier), selected_supplier=supplier_id)
Esempio n. 2
0
def download_artifact_filename(uuid, filename):
    """download artifact by UUID and filename
    """
    artifact, artifact_file = get_artifact(uuid)

    if artifact is None:
        abort(404)

    # if the artifact is an html page, serve its contents

    if artifact.filename[-5:] == ".html" or artifact.filename[-4:] == ".htm":
        with open(artifact_file) as file:
            return render_template_string(file.read())

    # if this is a crypto file, display it with crypto viewer (unless it fails)

    # try:
    if artifact.content_type == "crypto":
        with open(artifact_file) as file:
            crypto = json.loads(file.read())
            assert float(crypto["crypto_spec_version"]) >= 2.0
            return render_page("crypto_viewer", \
                filelist=crypto["crypto_evidence"], artifact=artifact, \
                package_name=crypto["package_name"], \
                verif_code=crypto["file_collection_verification_code"])
    # except:
    #     pass

    return send_file(artifact_file, filename)
Esempio n. 3
0
def catalog():
    """catalog page
    """
    parts = db_session.query(Part, Supplier).join(Supplier) \
        .order_by(asc(Part.id))

    # filter by search term if it exists

    if "q" in request.args:
        parts = parts.filter(Part.name.ilike("%" + request.args["q"] + "%"))

    return render_page("catalog",
                       parts=parts.all(),
                       suppliers=db_session.query(Supplier))
Esempio n. 4
0
def catalog_by_category(category):
    """catalog page filtered by category name
    """
    part_query = db_session.query(Part, Supplier).join(Supplier)

    if category == "other":
        part_query = part_query.filter(~Part.categories.any())
    else:
        part_query = part_query.filter(
            Part.categories.any(Category.name == category))

    part_query = part_query.order_by(asc(Part.id))

    return render_page("catalog",
                       parts=part_query.all(),
                       suppliers=db_session.query(Supplier))
Esempio n. 5
0
def view_part(part_id):
    """part profile page
    """
    if not db_session.query(exists().where(Part.id == part_id)).scalar():
        abort(404)

    part, supplier = db_session.query(Part, Supplier) \
        .join(Supplier).filter(Part.id == part_id).one()

    category_list = [{"text": cat.description, "value": cat.id} \
        for cat in db_session.query(Category).all()]

    selected_categories = [category.id for category in part.categories]

    return render_page("part", part=part, supplier=supplier, \
        category_list=category_list, envelope=part.envelope, \
        selected_categories=selected_categories)
Esempio n. 6
0
def all_envelopes():
    """page for viewing list of envelopes saved in the database. not implemented yet.
    """
    return render_page("envelopes", envelopes=db_session.query(Envelope))
Esempio n. 7
0
def new_part():
    """new part page"""
    return render_page("new_part", suppliers=db_session.query(Supplier))
Esempio n. 8
0
def create_supplier_page():
    """new supplier page
    """
    return render_page("new_supplier", suppliers=db_session.query(Supplier))