Skip to content

Commit

Permalink
added check to make sure all options have something selected
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterHindes committed Aug 18, 2024
1 parent 60c1b12 commit f0942a7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
23 changes: 18 additions & 5 deletions run-native.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
#!/bin/bash
python3 -m venv venv
. venv/bin/activate
pip install -r src/requirements.txt
python src/main.py
rm -r venv

if [[ "$@" == *"--clean"* ]]; then
rm -r venv
fi

if [ ! -d "venv" ]; then
python3 -m venv venv
. venv/bin/activate
pip install -r src/requirements.txt
else
. venv/bin/activate
fi

if [[ "$@" == *"--debug"* ]]; then
python3 src/main.py --debug
else
python src/main.py
fi
33 changes: 21 additions & 12 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import argparse
from flask import Flask, request, render_template, send_file
import webbrowser
from gensheet import excel_sheet
Expand All @@ -20,31 +21,39 @@ def favicon():
# This takes an html form post and prints it to the console returning success to the browser
@app.route('/submit', methods=['POST'])
def submit():
# print(request.form.getlist('media'))
# print(request.form["replicates"])

# <OptionsSection title="Select Media" name="media" options={["lb", "m9"]} selectFirst={true} />
# <OptionsSection title="Select a strain" name="strain" options={["top10", "dh5a"]} />
# <OptionsSection title="Select a supplement" name="supplement" options={["atc", "iptg"]} />
# <OptionsSection title="Select a vector" name="vector" options={["repressilator", "toggleswitch"]} />

# <OptionSlider title="Number of replicates" name="replicates" min="1" max="10" initialVal="1" />

# get the lists from the form
lists = [
request.form.getlist('media'),
request.form.getlist('strain'),
request.form.getlist('supplement'),
request.form.getlist('vector')
]

#check that all lists have at least one item
for l in lists:
if len(l) == 0:
return render_template('response.html',
message="Error, at least one item must be selected from each list, please go back.",
color="red"
)

# get the number of replicates from the form
replicates = int(request.form["replicates"])

# generate the excel sheet
excel_sheet(lists, replicates)

# return success to the browser
return render_template('response.html',
message="success")
message="Success",
color="green"
)

port = 4269
# webbrowser.open('http://localhost:'+str(port))
if __name__ == '__main__':
app.run(debug=False, port=port, host='0.0.0.0')
parser = argparse.ArgumentParser(description='Run Flask app with optional debug mode.')
parser.add_argument('--debug', action='store_true', help='Run the Flask app in debug mode')
args = parser.parse_args()

app.run(debug=args.debug, port=port, host='0.0.0.0')
2 changes: 1 addition & 1 deletion src/templates/response.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<title>Success</title>
</head>
<body>
<h1>Server Says: {{message}}</h1>
<h1>Server Says:</h1> <h2 style="color: {{color}}">{{message}}</h2>
<a href="/">Go Back</a>
</body>
</html>

0 comments on commit f0942a7

Please sign in to comment.