def add_asset(): """ Add a asset to the database """ add_asset = True form = AssetForm() if form.validate_on_submit(): asset = Asset( comments=form.comments.data, inventory_id=Inventory.query.first().id, location=Location.query.first().id, managed_by=current_user.id, assigned_to=current_user.id, certified_by=current_user.id, ) try: # add asset to the database db.session.add(asset) db.session.commit() flash('You have successfully added a new Asset.') except: # in case asset name already exists flash('Error: Asset cannot be created.') # redirect to assets page return redirect(url_for('assets.list_assets')) # load department template return render_template('assets/asset.html', action="Add", add_asset=add_asset, form=form, title="Add Asset")
def asset_edit(request, ids): status = 0 asset_types = ASSET_TYPE obj = get_object(Host, id=ids) if request.method == 'POST': af = AssetForm(request.POST, instance=obj) if af.is_valid(): af.save() status = 1 else: status = 2 else: af = AssetForm(instance=obj) return render(request, 'cmdb/asset_edit.html', locals())
def asset_add(request): temp_name = "cmdb/cmdb-header.html" if request.method == "POST": a_form = AssetForm(request.POST) if a_form.is_valid(): a_form.save() tips = u"增加成功!" display_control = "" else: tips = u"增加失败!" display_control = "" return render(request, "cmdb/asset_add.html", locals()) else: display_control = "none" a_form = AssetForm() return render(request, "cmdb/asset_add.html", locals())
def editAsset(request, pk): asset = Asset.objects.get(id=pk) if request.method == 'POST': form = AssetForm(request.POST, instance=asset) front_ip1 = asset.ip front_ip2 = asset.other_ip if form.is_valid(): ip1 = form.cleaned_data['ip'] ip2 = form.cleaned_data['other_ip'] if ip1: if front_ip1 != ip1: if Asset.objects.filter(ip=ip1).exists(): messages.add_message(request, messages.ERROR, u'IP: {0} 已经存在'.format(ip1)) return redirect(reverse('list')) if ip2: if front_ip2 != ip2: if Asset.objects.filter(other_ip=ip2).exists(): messages.add_message(request, messages.ERROR, u'IP: {0} 已经存在'.format(ip2)) return redirect(reverse('list')) form.save() messages.add_message(request, messages.SUCCESS, u'主机信息修改成功') return redirect(reverse('list')) else: form = AssetForm(instance=asset) return render(request, 'asset/asset_edit.html', locals())
def new_asset(): ''' Create new asset ''' form = AssetForm() if form.validate_on_submit(): my_asset = Asset() form.populate_obj(my_asset) db.session.add(my_asset) try: db.session.commit() # User info flash('Asset created correctly', 'success') return redirect(url_for('assets')) except: db.session.rollback() flash('Error generating asset.', 'danger') return render_template('web/new_asset.html', form=form)
def asset_add(request): shop = request.shop theme = shop.theme if request.method == 'POST': form = AssetForm(request.POST, request.FILES) if form.is_valid(): asset = form.save(commit=False) asset.theme = shop.theme asset.file.name = "%s_%s" % (shop.name, asset.file.name) asset.save() try: asset.render() request.flash['message'] = unicode(_("File successfully added.")) request.flash['severity'] = "success" except Exception, e: request.flash['message'] = "Error in asset. %s" % e request.flash['severity'] = "error" asset.delete() return HttpResponseRedirect(reverse('asset_add'))
def edit_asset(id): ''' Edit asset :param id: Id from asset ''' my_asset = Asset.query.filter_by(id=id).first() form = AssetForm(obj=my_asset) if form.validate_on_submit(): try: # Update asset form.populate_obj(my_asset) db.session.add(my_asset) db.session.commit() # User info flash('Saved successfully', 'success') except: db.session.rollback() flash('Error update asset.', 'danger') return render_template('web/edit_asset.html', form=form)
def asset_add(request): shop = request.shop theme = shop.theme if request.method == 'POST': form = AssetForm(request.POST, request.FILES) if form.is_valid(): asset = form.save(commit=False) asset.theme = shop.theme asset.file.name = "%s_%s" % (shop.name, asset.file.name) asset.save() try: asset.render() shop.last_date_to_change_layout = datetime.datetime.now() shop.save() request.flash['message'] = unicode(_("File successfully added.")) request.flash['severity'] = "success" except Exception, e: request.flash['message'] = "Error in asset. %s" % e request.flash['severity'] = "error" asset.delete()
def add_asset(id): """ Add a asset to the database """ #check_admin add_asset = True form = AssetForm() if form.validate_on_submit(): asset = Asset( name=form.name.data, description=form.description.data, analyse_id=id, sensitivity=form.sensitivity.data, criticality=form.criticality.data, ) try: # add asset to the database db.session.add(asset) db.session.commit() flash('You have successfully added a new asset.') except: # in case asset name already exists flash('Error: asset name already exists.') # redirect to the assets page #return redirect(url_for('home.list_assets')) return redirect(url_for('home.edit_analyse', id=id)) # load asset template w, h = 4, 4 myscores = [[0 for x in range(w)] for y in range(h)] # analyse = Analyse.query.get_or_404(id) return render_template('home/assets/asset.html', add_asset=add_asset, myscores=myscores, analyse_id=id, form=form, title='Add Asset')
def asset_add(request): shop = request.shop theme = shop.theme if request.method == 'POST': form = AssetForm(request.POST, request.FILES) if form.is_valid(): asset = form.save(commit=False) asset.theme = shop.theme asset.file.name = "%s_%s" % (shop.name, asset.file.name) asset.save() try: asset.render() shop.last_date_to_change_layout = datetime.datetime.now() shop.save() request.flash['message'] = unicode( _("File successfully added.")) request.flash['severity'] = "success" except Exception, e: request.flash['message'] = "Error in asset. %s" % e request.flash['severity'] = "error" asset.delete()
def virtual_edit(request,uuid): server = get_object_or_404(Server, uuid=uuid) asset = server.asset cpu = asset.cpu cf = CPUForm(instance=cpu) af = AssetForm(instance=asset) sf = ServerForm(instance=server) nic = NIC.objects.filter(asset=asset) project_all = Project.objects.all() project_host = server.project.all() projects = [p for p in project_all if p not in project_host] service_all = Service.objects.all() service_host = server.service.all() services = [s for s in service_all if s not in service_host] if request.method == 'POST': af = AssetForm(request.POST, instance=asset) sf = ServerForm(request.POST, instance=server) cf = CPUForm(request.POST, instance=cpu) if all((af.is_valid(),sf.is_valid(),cf.is_valid())): asset_data = af.save() cpu_data = cf.save(commit=False) cpu_data.asset = asset_data cpu_data.save() server_data = sf.save(commit=False) server_data.asset = asset_data server_data.save() sf.save_m2m() return HttpResponseRedirect('/allow/welcome/') return render(request,'assets/virtual_edit.html', locals())
def edit_asset(id): """ Edit an asset """ add_asset = False asset = Asset.query.get_or_404(id) form = AssetForm(obj=asset) if form.validate_on_submit(): asset.comments = form.comments.data db.session.commit() flash('You have successfully edited the asset.') # redirect to the departments page return redirect(url_for('assets.list_assets')) return render_template('assets/asset.html', action="Edit", add_asset=add_asset, form=form, asset=asset, title="Edit Asset")
def addAsset(request): if request.method == 'POST': form = AssetForm(request.POST) if form.is_valid(): new_asset = form.save() messages.add_message(request, messages.SUCCESS, u'主机添加成功') return redirect(reverse('list')) else: form = AssetForm() return render(request, 'asset/asset_add.html', locals())
def asset_edit(request, ids): status = 0 obj = get_object(Host, id=ids) if request.method == 'POST': af = AssetForm(request.POST, instance=obj) if af.is_valid(): af.save() status = 1 else: status = 2 else: af = AssetForm(instance=obj) return render_to_response('skcmdb/asset_edit.html', locals(), RequestContext(request))
def virtual_add(request): sf = ServerForm() af = AssetForm() cf = CPUForm() projects = Project.objects.all() services = Service.objects.all() ff_error = [] if request.method == 'POST': af = AssetForm(request.POST) sf = ServerForm(request.POST) cf = CPUForm(request.POST) ip = request.POST.get('ssh_host', '') if Server.objects.filter(ssh_host=ip): ff_error.append(u'添加失败, 该IP %s 已存在!' % ip) return render(request,'assets/virtual_add.html', locals()) if all((af.is_valid(),sf.is_valid(),cf.is_valid())): asset_data = af.save(commit=False) asset_data.asset_type = "virtual" asset_data.save() cpu_data = cf.save(commit=False) cpu_data.asset = asset_data cpu_data.save() cf.save_m2m() server_data = sf.save(commit=False) server_data.asset = asset_data server_data.save() sf.save_m2m() ## 网卡信息 nic_name0 = request.POST.get('nic_name0', '') if nic_name0: for i in range(6): nic_name = "nic_name" + str(i) nic_name = request.POST.get(nic_name) nic_memo = "nic_memo" + str(i) nic_memo = request.POST.get(nic_memo) nic_macaddress = "nic_macaddress" + str(i) nic_macaddress = request.POST.get(nic_macaddress) nic_ipaddress = "nic_ipaddress" + str(i) nic_ipaddress = request.POST.get(nic_ipaddress) nic_netmask = "nic_netmask" + str(i) nic_netmask = request.POST.get(nic_netmask) if nic_name and nic_macaddress: NIC.objects.create(asset = asset_data,name=nic_name,macaddress=nic_macaddress, ipaddress=nic_ipaddress,netmask=nic_netmask,memo=nic_memo) obj = get_object_or_404(Server, ssh_host=server_data.ssh_host) return render(request,'assets/asset_success.html', locals()) else: ff_error.append("关键信息遗漏或格式错误") return render(request,'assets/virtual_add.html', locals())
def asset(): form = AssetForm() # if request.method == 'POST' and form.validate_on_submit(): if request.method == 'POST': # [('Distribution', 'exponential'), ('assetName', 'aa'), ('entryVal', '100'), ('ownPercent', '0.2'), # ('periodYears', '10'), ('growthRate', '0.25'), ('sigma', ''), ('samples', '100'), ('submit', '')] modelData = dict( dist=request.form.get('Distribution'), assetName=request.form.get('assetName'), entryVal=float(request.form.get('entryVal')), ownPercent=float(request.form.get('ownPercent')), periodYears=int(request.form.get('periodYears')), growthRate=float(request.form.get('growthRate')), sigma=float(request.form.get('sigma') if request.form.get('sigma') != '' else 0), samples=int(request.form.get('samples')), ) chart = getFinalDistribution(modelData) script, div = components(chart) return render_template("pages/Asset.html", form=form, script1=script, div=div, asset=True) # print(30 * "=") # print(modelData) # print(30 * "=") return render_template('pages/Asset.html', asset=True, form=form)
def server_add(request): sf = ServerForm() af = AssetForm() projects = Project.objects.all() services = Service.objects.all() ff_error = [] if request.method == 'POST': af = AssetForm(request.POST) sf = ServerForm(request.POST) ip = request.POST.get('ssh_host', '') if Server.objects.filter(ssh_host=ip): ff_error.append(u'添加失败, 该IP %s 已存在!' % ip) return render(request, 'assets/server_add.html', locals()) if all((af.is_valid(), sf.is_valid())): asset_data = af.save(commit=False) asset_data.asset_type = "serverhost" asset_data.save() server_data = sf.save(commit=False) server_data.asset = asset_data server_data.save() sf.save_m2m() ##网卡 nic_name0 = request.POST.get('nic_name0', '') if nic_name0: for i in range(6): nic_name = "nic_name" + str(i) nic_name = request.POST.get(nic_name) nic_ipaddress = "nic_ipaddress" + str(i) nic_ipaddress = request.POST.get(nic_ipaddress) if nic_name and nic_ipaddress: NIC.objects.create(asset=asset_data, name=nic_name, ipaddress=nic_ipaddress) obj = server_data return render(request, 'assets/asset_success.html', locals()) else: ff_error.append("关键信息遗漏或格式错误") return render(request, 'assets/server_add.html', locals())
def add_pa_assets(park_id): form = AssetForm() pa_assets = [] rm_pa_assets = [] pa = park.query.get_or_404(park_id) if request.method == 'POST': for a in form.assets: #1 for aa in a.kids(): #1.1, 1.2 if aa.kids().__len__() > 0: for aaa in aa.kids(): #1.1.1, 1.1.2 p = request.form.get('{}'.format(aaa.id)) if pa.has_asset(aaa.id): paa = park_asset.query.filter_by( park_id=park_id, asset_id=aaa.id).first() if p == u'on': d = request.form.get('{}_desc'.format(aaa.id)) paa.description = d db.session.add(paa) else: db.session.delete(paa) elif p == u'on': d = request.form.get('{}_desc'.format(aaa.id)) pa_assets.append( park_asset(park_id=park_id, asset_id=aaa.id, desc=d)) else: p = request.form.get('{}'.format(aa.id)) if pa.has_asset(aa.id): paa = park_asset.query.filter_by( park_id=park_id, asset_id=aa.id).first() if p == u'on': d = request.form.get('{}_desc'.format(aa.id)) paa.description = d db.session.add(paa) else: db.session.delete(paa) elif p == u'on': d = request.form.get('{}_desc'.format(aaa.id)) pa_assets.append( park_asset(park_id=park_id, asset_id=aa.id, desc=d)) for a in form.practice_heads: #1 for aa in a.kids(): #1.1, 1.2 if aa.kids().__len__() > 0: for aaa in aa.kids(): #1.1.1, 1.1.2 p = request.form.get('{}_vgp'.format(aaa.id)) if pa.has_vgp(aaa.id): paa = park_domains_of_value.query.filter_by( park_id=park_id, asset_value_domain_id=aaa.id).first() if p == u'on': d = request.form.get('{}_vgp_desc'.format( aaa.id)) paa.description = d db.session.add(paa) else: db.session.delete(paa) elif p == u'on': d = request.form.get('{}_vgp_desc'.format(aaa.id)) pa_assets.append( park_domains_of_value( park_id=park_id, asset_value_domain_id=aaa.id, desc=d)) else: p = request.form.get('{}_vgp'.format(aa.id)) if pa.has_vgp(aa.id): paa = park_domains_of_value.query.filter_by( park_id=park_id, asset_value_domain_id=aa.id).first() if p == u'on': d = request.form.get('{}_vgp_desc'.format(aa.id)) paa.description = d db.session.add(paa) else: db.session.delete(paa) elif p == u'on': d = request.form.get('{}_vgp_desc'.format(aaa.id)) pa_assets.append( park_domains_of_value(park_id=park_id, asset_value_domain_id=aa.id, desc=d)) for a in form.value_heads: #1 for aa in a.kids(): #1.1, 1.2 if aa.kids().__len__() > 0: for aaa in aa.kids(): #1.1.1, 1.1.2 p = request.form.get('{}_domain'.format(aaa.id)) if pa.has_domains_of_value(aaa.id): paa = park_domains_of_value.query.filter_by( park_id=park_id, asset_value_domain_id=aaa.id).first() if p == u'on': d = request.form.get('{}_domain_desc'.format( aaa.id)) paa.description = d db.session.add(paa) else: db.session.delete(paa) elif p == u'on': d = request.form.get('{}_domain_desc'.format( aaa.id)) pa_assets.append( park_vgps(park_id=park_id, asset_value_domain_id=aaa.id, desc=d)) else: p = request.form.get('{}_domain'.format(aa.id)) if pa.has_domains_of_value(aa.id): paa = park_domains_of_value.query.filter_by( park_id=park_id, asset_value_domain_id=aa.id).first() if p == u'on': d = request.form.get('{}_domain_desc'.format( aa.id)) paa.description = d db.session.add(paa) else: db.session.delete(paa) elif p == u'on': d = request.form.get('{}_domain_desc'.format(aaa.id)) pa_assets.append( park_vgps(park_id=park_id, asset_value_domain_id=aa.id, desc=d)) for pa_a in pa_assets: db.session.add(pa_a) db.session.commit() # return redirect('/admin/park/') s = SurveyClass() return render_template('park/add_assets_to_park.html', pa=pa, assets=s.asset_heads(), practice_heads=s.practice_heads(), value_heads=s.value_heads())
return HttpResponse('File successfully saved.') else: errors = "\n".join([ "%s" % (v.as_text()) for k, v in form_asset.errors.iteritems() ]) return HttpResponse(errors) else: text = asset.file.read() form_asset = AssetEditForm(shop=shop, initial={'text': text}) param = {'form_asset': form_asset, 'asset': asset} except: logging.exception("MUERE!!!!!!!!!!!!!!!!!") add_asset_form = AssetForm() param.update({ 'theme': theme, 'add_asset_form': add_asset_form, 'assets': shop.theme.asset_set.all(), 'templates': theme.get_templates(), }) return render_to_response('store_admin/web_store/theme.html', param, RequestContext(request)) @shop_required @shop_admin_required def theme_export(request):
def server_add(request): sf = ServerForm() af = AssetForm() cf = CPUForm() projects = Project.objects.all() services = Service.objects.all() ff_error = [] if request.method == 'POST': af = AssetForm(request.POST) sf = ServerForm(request.POST) cf = CPUForm(request.POST) ip = request.POST.get('ssh_host', '') if Server.objects.filter(ssh_host=ip): ff_error.append(u'添加失败, 该IP %s 已存在!' % ip) return render(request,'assets/server_add.html', locals()) if all((af.is_valid(),sf.is_valid(),cf.is_valid())): asset_data = af.save() cpu_data = cf.save(commit=False) cpu_data.asset = asset_data cpu_data.save() cf.save_m2m() server_data = sf.save(commit=False) server_data.asset = asset_data server_data.save() sf.save_m2m() ##网卡 nic_name0 = request.POST.get('nic_name0', '') if nic_name0: for i in range(6): nic_name = "nic_name" + str(i) nic_name = request.POST.get(nic_name) nic_memo = "nic_memo" + str(i) nic_memo = request.POST.get(nic_memo) nic_macaddress = "nic_macaddress" + str(i) nic_macaddress = request.POST.get(nic_macaddress) nic_ipaddress = "nic_ipaddress" + str(i) nic_ipaddress = request.POST.get(nic_ipaddress) nic_netmask = "nic_netmask" + str(i) nic_netmask = request.POST.get(nic_netmask) nic_model = "nic_model" + str(i) nic_model = request.POST.get(nic_model) if nic_name and nic_macaddress: NIC.objects.create(asset = asset_data,name=nic_name,model=nic_model,macaddress=nic_macaddress, ipaddress=nic_ipaddress,netmask=nic_netmask,memo=nic_memo) return HttpResponseRedirect('/allow/welcome/') ## 内存 ram_model0 = request.POST.get('ram_model0', '') if ram_model0: for i in range(16): ram_model = "ram_model" + str(i) ram_model = request.POST.get(ram_model) ram_slot = "ram_slot" + str(i) ram_slot = request.POST.get(ram_slot) ram_capacity = "ram_capacity" + str(i) ram_capacity = request.POST.get(ram_capacity) ram_sn = "ram_sn" + str(i) ram_sn = request.POST.get(ram_sn) ram_memo = "ram_memo" + str(i) ram_memo = request.POST.get(ram_memo) if ram_model and ram_capacity: RAM.objects.create(asset = asset_data,model=ram_model,slot=ram_slot, capacity=ram_capacity,sn=ram_sn,memo=ram_memo) ##硬盘 disk_model0 = request.POST.get('disk_model0', '') if disk_model0: for i in range(12): disk_model = "disk_model" + str(i) disk_model = request.POST.get(disk_model) disk_manufactory = "disk_manufactory" + str(i) disk_manufactory = request.POST.get(disk_manufactory) disk_capacity = "disk_capacity" + str(i) disk_capacity = request.POST.get(disk_capacity) disk_iface_type = "disk_iface_type" + str(i) disk_iface_type = request.POST.get(disk_iface_type) disk_slot = "disk_slot" + str(i) disk_slot = request.POST.get(disk_slot) disk_sn = "disk_sn" + str(i) disk_sn = request.POST.get(disk_sn) disk_memo = "disk_memo" + str(i) disk_memo = request.POST.get(disk_memo) if disk_model and disk_capacity: Disk.objects.create(asset = asset_data,model=disk_model,manufactory=disk_manufactory,iface_type=disk_iface_type,slot=disk_slot, capacity=disk_capacity,sn=disk_sn,memo=disk_memo) ##raid卡 raid_model0 = request.POST.get('raid_model0', '') if raid_model0: for i in range(2): raid_model = "raid_model" + str(i) raid_model = request.POST.get(raid_model) raid_slot = "raid_slot" + str(i) raid_slot = request.POST.get(raid_slot) raid_sn = "raid_sn" + str(i) raid_sn = request.POST.get(raid_sn) raid_memo = "raid_memo" + str(i) raid_memo = request.POST.get(raid_memo) if raid_model and raid_slot: RaidAdaptor.objects.create(asset = asset_data,model=raid_model,slot=raid_slot, sn=raid_sn,memo=raid_memo) return HttpResponseRedirect('/allow/welcome/') else: ff_error.append("关键信息遗漏或格式错误") return render(request,'assets/server_add.html', locals())
def edit_asset(request, asset_id=None, template="assets/edit_asset.html", context=None): context = context or {} asset = None asset_detail = None asset_purchase_detail = None contact_person = None address = None if asset_id: asset = Asset.objects.get(pk=asset_id) asset_form = AssetForm(request.POST or None, instance=asset) if asset.asset_detail: asset_detail = AssetDetail.objects.get(pk=asset.asset_detail_id) asset_detail_form = AssetDetailForm(request.POST or None, instance=asset_detail) if asset.asset_purchase_detail: asset_purchase_detail = AssetPurchaseDetail.objects.get(pk=asset.asset_purchase_detail_id) asset_purchase_detail_form = AssetPurchaseDetailForm(request.POST or None, instance=asset_purchase_detail) if asset.contact_person: contact_person = Contact.objects.get(pk=asset.contact_person_id) contact_form = ContactForm(request.POST or None, instance=contact_person) if asset.address: address = Address.objects.get(pk=asset.address_id) address_form = AddressForm(request.POST or None, instance=address) else: asset_form = AssetForm(request.POST or None) asset_detail_form = AssetDetailForm(request.POST or None) asset_purchase_detail_form = AssetPurchaseDetailForm(request.POST or None) contact_form = ContactForm(request.POST or None) address_form = AddressForm(request.POST or None) if asset_detail_form.is_valid(): asset_detail = asset_detail_form.save(commit=False) asset_detail.created_by = request.user asset_detail.save() if asset_purchase_detail_form.is_valid(): asset_purchase_detail = asset_purchase_detail_form.save(commit=False) asset_purchase_detail.created_by = request.user asset_purchase_detail.save() if contact_form.is_valid(): contact_person = contact_form.save(commit=False) contact_person.save() if address_form.is_valid(): address = address_form.save(commit=False) address.address_type = 'business' address.save() if asset_form.is_valid(): asset = asset_form.save(commit=False) asset.asset_detail = asset_detail asset.asset_purchase_detail = asset_purchase_detail asset.contact_person = contact_person asset.address = address asset.created_by = request.user if asset.category_one == 'stationery': asset.serial_number = None else: asset.asset_detail.quantity = None asset.save() return redirect(reverse('assets:view_assets')) context['asset_form'] = asset_form context['asset_detail_form'] = asset_detail_form context['purchase_detail_form'] = asset_purchase_detail_form context['asset'] = asset context['contact_form'] = contact_form context['address_form'] = address_form return render(request, template, context)
def edit_asset(id): """ Edit a asset """ #check_admin add_asset = False asset = Asset.query.get_or_404(id) analyse = Analyse.query.get_or_404(asset.analyse_id) attackers = Attacker.query.all() form = AssetForm(obj=asset) if form.validate_on_submit(): asset.name = form.name.data asset.description = form.description.data #asset.analyse_id = form.analyse_id.data asset.criticality = form.criticality.data asset.sensitivity = form.sensitivity.data myexpsum = 0.0 myexparr = [0, 0, 0, 0] for attacker in attackers: myassetattacker = AssetAttacker.query.filter_by( asset_id=id).filter_by(attacker_id=attacker.id).first() myexparr[attacker.wert - 1] = max(myexparr[attacker.wert - 1], myassetattacker.wert) risk = myexparr[0] + myexparr[1] * 2 + myexparr[2] * 3 + myexparr[3] * 4 wu = max(form.criticality.data, form.sensitivity.data) myexpsum = (int(wu) * risk) asset.exposition = myexpsum / 10.0 db.session.add(asset) db.session.commit() #flash('You have successfully edited the asset.') # redirect to the asset page #return redirect(url_for('home.list_assets')) #asset = Asset.query.get(assetattacker.asset_id) return redirect(url_for('home.edit_analyse', id=asset.analyse_id)) form.description.data = asset.description form.name.data = asset.name #analyse = Analyse.query.get(asset.analyse_id) #form.analyse.default = asset.analyse_id # trying to set default select value form.sensitivity.data = str(asset.sensitivity) form.criticality.data = str(asset.criticality) form.exposition.data = asset.exposition # add an assetattacker per asset and attackers # get current asset.id id w, h = 4, 4 myscores = [[0 for x in range(w)] for y in range(h)] for attacker in attackers: attacker.myassetattacker = AssetAttacker.query.filter_by( asset_id=id).filter_by(attacker_id=attacker.id).first() if not (attacker.myassetattacker): mya = AssetAttacker() mya.asset_id = id mya.attacker_id = attacker.id mya.wert = -1 db.session.add(mya) db.session.commit() try: #myscores[ max((attacker.myassetattacker.wert-1),0) ][asset.wa-1] = "True" for myassetattackervaluemax in range( 0, max((attacker.myassetattacker.wert), 0)): myscores[max((attacker.wert - 1), 0)][myassetattackervaluemax] = "True" except: a = 2 return render_template('home/assets/asset.html', add_asset=add_asset, attackers=attackers, form=form, myscores=myscores, analyse_id=analyse.id, title="Edit Asset")