Esempio n. 1
0
def autofill(cid):
    mole = Molecule(CID=cid)
    mole.autofill(get_image=False)
    keywords = mole.get_keywords()
    keyword_resp = [keyword.to_hash() for keyword in keywords]
    resp = {"molecule": mole.to_hash(), "keywords": keyword_resp}
    return Response(json.dumps(resp), content_type="application/json")
Esempio n. 2
0
def create():
    data = request.json
    try:
        mole = do_save(g.user, **data)
        if request.headers.get("Accept") == "application/json":
            return Response(json.dumps(mole.to_hash()), headers={"Content-Type": "application/json"})
        return redirect("/")
    except Exception as e:
        db.session.rollback()
        msg = str(e)
        if e.__class__ == ValidationException().__class__:
            msg = e.errors()

        if request.headers.get("Accept") == "application/json":
            return Response(json.dumps({"molecule": Molecule.to_hash(), "error_details": msg}), status=400, headers={"Content-Type": "application/json"})
        flash(msg)
        return render_template("molecule/new.html", molecule=Molecule().to_hash())

    """
Esempio n. 3
0
def new():
    mole = Molecule()
    resp = json.dumps(mole.to_hash())
    return render_template("molecule/edit.html", molecule=resp, runninguser=json.dumps(g.user.to_hash()))