Ejemplo n.º 1
0
def entryeditor(dictID, doctype, user, dictDB, configs):
    if "_xsl" in configs["xemplate"] and configs["xemplate"]["_xsl"] != "":
        configs["xemplate"]["_xsl"] = "dummy"
    configs["xema"]["_root"] = configs["xema"]["root"]
    userdicts = ops.getDictsByUser(user["email"])
    if doctype in configs["xema"]["elements"]:
        configs["xema"]["root"] = doctype
    return template(
        "entryeditor.tpl", **{
            "siteconfig": siteconfig,
            "user": user,
            "dictID": dictID,
            "flagging": configs["flagging"],
            "doctype": doctype,
            "xema": configs["xema"],
            "xemplate": configs["xemplate"],
            "kex": configs["kex"],
            "xampl": configs["xampl"],
            "thes": configs["thes"],
            "collx": configs["collx"],
            "defo": configs["defo"],
            "titling": configs["titling"],
            "css": configs["xemplate"].get("_css"),
            "editing": configs["editing"],
            "subbing": configs["subbing"],
            "linking": configs["links"],
            "userdicts": userdicts
        })
Ejemplo n.º 2
0
def pushapi():
    data = json.loads(request.body.getvalue().decode('utf-8'))
    user = ops.verifyUserApiKey(data["email"], data["apikey"])
    if not user["valid"]:
        return {"success": False}
    else:
        if data["command"] == "makeDict":
            dictID = ops.suggestDictId()
            dictTitle = re.sub(r"^\s+", "", data["dictTitle"])
            if dictTitle == "":
                dictTitle = dictID
            dictBlurb = data["dictBlurb"]
            poses = data["poses"]
            labels = data["labels"]
            res = ops.makeDict(dictID, "push", dictTitle, dictBlurb,
                               user["email"])
            if not res:
                return {"success": False}
            else:
                dictDB = ops.getDB(dictID)
                configs = ops.readDictConfigs(dictDB)
                if configs["xema"]["elements"].get("partOfSpeech"):
                    for pos in poses:
                        configs["xema"]["elements"]["partOfSpeech"][
                            "values"].append({
                                "value": pos,
                                "caption": ""
                            })
                if configs["xema"]["elements"].get("collocatePartOfSpeech"):
                    for pos in poses:
                        configs["xema"]["elements"]["collocatePartOfSpeech"][
                            "values"].append({
                                "value": pos,
                                "caption": ""
                            })
                if configs["xema"]["elements"].get("label"):
                    for label in labels:
                        configs["xema"]["elements"]["label"]["values"].append({
                            "value":
                            label,
                            "caption":
                            ""
                        })
                ops.updateDictConfig(dictDB, dictID, "xema", configs["xema"])
                return {"success": True, "dictID": dictID}
        elif data["command"] == "listDicts":
            dicts = ops.getDictsByUser(user["email"])
            return {"entries": dicts, "success": True}
        elif data["command"] == "createEntries":
            dictID = data["dictID"]
            entryXmls = data["entryXmls"]
            dictDB = ops.getDB(dictID)
            configs = ops.readDictConfigs(dictDB)
            for entry in entryXmls:
                ops.createEntry(dictDB, configs, None, entry, user["email"],
                                {"apikey": data["apikey"]})
            return {"success": True}
        else:
            return {"success": False}
Ejemplo n.º 3
0
def home():
    res = ops.verifyLogin(request.cookies.email, request.cookies.sessionkey)
    if res["loggedin"] and siteconfig["consent"] and siteconfig["consent"]["terms"] and not res["consent"]:
        return redirect("/consent/")
    dicts = ops.getDictsByUser(res["email"])
    error = ""
    version = ""
    if os.path.isfile("version.txt"):
        with open("version.txt", "r") as version_file:
            version = version_file.read()
    if request.cookies.jwt_error:
        error = request.cookies.jwt_error
        response.delete_cookie("jwt_error", path="/")
    return template("home.tpl", **{"user": res, "siteconfig": siteconfig, "dicts": dicts, "error": error, "version": version})