예제 #1
0
def publicentry(dictID, entryID):
    if not ops.dictExists(dictID):
        return redirect("/")
    dictDB = ops.getDB(dictID)
    user, configs = ops.verifyLoginAndDictAccess(request.cookies.email, request.cookies.sessionkey, dictDB)
    if not configs["publico"]["public"]:
        return redirect("/"+dictID)
    adjustedEntryID, xml, _title = ops.readEntry(dictDB, configs, entryID)
    if adjustedEntryID == 0:
        return redirect("/"+dictID)
    nabes = ops.readNabesByEntryID(dictDB, dictID, entryID, configs)
    if "_xsl" in configs["xemplate"] and configs["xemplate"]["_xsl"] != "":
        from lxml import etree
        xslt_root = etree.XML(configs["xemplate"]["_xsl"].encode("utf-8"))
        transform = etree.XSLT(xslt_root)
        doc_root = etree.XML(xml.encode("utf-8"))
        html = transform(doc_root)
    elif "_css" in configs["xemplate"] and configs["xemplate"]["_css"] != "":
        html = xml
    else:
        entrydata = re.sub(r"'", "\\'", xml)
        entrydata = re.sub(r"\n", " ", entrydata)
        html = "<script type='text/javascript'>$('#viewer').html(Xemplatron.xml2html('"+entrydata+"', "+json.dumps(configs["xemplate"])+", "+json.dumps(configs["xema"])+"));</script>"
        #rewrite xemplatron to python, too?
    css = ""
    if "_css" in configs["xemplate"]:
        css = configs["xemplate"]["_css"]
    return template("dict-entry.tpl", **{"siteconfig": siteconfig, "user": user, "dictID": dictID, "dictTitle": configs["ident"]["title"], "dictBlurb": configs["ident"]["blurb"], "publico": configs["publico"], "entryID": adjustedEntryID, "nabes": nabes, "html": html, "title": _title, "css": css})
예제 #2
0
def history(dictID):
    if not ops.dictExists(dictID):
        return redirect("/")
    user, configs = ops.verifyLoginAndDictAccess(request.cookies.email,
                                                 request.cookies.sessionkey,
                                                 ops.getDB(dictID))
    history = ops.readDictHistory(ops.getDB(dictID), dictID, configs,
                                  request.forms.id)
    res_history = []
    for item in history:
        xml = item["content"]
        html = ""
        if xml:
            if configs["xemplate"].get(
                    "_xsl") and configs["xemplate"]["_xsl"] != "":
                import lxml.etree as ET
                dom = ET.XML(xml.encode("utf-8"))
                xslt = ET.XML(configs["xemplate"]["_xsl"].encode("utf-8"))
                html = str(ET.XSLT(xslt)(dom))
            elif configs["xemplate"].get(
                    "_css") and configs["xemplate"]["_css"] != "":
                html = xml
            else:
                entrydata = re.sub(r"'", "\\'", xml)
                entrydata = re.sub(r"[\n\r]", "", entrydata)
                html = "<script type='text/javascript'>$('#viewer').html(Xemplatron.xml2html('" + entrydata + "', " + json.dumps(
                    configs["xemplate"]) + ", " + json.dumps(
                        configs["xema"]) + "));</script>"
        item["contentHtml"] = html
        res_history.append(item)
    return {"history": res_history}
예제 #3
0
def dictsearch(dictID):
    if not ops.dictExists(dictID):
        return redirect("/")
    dictDB = ops.getDB(dictID)
    user, configs = ops.verifyLoginAndDictAccess(request.cookies.email,
                                                 request.cookies.sessionkey,
                                                 dictDB)
    if not configs["publico"]["public"]:
        return redirect("/" + dictID)
    entries = ops.listEntriesPublic(dictDB, dictID, configs, request.query.q)
    if len(entries) == 1 and entries[0]["exactMatch"]:
        redirect("/" + dictID + "/" + entries[0]["id"])
    else:
        nabes = ops.readNabesByText(dictDB, dictID, configs, request.query.q)
        return template(
            "dict-search.tpl", **{
                "siteconfig": siteconfig,
                "user": user,
                "dictID": dictID,
                "dictTitle": configs["ident"]["title"],
                "dictBlurb": configs["ident"]["blurb"],
                "publico": configs["publico"],
                "q": request.query.q,
                "entries": entries,
                "nabes": nabes
            })
예제 #4
0
def publicentryxml(dictID, entryID):
    if not ops.dictExists(dictID):
        return redirect("/")
    dictDB = ops.getDB(dictID)
    user, configs = ops.verifyLoginAndDictAccess(request.cookies.email, request.cookies.sessionkey, dictDB)
    if not configs["publico"]["public"]:
        return redirect("/"+dictID)
    if not "licence" in configs["publico"] or not siteconfig["licences"][configs["publico"]["licence"]]["canDownloadXml"]:
        return redirect("/"+dictID)
    res = ops.exportEntryXml(dictDB, dictID, entryID, configs, siteconfig["baseUrl"])
    if res["entryID"] == 0:
        return redirect("/"+dictID)
    response.content_type = "text/xml; charset=utf-8"
    return res["xml"]
예제 #5
0
파일: lexonomy.py 프로젝트: alhm02/lexonomy
 def wrapper_verifyLoginAndDictAccess(*args, **kwargs):
     try:
         conn = ops.getDB(kwargs["dictID"])
     except IOError:
         abort(404, "No such dictionary")
     res, configs = ops.verifyLoginAndDictAccess(request.cookies.email, request.cookies.sessionkey, conn)
     for r in checkRights:
         if not res.get(r, False):
             return res
     del kwargs["dictID"]
     kwargs["user"] = res
     kwargs["dictDB"] = conn
     kwargs["configs"] = configs
     return func(*args, **kwargs)
예제 #6
0
def publicdict(dictID):
    if not ops.dictExists(dictID):
        return redirect("/")
    user, configs = ops.verifyLoginAndDictAccess(request.cookies.email,
                                                 request.cookies.sessionkey,
                                                 ops.getDB(dictID))
    blurb = ops.markdown_text(configs["ident"]["blurb"])
    return template(
        "dict.tpl", **{
            "siteconfig": siteconfig,
            "user": user,
            "dictID": dictID,
            "dictTitle": configs["ident"]["title"],
            "dictBlurb": blurb,
            "publico": configs["publico"]
        })
예제 #7
0
def linkNaisc(dictID, user, dictDB, configs):
    otherdictID = request.query.otherdictID
    if dictID == otherdictID:
        abort(
            400,
            "Linking dictionary to the same dictionary does not make any sense"
        )
    try:
        otherconn = ops.getDB(otherdictID)
    except IOError:
        abort(404, "No such dictionary")
    _res, otherconfigs = ops.verifyLoginAndDictAccess(
        request.cookies.email, request.cookies.sessionkey, otherconn)
    res = ops.linkNAISC(dictDB, dictID, configs, otherconn, otherdictID,
                        otherconfigs)
    return res