Exemple #1
0
def view_software():
    all_software = db_connect.query_all(models.Software)
    add_software_company_form = forms.AddSoftwareCompanyForm()
    add_software_form = forms.AddSoftwareForm()
    all_software_companies = []
    try:
        for c in db_connect.query_all(models.SoftwareCompanies):
            all_software_companies.append((str(c.id), c.software_company.title()))
    except:
        pass
    add_software_form.software_company.choices = [('', 'Select Software Company')] + all_software_companies
    if add_software_company_form.software_company_submit.data and add_software_company_form.validate():
        db_connect.insert_db(models.SoftwareCompanies(software_company=add_software_company_form.software_company.data))
        return redirect(url_for('view_software'))
    if add_software_form.software_submit.data and add_software_form.validate():
        db_connect.insert_db(models.Software(software_name=add_software_form.software_name.data,
                                             software_company=add_software_form.software_company.data))
        return redirect(url_for('view_software'))
    s = data_functions.software_companies_as_dict()
    for a in all_software:
        print(s[a.software_company])
    return render_template('view_software.html',
                           add_software_company_form=add_software_company_form,
                           add_software_form=add_software_form,
                           soft_company_dict=data_functions.software_companies_as_dict(),
                           all_software=all_software)
Exemple #2
0
def main():
    data_functions.asset_models_by_manufacturer()
    print('Current CWD: ' + os.getcwd())
    all_asset_types = db_connect.query_all(models.AssetTypes)
    data_functions.write_all_solution_data()
    add_department_form = forms.AddDepartmentForm()
    if request.args.get('solution_category'):
        solution_category = request.args.get('solution_category')
    else:
        solution_category = '0'
    if request.args.get('company'):
        company = request.args.get('company')
    else:
        company = '0'
    if add_department_form.department_submit.data and add_department_form.validate():
        db_connect.insert_db(models.Departments(department=add_department_form.department.data))
        return redirect(url_for('main'))
    # This is as a test for creating dynamic steps and sending image data through ajax
    # return render_template('test_form.html')
    return render_template('base.html',
                           all_departments=db_connect.query_all(models.Departments),
                           add_department_form=add_department_form,
                           solution_category=solution_category,
                           company=company,
                           asset_types=all_asset_types)
Exemple #3
0
def write_asset_data_to_json(asset_id=0):
    if asset_id != 0:
        asset_data = {}
        all_types = []
        all_manufacturers = []
        all_departments = []
        for t in db_connect.query_all(models.AssetTypes):
            all_types.append({'id': t.id, 'asset_type': t.asset_type})
        for m in db_connect.query_all(models.Manufacturers):
            all_manufacturers.append({
                'id': m.id,
                'manufacturer': m.manufacturer
            })
        for d in db_connect.query_all(models.Departments):
            all_departments.append({'id': d.id, 'department': d.department})
        asset_data['all_types'] = all_types
        asset_data['all_manufacturers'] = all_manufacturers
        asset_data['all_departments'] = all_departments
        asset_data['this_asset'] = write_one_asset_data_to_json(asset_id)
        data_folder = Path("static/data/all_asset_data.json")
        with open(data_folder, 'w') as fp:
            json.dump(asset_data, fp, indent=4)
        return None
    else:
        return None
Exemple #4
0
def view_solutions():
    if request.args.get('asset_type'):
        asset_type = request.args.get('asset_type')
    this_asset_type = db_connect.query_one_db(models.AssetTypes, models.AssetTypes.id, asset_type)
    return render_template('view_solutions.html',
                           all_departments=db_connect.query_all(models.Departments),
                           asset_type=this_asset_type.asset_type,
                           asset_type_id=this_asset_type.id,
                           manufacturers=data_functions.manufacturers_as_dict(),
                           asset_types=db_connect.query_all(models.AssetTypes),
                           latest_five=db_connect.query_latest_five_by_asset_type(this_asset_type.id),
                           latest_five_assets=db_connect.query_latest_five_better(model=models.Assets,
                                                                                  column=models.Assets.asset_type,
                                                                                  v=this_asset_type.id)
                           )
