Beispiel #1
0
def get_update_kit(kit_id):
    form = UpdateForm(csrf_enabled=False)
    form.init()
    json = {
        "request": {
            "substance": {
                "kit_id": kit_id,
            }
        }
    }
    req = json.get("request")
    ret = KitFacade.read(req).get("response")
    if ret and ret.get("result") == const.RESPONSE_RESULT_SUCCESSFUL:
        substance = ret.get("substance")

        form.kit_id.data = substance.get("kit_id")
        form.kit_name.data = substance.get("kit_name")
        form.author_id.data = substance.get("author").get("author_id")
        form.category_id.data = substance.get("category").get("category_id")
        form.tags.data = ",".join(substance.get("tags"))
        form.description.data = substance.get("description")
        form.valid.data = str(substance.get("valid"))
    else:
        return redirect("/admin/author/list")
    return render_template("kit/update.html", form=form)
Beispiel #2
0
def post_update_kit(kit_id):
    form = UpdateForm(csrf_enabled=False)
    form.init()
    form.process(request.form)
    kit_file = request.files["kit_file"]

    if form.validate():
        json = {
            "request": {
                "substance": {
                    "kit_id": form.kit_id.data,
                    "kit_name": form.kit_name.data,
                    "category_id": form.category_id.data,
                    "tags": unicode(form.tags.data).split(","),
                    "description": form.description.data,
                    "kit_file": kit_file,
                    "valid": True if form.valid.data == "True" else False,
                }
            }
        }
        req = json.get("request")
        ret = KitFacade.update(req, secure=False).get("response")
        if ret and ret.get("result") == const.RESPONSE_RESULT_SUCCESSFUL:
            return redirect("/admin/author/update/" + form.author_id.data)
        else:
            form.errors["exceptions"] = [ret.get("message")]
    return render_template("kit/update.html", form=form)