Exemplo n.º 1
0
def create_alt_name_objects_from_package_sheet(form, sheet, max_row):
    obj_to_add_to_db = []
    identifiers_to_add = []

    for index in range(2, max_row):
        identifier_str = sheet.cell(row=index,
                                    column=form.alt_package.data).value
        if identifier_str != None:
            identifier_str = identifier_str.replace(" ", "")
            identifier_list = identifier_str.split(",")
            for identifier in identifier_list:
                if AltPackage.query.filter_by(name=identifier).first() != None:
                    flash('\"%s\" exists already' % identifier, "error")
                elif already_in_list(searchfor=identifier,
                                     inlist=identifiers_to_add):
                    flash(
                        'Identifier \"%s\" was found twice in import file, second instance ignored'
                        % identifier, "warning")
                else:
                    flash('\"%s\" added to database' % identifier, "success")
                    parent_package_name = sheet.cell(
                        row=index, column=form.name.data).value
                    parent_id = Package.query.filter_by(
                        name=parent_package_name).first().id
                    obj = AltPackage(identifier, parent_id)
                    obj_to_add_to_db.append(obj)
    return obj_to_add_to_db
Exemplo n.º 2
0
def package_add():
    form = PackageAddForm()
    if form.validate_on_submit():
        package_id = package_in_db_get_id_or_none(
            form.name.data
        )  # check if the package name exists as a package or as an alternative name
        if package != None:  # if this package has been found then abort!
            flash("Package already exists in db!",
                  "error")  # add an error to the flash messages
            return redirect(
                url_for('package_showById',
                        id=package_id))  # send to site of existing package
        package = Package(  # package did not exist in database: create and add to session
            form.name.data, form.pin_count.data, form.pitch.data,
            form.width.data, form.length.data, form.height.data)
        db.session.add(
            package
        )  # add the package to the session so we can link alt names to it!
        db.session.flush(
        )  # flush but dont commit yet, in case we need to undo the changes

        if form.alt_names.data != "":  # were alternative names provided?
            alt_names_to_add_to_db = [
            ]  # store objects we will actually add to the db (not adding duplicates here!)
            identifiers_to_add = [
            ]  # alt package identifiers that have been processed (so we can filter additional names/duplicates)
            identifier_str = form.alt_names.data.replace(" ",
                                                         "")  # trim spaces
            identifier_list = identifier_str.split(
                ",")  # split at "," and prepare a list of names
        for identifier in identifier_list:  # check the identifiers in the list for existing packages
            existingAltPackage = package_in_db_get_id_or_none(name=identifier)
            if existingAltPackage != None:
                flash('\"%s\" exists already, rolling back!' % identifier,
                      "error")
                db.session.rollback()  # if a package was found, undo!
                return redirect(
                    url_for('package_showById',
                            id=existingAltPackage.parent_packet.id))
            elif already_in_list(searchfor=identifier,
                                 inlist=identifiers_to_add):
                flash(
                    'Identifier \"%s\" was found twice in import file, second instance ignored'
                    % identifier, "warning")
            else:
                flash('\"%s\" added to database' % identifier, "success")
                parent_package_name = sheet.cell(row=index,
                                                 column=form.name.data).value
                parent_id = Package.query.filter_by(
                    name=parent_package_name).first().id
                obj = AltPackage(identifier, parent_id)
                obj_to_add_to_db.append(obj)
        db.session.add(obj_to_add_to_db)
        db.session.flush()
        db.session.commit()
        return redirect(url_for('package_show', id=package.id))
    return render_template("package_mng/add.html", form=form, action="new")
