示例#1
0
文件: views.py 项目: Boomatang/Clue
def material_add():

    if request.method == "POST":

        size = request.form.get("size")
        lengths = request.form.getlist("lengths")

        checked_lengths = []
        failed_lengths = []

        for length in lengths:
            if isInt(length):
                checked_lengths.append(int(length))
            else:
                failed_lengths.append(length)

        if len(failed_lengths) > 1:
            flash(error_builder(failed_lengths))

        if hasName(size) and hasValues(checked_lengths):
            MaterialSize.add_new_material(size, checked_lengths)
            flash(f"{size} has been added to the database")

        else:
            flash("There was some error with your input please try again")
            return redirect(url_for(".material_add"))

        print(f"this was the size {size}")
        print(f"lengths are {checked_lengths}")

    return render_template("materials/add.html")
示例#2
0
    def _check_is_int(num):

        value = RawBomFile._check_is_string(num)

        if isInt(value):
            return int(value)
        else:
            return None
示例#3
0
文件: views.py 项目: Boomatang/Clue
def material_classes():
    add_form = AddClass(prefix="add_form")
    remove_form = RemoveClassForm(prefix="remove_form",
                                  company=current_user.company.id)

    if add_form.is_submitted():
        if add_form.validate():
            material_class = MaterialClass(
                name=add_form.name.data,
                description=add_form.description.data,
                company=current_user.company.id,
            )
            try:
                db.session.add(material_class)
                db.session.commit()
                current_user.company.add_asset(material_class.asset)
                db.session.commit()
            except IntegrityError as e:
                db.session.rollback()
                flash(
                    "There was an error saving your entry. It looks like that name was used before."
                )
            return redirect(url_for(".material_classes"))

        else:
            flash_form_errors(add_form)

    if remove_form.is_submitted():
        data = request.form.getlist("remove")
        if len(data):
            default = MaterialClass.query.filter_by(
                name="Undefined").first_or_404()
            remove = False
            for item in data:
                if isInt(item):
                    entry: MaterialClass = MaterialClass.query.filter_by(
                        id=int(item)).first_or_404()

                    if entry.id != default.id:
                        for material in entry.materials:
                            default.materials.append(material)

                        entry.materials = []
                        db.session.delete(entry)
                        remove = True
                    else:
                        flash(
                            f"You cannot remove the {default.name} class. Its a system default."
                        )
            db.session.add(default)
            db.session.commit()
            if remove:
                flash("Material Class has been removed.")
            return redirect(url_for(".material_classes"))

    return render_template("materials/classes.html",
                           add_form=add_form,
                           remove_form=remove_form)
示例#4
0
文件: views.py 项目: Boomatang/Clue
def get_one_bom(ref):

    if ref.lower().startswith("t"):
        result = bom_api_test_function(ref)
    else:
        if not isInt(ref):
            return jsonify(
                {"error": "BOM ID not found \nPlease check your input"}), 404

        result = get_bom_ref_data(int(ref))

    return jsonify(result)
示例#5
0
文件: views.py 项目: Boomatang/Clue
def material_view(asset):

    unit: MaterialSize = MaterialSize.query.filter_by(
        asset=asset).first_or_404()
    choice = unit.class_id

    form = testform(unit.id, current_user.company.id)

    if form.is_submitted():
        print(request.form.getlist("remove"))
        remove_lengths = request.form.getlist("remove")
        remove_lengths = [int(l) for l in remove_lengths]

        print(remove_lengths)
        if len(remove_lengths):
            unit.remove_lengths(remove_lengths)
            flash(f"{remove_lengths} has been removed from {unit.size}")

        new_length = form.add.data
        if len(new_length):
            if isInt(new_length):
                unit.add_length(new_length)
                flash(f"{new_length} has been added to {unit.size}")

            else:
                flash("The length most be a whole number.", "error")

        if form.choice.data != choice:
            unit.class_id = form.choice.data
            db.session.add(unit)
            db.session.commit()

        # return redirect(url_for(".material_view", material_id=material_id))
        return redirect(url_for(".material_library"))

    return render_template("materials/view.html",
                           unit=unit,
                           form=form,
                           choice=choice)
示例#6
0
文件: views.py 项目: Boomatang/Clue
def material_missing():
    material = session["material_missing"]
    choices = get_choices()

    if request.method == "POST":

        size = material
        lengths = request.form.getlist("lengths")
        group = request.form.get("choice")

        checked_lengths = []
        failed_lengths = []

        for length in lengths:
            if isInt(length):
                checked_lengths.append(int(length))
            else:
                failed_lengths.append(length)

        if len(failed_lengths) > 1:
            flash(error_builder(failed_lengths))

        # TODO this needs to be refactored 2019-04-04
        if hasName(size) and hasValues(checked_lengths) and hasGroup(group):
            MaterialSize.add_new_material(size,
                                          checked_lengths,
                                          group=group,
                                          company=current_user.company.id)
            flash(f"{size} has been added to the database")
            return redirect(url_for("BOM.BOM_setup"))

        else:
            flash("There was some error with your input please try again")
            return redirect(url_for(".material_missing"))

    return render_template("materials/missing.html",
                           material=material,
                           choices=choices)
示例#7
0
def test_is_int_pass(pass_value):
    assert isInt(pass_value)
示例#8
0
def test_is_int_fail(fail_value):
    assert not isInt(fail_value)