Exemple #5
0
def asset_models_by_manufacturer():
    all_manufacturers = db_connect.query_all(models.Manufacturers)
    all_asset_types = db_connect.query_all(models.AssetTypes)
    model_by_manufacturer = {}
    for m in all_manufacturers:
        asset_type_list = {}
        for t in all_asset_types:
            model_numbers_for_type = []
            q = db_connect.query_distinct_for_models(m.id, t.id)
            for model_no in q:
                model_numbers_for_type.append(model_no.model)
            asset_type_list[t.id] = model_numbers_for_type
        model_by_manufacturer[m.id] = asset_type_list
    data_folder = Path("static/data/model_by_manufacturer.json")
    with open(data_folder, 'w') as fp:
        json.dump(model_by_manufacturer, fp, indent=4)
    return model_by_manufacturer
Exemple #6
0
def write_asset_types_to_json():
    asset_types = db_connect.query_all(models.AssetTypes)
    type_dict = {}
    for i in asset_types:
        type_dict[i.id] = i.asset_type
    data_folder = Path("static/data/all_assoc_types.json")
    with open(data_folder, 'w') as fp:
        json.dump(type_dict, fp, indent=4)
    return type_dict
Exemple #7
0
def write_all_solution_data():
    all_solutions = db_connect.query_all(models.Solutions)
    solution_data = []
    for s in all_solutions:
        main_asset_type = db_connect.query_one_db(model=models.AssetTypes,
                                                  column=models.AssetTypes.id,
                                                  v=s.primary_asset_type)
        solution_data.append({
            'id': s.id,
            'title': s.solution_title,
            'primary_asset_type': main_asset_type.asset_type
        })
    data_folder = Path("static/data/all_solution_data.json")
    with open(data_folder, 'w') as fp:
        json.dump(solution_data, fp, indent=4)
    return None
Exemple #8
0
def add_solution():
    data_folder = Path("static/data/one_solution.json")
    with open(data_folder, 'w') as fp:
        json.dump('', fp, indent=4)
    if request.args.get('message'):
        message = request.args.get('message')
    else:
        message = 0
    if request.args.get('asset_type'):
        asset_type = request.args.get('asset_type')
        this_asset_type = db_connect.query_one_db(model=models.AssetTypes, column=models.AssetTypes.id, v=asset_type)
    else:
        asset_type = 0
    return render_template('add_solution.html',
                           message=message,
                           asset_type_name=this_asset_type.asset_type,
                           asset_type_id=asset_type,
                           asset_types=db_connect.query_all(models.AssetTypes))
