예제 #1
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)
예제 #2
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
                           )
예제 #3
0
def addDepartment(department):
    row = models.Departments(key_name=addUnderscore(department))
    row.active = '1'
    row.departmentName = addUnderscore(department)  #department_name
    row.put()
예제 #4
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)
예제 #5
0
def getDepartments():
    q = models.Departments().all()
    row = q.fetch(100)
    return row