Exemplo n.º 3
0
def create_partlist_from_part_sheet(form, sheet, max_row):
    obj_to_add_to_db = []
    identifiers_to_add = []
    sheet_dim = calc_and_limit_sheet_dim(sheet, 0, max_row)
    row_count = sheet_dim[1]

    for index in range(2, row_count):
        # first lets make sure this part does not exist
        identifier = sheet.cell(row=index, column=form.order_code.data).value
        if identifier == None:
            pass
        elif find_part_in_db(ordering_code=identifier):
            flash(
                'Duplicate identifier \"%s\" was already found in database, ignored'
                % identifier, "warning")
        elif already_in_list(searchfor=identifier, inlist=identifiers_to_add):
            flash(
                'Identifier \"%s\" was found twice in import file, second instance ignored'
                % identifier, "warning")
        else:
            #if the part does not exist, make sure we have the package!
            package_name = sheet.cell(row=index,
                                      column=form.package.data).value
            package_id = package_in_db_get_id_or_none(name=package_name)
            if package_id == None:
                flash('no case \"%s\" found' % package_name, "error")
            else:
                flash(
                    'Part \"%s\" was succesfully added to database' %
                    identifier, "success")
                identifiers_to_add.append(identifier)
                part = Part(
                    secure_check_cell_string(sheet=sheet,
                                             row=index,
                                             column=form.part_name.data),
                    secure_check_cell_string(sheet=sheet,
                                             row=index,
                                             column=form.manufacturer.data),
                    secure_check_cell_string(sheet=sheet,
                                             row=index,
                                             column=form.order_code.data),
                    package_id,
                    secure_check_cell_string(sheet=sheet,
                                             row=index,
                                             column=form.description.data),
                )
                obj_to_add_to_db.append(part)
    return obj_to_add_to_db
Exemplo n.º 4
0
def create_packagelist_from_package_sheet(form, sheet, max_row):
    obj_to_add_to_db = []
    identifiers_to_add = []
    sheet_dim = calc_and_limit_sheet_dim(sheet, 0, max_row)
    row_count = sheet_dim[1]

    for index in range(2, max_row):
        # first lets make sure this object does not exist in database
        identifier = sheet.cell(row=index, column=form.name.data).value
        if identifier == None:
            pass
        elif package_in_db_get_id_or_none(name=identifier) != None:
            flash('\"%s\" exists already' % identifier, "error")
        elif already_in_list(searchfor=identifier, inlist=identifiers_to_add):
            flash(
                'Identifier \"%s\" was found twice in import file, second instance ignored'
                % identifier, "warning")
        else:
            flash('\"%s\" added to database' % identifier, "success")
            identifiers_to_add.append(identifier)
            obj = Package(
                sheet.cell(row=index, column=form.name.data).value,
                secure_check_cell_number(sheet=sheet,
                                         row=index,
                                         column=form.pin_count.data),
                secure_check_cell_number(sheet=sheet,
                                         row=index,
                                         column=form.pitch.data),
                secure_check_cell_number(sheet=sheet,
                                         row=index,
                                         column=form.width.data),
                secure_check_cell_number(sheet=sheet,
                                         row=index,
                                         column=form.length.data),
                secure_check_cell_number(sheet=sheet,
                                         row=index,
                                         column=form.height.data))
            obj_to_add_to_db.append(obj)
    return obj_to_add_to_db
Exemplo n.º 5
0
def package_show(id):
    form = PackageAddAlternativeNameForm()  # set the current form
    if form.validate_on_submit(
    ):  # is this a post and are the fields as required?
        list_of_procesesed_items = []  # list to store names for alt packages
        list_of_items_to_add_to_db = [
        ]  # list to store items to be added to db
        name_list = form.name.data.replace(" ", "").split(
            ","
        )  # on acse multiple alternate ids were entered, lest split the string

        for alt_name in name_list:
            already_exists_id = package_in_db_get_id_or_none(
                name=alt_name
            )  # check if we already have a package or altpackage in the db with this name
            if already_exists_id:  # do nothing if name is already used and print an error
                flash("Package '%s' already exists in database! (See \"%s\")" \
                        %(alt_name, url_for('package_show', id=already_exists_id)),\
                        "error")                                # display an error to the user with a link to the duplicate part
            else:
                if already_in_list(alt_name, list_of_procesesed_items):
                    flash("Found duplicate in list, ignoring second instance of %s" % alt_name, \
                          "warning")                            # warn the user about naming an instance twice
                else:
                    alt = AltPackage(
                        alt_name,
                        id)  # all is good, lets create the altPackage object
                    list_of_procesesed_items.append(
                        alt_name)  # store name to check for duplicates
                    db.session.add(alt)
        db.session.commit()
    package = Package.query.filter_by(
        id=id).first()  # get the package and refrech the page
    return render_template('/package_mng/showById.html',
                           package=package,
                           form=form)