Exemple #9
0
def add_asset():
    add_asset_form = forms.AddAssetForm()
    add_asset_type_form = forms.AddAssetTypeForm()
    add_manufacturer_form = forms.AddManufacturerForm()
    add_department_form = forms.AddDepartmentForm()
    all_asset_types = []
    all_departments = []
    all_manufacturers = []
    try:
        for t in db_connect.query_all(models.AssetTypes):
            all_asset_types.append((str(t.id), t.asset_type.title()))
    except:
        pass
    try:
        for d in db_connect.query_all(models.Departments):
            all_departments.append((str(d.id), d.department.title()))
    except:
        pass
    try:
        for m in db_connect.query_all(models.Manufacturers):
            all_manufacturers.append((str(m.id), m.manufacturer.title()))
    except:
        pass

    if add_asset_type_form.asset_type_submit.data and add_asset_type_form.validate():
        db_connect.insert_db(models.AssetTypes(asset_type=add_asset_type_form.asset_type.data))
        return redirect(url_for('add_asset'))
    if add_department_form.department_submit.data and add_department_form.validate():
        db_connect.insert_db(models.Departments(department=add_department_form.department.data))
        return redirect(url_for('add_asset'))
    if add_manufacturer_form.manufacturer_submit.data and add_manufacturer_form.validate():
        db_connect.insert_db(models.Manufacturers(manufacturer=add_manufacturer_form.manufacturer.data))
        return redirect(url_for('add_asset'))

    add_asset_form.add_asset_asset_type.choices = [('', 'Select Asset Type')] + all_asset_types
    add_asset_form.department.choices = [('', 'Select Department')] + all_departments
    add_asset_form.add_asset_manufacturer.choices = [('', 'Select Manufacturer')] + all_manufacturers
    if add_asset_form.asset_submit.data and add_asset_form.validate():
        db_connect.insert_db(models.Assets(asset_type=add_asset_form.add_asset_asset_type.data,
                                           manufacturer=add_asset_form.add_asset_manufacturer.data,
                                           model=add_asset_form.model.data,
                                           serial_no=add_asset_form.serial_no.data,
                                           dia_asset_tag=add_asset_form.dia_asset_tag.data,
                                           name=add_asset_form.name.data,
                                           description=add_asset_form.description.data,
                                           ip_address=add_asset_form.ip_address.data,
                                           department=add_asset_form.department.data,
                                           date_added=datetime.datetime.now(),
                                           date_revised=datetime.datetime.now()
                                           )
                             )
        data_functions.asset_models_by_manufacturer()
        return redirect(url_for('view_solutions', asset_type=add_asset_form.add_asset_asset_type.data))

    return render_template('add_asset.html',
                           asset_types=db_connect.query_all(models.AssetTypes),
                           add_asset_form=add_asset_form,
                           add_asset_type_form=add_asset_type_form,
                           add_manufacturer_form=add_manufacturer_form,
                           add_department_form=add_department_form
                           )
