From 009f0a863c123bb120400949f1b8bb09d8129add Mon Sep 17 00:00:00 2001 From: junikimm717 <68165832+junikimm717@users.noreply.github.com> Date: Sat, 24 Dec 2022 22:55:00 -0500 Subject: [PATCH] admin documentation added --- app.py | 6 ++--- templates/admin.html | 61 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/app.py b/app.py index da7affe..dc33a86 100755 --- a/app.py +++ b/app.py @@ -234,7 +234,7 @@ def search_api(): mz_min, mz_max = request.args.get('mz_min'), request.args.get('mz_max') rt_min, rt_max = request.args.get('rt_min'), request.args.get('rt_max') if (mz_min is None and mz_max is None) or (rt_min is None and rt_max is None): - abort(400) + return jsonify({"error": "invalid data"}), 400 try: if mz_min is not None and mz_max is None: mz_max = float(mz_min) + 3 @@ -247,8 +247,8 @@ def search_api(): mz_min, mz_max = float(mz_min), float(mz_max) rt_min, rt_max = float(rt_min), float(rt_max) except ValueError: - abort(400) - + return jsonify({"error": "invalid data"}), 400 + mz_filter = and_(mz_max > Chemical.final_mz, Chemical.final_mz > mz_min) rt_filter = and_(rt_max > Chemical.final_rt, Chemical.final_rt > rt_min) result = Chemical.query.filter( diff --git a/templates/admin.html b/templates/admin.html index 16400ff..1d24d75 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -1,11 +1,68 @@ {% extends "base.html" %} {% block content %} + + +

Admin Dashboard

-

You are {{user}}

+

Logged in as {{user}}

+ + +

Admin Authentication

+

+ Since there is now an admin, only admins can create new admin accounts. You can do so through the /admin/create + route. +

+

API Routes

+ +

Programmatically adding Chemicals

+

+ You need admin credentials to access the /chemical/create endpoint, so using an HTTP library + like python's requests library is highly recommended for keeping track of session cookies. +

+

+import requests
+session = requests.session()
+baseurl = "chemicaldb.teidkim.me"
+session.post(baseurl + "/admin/login", {"username": <username>, "password": <password>})
+fields = {
+    "chemical_db_id": <db id from another database>,
+    "library": (library),
+    # name, formula, and mass are required fields!
+    "name": (name of the chemical),
+    "formula": (molecular formula),
+    "mass": (monoisotopic mass, float),
+    "pubchem_cid": <string>,
+    "pubmed_refcount": <integer>
+    "standard_class": <string>
+    "inchikey": <inchikey>,
+    "inchikey14": <inchikey14>,
+    # final_mz and final_rt are required fields!
+    "final_mz": (m/z ratio after experiment, float),
+    "final_rt": (retention time after experiment, float),
+    "final_adduct": <string>,
+    "final_adduct": <string>,
+    "detected_adducts": <string>,
+    "adduct_calc_mz": <string>,
+    "msms_detected": <string if yes, do not include this field otherwise>
+    "msms_purity": <float>
+}
+session.post(baseurl + "/chemical/create", fields)
+        
{% endblock %} \ No newline at end of file