|
@ -50,10 +50,12 @@ class Admin(db.Model): |
|
|
if not session.get('admin'): |
|
|
if not session.get('admin'): |
|
|
return redirect(url_for("admin_login")) |
|
|
return redirect(url_for("admin_login")) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def object_as_dict(obj): |
|
|
def object_as_dict(obj): |
|
|
return {c.key: getattr(obj, c.key) |
|
|
return {c.key: getattr(obj, c.key) |
|
|
for c in inspect(obj).mapper.column_attrs} |
|
|
for c in inspect(obj).mapper.column_attrs} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Chemical(db.Model): |
|
|
class Chemical(db.Model): |
|
|
query: db.Query |
|
|
query: db.Query |
|
|
id = db.Column(db.Integer, primary_key=True) |
|
|
id = db.Column(db.Integer, primary_key=True) |
|
@ -86,7 +88,6 @@ class ChemicalForm(ModelForm): |
|
|
class Meta: |
|
|
class Meta: |
|
|
csrf = False |
|
|
csrf = False |
|
|
model = Chemical |
|
|
model = Chemical |
|
|
#exclude = ['id'] |
|
|
|
|
|
|
|
|
|
|
|
# Error Handlers |
|
|
# Error Handlers |
|
|
|
|
|
|
|
@ -155,6 +156,7 @@ def home(): |
|
|
|
|
|
|
|
|
# Routes for CRUD operations on chemicals |
|
|
# Routes for CRUD operations on chemicals |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/chemical/create", methods=['GET', 'POST']) |
|
|
@app.route("/chemical/create", methods=['GET', 'POST']) |
|
|
def chemical_create(): |
|
|
def chemical_create(): |
|
|
if not session.get('admin'): |
|
|
if not session.get('admin'): |
|
@ -165,9 +167,9 @@ def chemical_create(): |
|
|
new_chemical = Chemical(**form.data) |
|
|
new_chemical = Chemical(**form.data) |
|
|
db.session.add(new_chemical) |
|
|
db.session.add(new_chemical) |
|
|
db.session.commit() |
|
|
db.session.commit() |
|
|
return render_template("create_chemical.html", form=form, success=True) |
|
|
|
|
|
|
|
|
return render_template("create_chemical.html", form=ChemicalForm(), success=True) |
|
|
else: |
|
|
else: |
|
|
return render_template("create_chemical.html", form=ChemicalForm(), invalid=True) |
|
|
|
|
|
|
|
|
return render_template("create_chemical.html", form=form, invalid=True) |
|
|
else: |
|
|
else: |
|
|
form = ChemicalForm() |
|
|
form = ChemicalForm() |
|
|
return render_template("create_chemical.html", form=form) |
|
|
return render_template("create_chemical.html", form=form) |
|
@ -194,6 +196,7 @@ def chemical_update(id:int): |
|
|
form = ChemicalForm(**dct) |
|
|
form = ChemicalForm(**dct) |
|
|
return render_template("create_chemical.html", form=form, id=id) |
|
|
return render_template("create_chemical.html", form=form, id=id) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/chemical/<int:id>/delete") |
|
|
@app.route("/chemical/<int:id>/delete") |
|
|
def chemical_delete(id: int): |
|
|
def chemical_delete(id: int): |
|
|
if not session.get('admin'): |
|
|
if not session.get('admin'): |
|
@ -221,6 +224,7 @@ def chemical_all(): |
|
|
data.append({"url": url_for("chemical_view", id=x.id), "name": x.name, "mz": x.final_mz, "rt": x.final_rt}) |
|
|
data.append({"url": url_for("chemical_view", id=x.id), "name": x.name, "mz": x.final_mz, "rt": x.final_rt}) |
|
|
return jsonify(data) |
|
|
return jsonify(data) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/chemical/search") |
|
|
@app.route("/chemical/search") |
|
|
def search_api(): |
|
|
def search_api(): |
|
|
mz_min, mz_max = request.args.get('mz_min'), request.args.get('mz_max') |
|
|
mz_min, mz_max = request.args.get('mz_min'), request.args.get('mz_max') |
|
@ -235,7 +239,7 @@ def search_api(): |
|
|
if rt_min is not None and rt_max is None: |
|
|
if rt_min is not None and rt_max is None: |
|
|
rt_max = float(rt_min) + 3 |
|
|
rt_max = float(rt_min) + 3 |
|
|
elif rt_max is not None and rt_min is None: |
|
|
elif rt_max is not None and rt_min is None: |
|
|
rt_min = rt_max - 3 |
|
|
|
|
|
|
|
|
rt_min = float(rt_max) - 3 |
|
|
mz_min, mz_max = float(mz_min), float(mz_max) |
|
|
mz_min, mz_max = float(mz_min), float(mz_max) |
|
|
rt_min, rt_max = float(rt_min), float(rt_max) |
|
|
rt_min, rt_max = float(rt_min), float(rt_max) |
|
|
except ValueError: |
|
|
except ValueError: |
|
@ -259,6 +263,7 @@ def search_api(): |
|
|
def search(): |
|
|
def search(): |
|
|
return render_template("search.html") |
|
|
return render_template("search.html") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
if __name__ == "__main__": |
|
|
db.init_app(app) |
|
|
db.init_app(app) |
|
|
with app.app_context(): |
|
|
with app.app_context(): |
|
|