Exemple #10
0
def view_one_asset():
    if request.args.get('asset_id'):
        asset_id = request.args.get('asset_id')
    else:
        asset_id = 0
    asset = db_connect.query_one_db(model=models.Assets,
                                    column=models.Assets.id,
                                    v=asset_id)
    data_functions.write_asset_data_to_json(asset_id)
    add_asset_type_form = forms.AddAssetTypeForm()
    add_manufacturer_form = forms.AddManufacturerForm()
    add_department_form = forms.AddDepartmentForm()
    all_asset_types = []
    all_departments = []
    all_manufacturers = []
    try:
        for t in db_connect.query_all(models.AssetTypes):
            all_asset_types.append((str(t.id), t.asset_type.title()))
    except:
        pass
    try:
        for d in db_connect.query_all(models.Departments):
            all_departments.append((str(d.id), d.department.title()))
    except:
        pass
    try:
        for m in db_connect.query_all(models.Manufacturers):
            all_manufacturers.append((str(m.id), m.manufacturer.title()))
    except:
        pass

    edit_asset_form = forms.EditAssetForm()
    edit_asset_form.asset_type.choices = all_asset_types
    edit_asset_form.department.choices = all_departments
    edit_asset_form.manufacturer.choices = all_manufacturers

    if add_asset_type_form.asset_type_submit.data and add_asset_type_form.validate():
        db_connect.insert_db(models.AssetTypes(asset_type=add_asset_type_form.asset_type.data))
        return redirect(url_for('view_one_asset', asset_id=asset_id))
    if add_department_form.department_submit.data and add_department_form.validate():
        db_connect.insert_db(models.Departments(department=add_department_form.department.data))
        return redirect(url_for('view_one_asset', asset_id=asset_id))
    if add_manufacturer_form.manufacturer_submit.data and add_manufacturer_form.validate():
        db_connect.insert_db(models.Manufacturers(manufacturer=add_manufacturer_form.manufacturer.data))
        return redirect(url_for('view_one_asset', asset_id=asset_id))

    if edit_asset_form.edit_asset_submit.data and edit_asset_form.validate():
        db_connect.update_column(model=models.Assets, id=asset_id, column=models.Assets.asset_type, v=edit_asset_form.asset_type.data)
        db_connect.update_column(model=models.Assets, id=asset_id, column=models.Assets.manufacturer, v=edit_asset_form.manufacturer.data)
        db_connect.update_column(model=models.Assets, id=asset_id, column=models.Assets.model, v=edit_asset_form.model.data)
        db_connect.update_column(model=models.Assets, id=asset_id, column=models.Assets.serial_no, v=edit_asset_form.serial_no.data)
        db_connect.update_column(model=models.Assets, id=asset_id, column=models.Assets.dia_asset_tag, v=edit_asset_form.dia_asset_tag.data)
        db_connect.update_column(model=models.Assets, id=asset_id, column=models.Assets.name, v=edit_asset_form.name.data)
        db_connect.update_column(model=models.Assets, id=asset_id, column=models.Assets.description, v=edit_asset_form.description.data)
        db_connect.update_column(model=models.Assets, id=asset_id, column=models.Assets.ip_address, v=edit_asset_form.ip_address.data)
        db_connect.update_column(model=models.Assets, id=asset_id, column=models.Assets.department, v=edit_asset_form.department.data)
        db_connect.update_column(model=models.Assets, id=asset_id, column=models.Assets.date_revised, v=datetime.datetime.now())
        if edit_asset_form.decommissioned.data:
            db_connect.update_column(model=models.Assets, id=asset_id, column=models.Assets.decommissioned, v=datetime.datetime.now())
        else:
            db_connect.update_column(model=models.Assets, id=asset_id, column=models.Assets.decommissioned, v=None)
        if edit_asset_form.deployed.data:
            db_connect.update_column(model=models.Assets, id=asset_id, column=models.Assets.deployed, v=True)
        else:
            db_connect.update_column(model=models.Assets, id=asset_id, column=models.Assets.deployed, v=False)
        return redirect(url_for('view_one_asset', asset_id=asset_id))

    edit_asset_form.asset_type.default = str(asset.asset_type)
    edit_asset_form.process()
    edit_asset_form.department.default = str(asset.department)
    edit_asset_form.process()
    edit_asset_form.manufacturer.default = str(asset.manufacturer)
    edit_asset_form.process()
    edit_asset_form.model.default = asset.model
    edit_asset_form.process()
    if asset.serial_no:
        edit_asset_form.serial_no.default = asset.serial_no
        edit_asset_form.process()
    if asset.dia_asset_tag:
        edit_asset_form.dia_asset_tag.default = asset.dia_asset_tag
        edit_asset_form.process()
    if asset.name:
        edit_asset_form.name.default = asset.name
        edit_asset_form.process()
    if asset.description:
        edit_asset_form.description = asset.description
        edit_asset_form.process()
    if asset.ip_address:
        edit_asset_form.ip_address = asset.ip_address
        edit_asset_form.process()
    if asset.decommissioned:
        edit_asset_form.decommissioned.default = True
        edit_asset_form.process()

    return render_template('view_one_asset.html',
                           asset_types=db_connect.query_all(models.AssetTypes),
                           manufacturers=data_functions.manufacturers_as_dict(),
                           departments=data_functions.departments_as_dict(),
                           asset_id=asset_id,
                           add_asset_type_form=add_asset_type_form,
                           add_manufacturer_form=add_manufacturer_form,
                           add_department_form=add_department_form,
                           edit_asset_form=edit_asset_form,
                           asset=asset)
