Im trying to use python and flask so that i can have someone submit a report (via ajax)
I got the items from my form in the python view, but now im trying to export it to my viewmodel so that from within my viewmodel i can call a function, however, im stuck as to how to do this with or continue...
This is my view
@bp.route("/rapid7/submit_report", methods=["GET"])
@login_required_with_ip_whitelist
def submit_report():
log_request()
vm = Rapid7()
return render_template("rapid7/submit_report.html", **vm.to_dict())
@bp.route("/rapid7/submit_report/process", methods=["POST"])
@login_required_with_ip_whitelist
def process():
log_request()
getFormData = (request.form)
reportName = (getFormData['reportName'])
districtName = (getFormData['districtName'])
rapid7Query = (getFormData['rapid7Query'])
rapid7SeverityLevel = (getFormData['rapid7SeverityLevel'])
print(reportName, districtName, rapid7Query, rapid7SeverityLevel)
r7report = Rapid7.check_action(reportName, districtName, rapid7Query, rapid7SeverityLevel)
print(r7report)
#exort to viewmodel
#r7_insightvm_report.configure_report(reportName, districtName, rapid7Query, rapid7SeverityLevel)
return reportName, districtName, rapid7Query, rapid7SeverityLevel
my viewmodel
from shutil import ExecError
from app.viewmodels.rapid7.rapid7 import rapid_7_report
from flask import current_app
from services.rapid7 import insightvmreport
from app.viewmodels.shared.viewmodelbase import ViewModelBase
class Rapid7(ViewModelBase):
def __init__(self):
super().__init__()
self.title = "Rapid7 Test"
self.check_action()
def check_action(self,reportName, districtName, rapid7Query, rapid7SeverityLevel):
try:
self.response = insightvmreport.check_action(
#path = current_app.config["r7_host_path"],
districtName=districtName,
reportName=reportName,
rapid7Query=rapid7Query,
rapid7SeverityLevel=rapid7SeverityLevel,
site_scope={"site":"DISTRICT 1 (EUR)","scan":"DISCOVERY"},
version="2.3.0",
action="download",
)
except Exception as e:
print(f"Failed to connect Error message: {e}")
when i run my flask app, it says NameError: name 'reportName' is not defined
i want to use the reportName from the view (from what the user submitted to the post request), if i do a print reportName, i can see that the user was able to submit the data
i kind of understand that i have Rapid7() in my view (under the get request), which could be part of the problem, but im wondering if there's a way around this or a way to fix it, in order for my ajax script to work the way i want (Reload without having to refresh), id like for it to load the class, if this wont work is there a better solution?