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}
def configupdate(dictID, user, dictDB, configs): adjustedJson, resaveNeeded = ops.updateDictConfig( dictDB, dictID, request.forms.id, json.loads(request.forms.content)) if resaveNeeded: configs = ops.readDictConfigs(dictDB) ops.resave(dictDB, dictID, configs) return {"success": True, "id": request.forms.id, "content": adjustedJson}
def configupdate(dictID, user, dictDB, configs): adjustedJson, resaveNeeded = ops.updateDictConfig( dictDB, dictID, request.forms.id, json.loads(request.forms.content)) redirUrl = "../../resave" if resaveNeeded else None return { "success": True, "id": request.forms.id, "content": adjustedJson, redirUrl: redirUrl }