Exemple #11
0
def view_one_solution():
    add_type_to_solution_form = forms.AddAssetTypeToSolutionForm()
    add_assoc_solution_form = forms.AddAssocSolutionForm()
    change_primary_asset_type_form = forms.ChangePrimaryAssetTypeForm()
    if request.args.get('solution_id'):
        solution_id = request.args.get('solution_id')
    else:
        solution_id = 0
    if request.args.get('asset_types'):
        for r in request.args.get('asset_types'):
            print(r)
    data_functions.one_solution_data(solution_id)
    solution = db_connect.query_one_db(model=models.Solutions, column=models.Solutions.id, v=solution_id)
    associated_asset_types = solution.associated_asset_types
    assoc_dict = {}
    all_types = db_connect.query_all(models.AssetTypes)
    # I believe the below comment is resolved. Leaving in just in case it is not.
    # this is causing an issue when reloading the page. It is returning too many things.
    for t in associated_asset_types:
        a_type = db_connect.query_one_db(model=models.AssetTypes, column=models.AssetTypes.id, v=t)
        assoc_dict[str(a_type.id)] = a_type.asset_type
    change_primary_choices = list(assoc_dict.items())
    change_primary_asset_type_form.all_asset_types.choices = change_primary_choices
    data_folder = Path("static/data/assoc_types_for_solution.json")
    with open(data_folder, 'w') as fp:
        json.dump(assoc_dict, fp, indent=4)
    data_functions.write_asset_types_to_json()

    data_functions.one_solution_asset_types(solution_id)

    add_type_to_solution_form.solution_id.data = solution_id
    non_assoc_types = []
    add_type_to_solution_form.asset_types.choices = non_assoc_types
    for t in all_types:
        if t.id not in associated_asset_types:
            non_assoc_types.append((str(t.id), t.asset_type))
    if change_primary_asset_type_form.change_primary_asset_type_submit.data and change_primary_asset_type_form.validate():
        db_connect.update_column(model=models.Solutions,
                                 column=models.Solutions.primary_asset_type,
                                 id=solution_id,
                                 v=change_primary_asset_type_form.all_asset_types.data)
        data_functions.one_solution_data(solution_id)
    # Adds asset type to solution
    if add_type_to_solution_form.add_submit.data and add_type_to_solution_form.validate():
        solution = db_connect.query_one_db(model=models.Solutions,
                                           column=models.Solutions.id,
                                           v=solution_id)
        updated_list = solution.associated_asset_types
        for t in add_type_to_solution_form.asset_types.data:
            if t not in solution.associated_asset_types:
                updated_list.append(int(t))
                print(t)
        db_connect.update_assoc_asset_types(sid=int(add_type_to_solution_form.solution_id.data),
                                            values=updated_list)
        db_connect.update_column(model=models.Solutions,
                                 id=solution_id,
                                 column=models.Solutions.date_revised,
                                 v=datetime.datetime.now())
        redirect(url_for('view_one_solution', solution_id=add_type_to_solution_form.solution_id.data))

    # Adds associated solution
    if add_assoc_solution_form.assoc_solution_submit.data and add_assoc_solution_form.validate():
        print(add_assoc_solution_form.assoc_solution_id.data + "will be added")
        update_column = db_connect.query_one_db(model=models.Solutions,
                                                column=models.Solutions.id,
                                                v=int(add_assoc_solution_form.main_solution_id.data))
        print(str(add_assoc_solution_form.assoc_solution_id.data) + " added to " + str(update_column.id))

        # This makes sure the associated solution is not the solution itself
        if int(add_assoc_solution_form.assoc_solution_id.data) == int(
                update_column.id):  # or update_column.associated_solutions is None or int(add_assoc_solution_form.assoc_solution_id.data) in update_column.associated_solutions:
            print("Caught to be the same solution!!!!!!!!!!!!!!!!!!!!!!!!!!")
            return redirect(url_for('view_one_solution', solution_id=add_assoc_solution_form.main_solution_id.data))
        else:
            # If the solution IDs are not the same, check if there is an associated solution yet.
            if update_column.associated_solutions is None:
                # If there are no associated solutions, make an empty list
                print("No associated solutions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
                associated_solutions = []
                db_connect.update_column(model=models.Solutions,
                                         id=int(add_assoc_solution_form.main_solution_id.data),
                                         column=models.Solutions.associated_solutions,
                                         v=associated_solutions + [int(add_assoc_solution_form.assoc_solution_id.data)])
            # If the solution IDs are not the same, make sure it is not already an associated solution
            elif int(add_assoc_solution_form.assoc_solution_id.data) not in update_column.associated_solutions:
                print("Adding to solution!!!!!!!!!!!!!!!!!!!!!!!")
                # If it is already an associated solution it will just reload the page. Can make a message later
                # There might be a way to make the Array field have to be unique with sqlalchemy.
                # In which case I could just but this in a try/except statement.
                associated_solutions = []
                s = data_functions.get_associated_solutions(solution_id)
                for i in s:
                    associated_solutions.append(i)
                print(associated_solutions + [int(add_assoc_solution_form.assoc_solution_id.data)])
                db_connect.update_column(model=models.Solutions,
                                         id=int(add_assoc_solution_form.main_solution_id.data),
                                         column=models.Solutions.associated_solutions,
                                         v=associated_solutions + [int(add_assoc_solution_form.assoc_solution_id.data)])
                redirect(url_for('view_one_solution', solution_id=add_assoc_solution_form.main_solution_id.data))

    # Get image filenames for each step in the solution
    solution_path = os.getcwd() + '\\static\data\\solution_images\\sid' + solution_id
    # solution_path = '\\documentation_system\\static\data\\solution_images\\sid' + solution_id
    # solution_path = 'documentation_system/static/data/solution_images/sid' + solution_id
    step_folders = [f.path for f in os.scandir(solution_path) if f.is_dir()]
    step_count = 1
    step_images = {}
    f = open(os.getcwd() + '\\static\data\one_solution.json')
    solution_json = json.load(f)
    # for s in step_folders:
    #     # This doesn't work because listdir(s) is a list of all the filenames in the directory
    #     this_step = []
    #     # for i in os.listdir(s):
    #     # Getting the info from the JSON data instead of the folder because that is what will update when editing
    #     # a solution so that is what it should pull from when selecting what images to get from the directory.
    for s in solution_json['Steps']:
        this_step = []
        for i in solution_json['Steps'][str(step_count)]['Images']:
            this_step.append(["data/solution_images/sid" + str(solution_id) + "/" + i, i])
        step_images[str(step_count)] = this_step
        step_count += 1
    print(step_images)
    # Info on view_one_solution page that may be useful on the edit checkbox for images
    # style='background-image: url("{{ url_for('static', filename=i[0]) }}")'

    return render_template('view_one_solution.html',
                           asset_types=db_connect.query_all(models.AssetTypes),
                           associated_asset_types=data_functions.one_solution_asset_types(solution_id),
                           assoc_solutions=data_functions.get_associated_solutions(solution_id),
                           non_assoc_types=non_assoc_types,
                           all_asset_types=data_functions.write_asset_types_to_json(),
                           add_type_to_solution_form=add_type_to_solution_form,
                           add_assoc_solution_form=add_assoc_solution_form,
                           change_primary_asset_type_form=change_primary_asset_type_form,
                           solution_id=solution_id,
                           steps=solution.steps,
                           title=solution.solution_title,
                           step_images=step_images,
                           public=solution.public,
                           )
Exemple #12
0
def software_names_as_dict():
    all_software = db_connect.query_all(models.Software)
    software_name_dict = {}
    for s in all_software:
        software_name_dict[s.id] = s.software_name
    return software_name_dict
Exemple #13
0
def software_companies_as_dict():
    all_software_companies = db_connect.query_all(models.SoftwareCompanies)
    software_co_dict = {}
    for s in all_software_companies:
        software_co_dict[s.id] = s.software_company
    return software_co_dict
Exemple #14
0
def departments_as_dict():
    all_departments = db_connect.query_all(models.Departments)
    dept_dict = {}
    for d in all_departments:
        dept_dict[d.id] = d.department
    return dept_dict
Exemple #15
0
def manufacturers_as_dict():
    all_manufacturers = db_connect.query_all(models.Manufacturers)
    manufacturer_dict = {}
    for m in all_manufacturers:
        manufacturer_dict[m.id] = m.manufacturer
    return manufacturer_dict