예제 #1
0
def entryread(dictID, user, dictDB, configs):
    adjustedEntryID, xml, _title = ops.readEntry(dictDB, configs,
                                                 request.forms.id)
    adjustedEntryID = int(adjustedEntryID)
    xml = xml.replace(">\n<", "><")
    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:
            html = "<script type='text/javascript'>$('#viewer').html(Xemplatron.xml2html('" + xml.replace(
                "'", "\\'").replace("\n", "").replace(
                    "\r", "") + "', " + json.dumps(
                        configs["xemplate"]) + ", " + json.dumps(
                            configs["xema"]) + "));</script>"
    return {
        "success": (adjustedEntryID > 0),
        "id": adjustedEntryID,
        "content": xml,
        "contentHtml": html
    }
예제 #2
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})
예제 #3
0
파일: lexonomy.py 프로젝트: alhm02/lexonomy
def entryread(user, dictDB, configs):
    adjustedEntryID, xml, _title = ops.readEntry(dictDB, configs, request.forms.id)
    adjustedEntryID = int(adjustedEntryID)
    html = ""
    if xml:
        if configs["xemplate"].get("_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"):
            html = xml
    return {"success": (adjustedEntryID > 0), "id": adjustedEntryID, "content": xml, "contentHtml": html}