示例#1
0
文件: edit.py 项目: hibozzy/mediatum
def content(req):

    user = users.getUserFromRequest(req)

    access = AccessData(req)
    language = lang(req)
    if not access.user.isEditor():
        return req.writeTAL("web/edit/edit.html", {}, macro="error")

    if "id" in req.params and len(req.params) == 1:
        nid = req.params.get("id")
        try:
            node = tree.getNode(nid)
        except:
            node = None
        if node:
            cmd = "cd (%s %r, %r)" % (nid, node.name, node.type)
            logger.info("%s: %s" % (user.getName(), cmd))
            # logging.getLogger("usertracing").info("%s: in editor %s" % (user.getName(), cmd))
        else:
            cmd = "ERROR-cd to non-existing id=%r" % nid
            logger.error("%s: %s") % (user.getName(), cmd)

    if "action" in req.params and req.params["action"] == "upload":
        pass

    content = {"script": "", "body": ""}
    v = {"dircontent": "", "notdirectory": 0, "operations": ""}
    try:
        v["nodeiconpath"] = getEditorIconPath(node)
    except:
        v["nodeiconpath"] = "webtree/directory.gif"

    path = req.path[1:].split("/")
    if len(path) >= 4:
        req.params["style"] = "popup"
        req.params["id"] = path[1]
        req.params["tab"] = path[2]
        req.params["option"] = path[3]
    getEditModules()

    if not access.user.isEditor():
        return req.writeTAL("web/edit/edit.html", {}, macro="error")

    # remove all caches for the frontend area- we might make changes there
    for sessionkey in ["contentarea", "navframe"]:
        try:
            del req.session[sessionkey]
        except:
            pass

    ids = getIDs(req)

    if req.params.get("type", "") == "help" and req.params.get("tab", "") == "upload":
        return upload_help(req)

    if len(ids) > 0:
        node = tree.getNode(ids[0])
    tabs = "content"
    if node.type == "root":
        tabs = "content"
    elif node.id == users.getUploadDir(access.getUser()).id:
        tabs = "upload"
    elif node.id == users.getImportDir(access.getUser()).id:
        tabs = "imports"
    elif hasattr(node, "getDefaultEditTab"):
        tabs = node.getDefaultEditTab()
        v["notdirectory"] = 0

    current = req.params.get("tab", tabs)
    logger.debug("... %s inside %s.%s: ->  !!! current = %r !!!" % (get_user_id(req), __name__, funcname(), current))
    msg = "%s selected editor module is %r" % (user.getName(), current)
    jsfunc = req.params.get("func", "")
    if jsfunc:
        msg = msg + (", js-function: %r" % jsfunc)
    logger.info(msg)

    # some tabs operate on only one file
    # if current in ["files", "view", "upload"]:
    if current in ["files", "upload"]:
        ids = ids[0:1]

    # display current images
    if not tree.getNode(ids[0]).isContainer():
        v["notdirectory"] = 1
        items = []
        if current != "view":
            for id in ids:
                node = tree.getNode(id)
                if hasattr(node, "show_node_image"):
                    if not isDirectory(node) and not node.isContainer():
                        items.append((id, node.show_node_image()))
                    else:
                        items.append(("", node.show_node_image()))
        v["items"] = items
        logger.debug(
            "... %s inside %s.%s: -> display current images: items: %r"
            % (get_user_id(req), __name__, funcname(), [_t[0] for _t in items])
        )
        try:
            n = tree.getNode(req.params.get("src", req.params.get("id")))
            if current == "metadata" and "save" in req.params:
                pass
            s = []
            while n:
                try:
                    s = [
                        '<a onClick="activateEditorTreeNode(%r); return false;" href="/edit/edit_content?id=%s">%s</a>'
                        % (n.id, n.id, n.getLabel(lang=language))
                    ] + s
                except:
                    s = [
                        '<a onClick="activateEditorTreeNode(%r); return false;" href="/edit/edit_content?id=%s">%s</a>'
                        % (n.id, n.id, n.name)
                    ] + s

                p = n.getParents()
                if p:
                    n = p[0]
                else:
                    n = None
            v["dircontent"] = " <b>&raquo;</b> ".join(s[1:])
        except:
            logger.exception("ERROR displaying current images")

    else:  # or current directory
        n = tree.getNode(ids[0])
        s = []
        while n:
            if len(s) == 0:
                try:
                    s = ["%s" % (n.getLabel(lang=language))]
                except:
                    s = ["%s" % (n.name)]
            else:
                try:
                    s = [
                        '<a onClick="activateEditorTreeNode(%r); return false;" href="/edit/edit_content?id=%s">%s</a>'
                        % (n.id, n.id, n.getLabel(lang=language))
                    ] + s
                except:
                    s = [
                        '<a onClick="activateEditorTreeNode(%r); return false;" href="/edit/edit_content?id=%s">%s</a>'
                        % (n.id, n.id, n.name)
                    ] + s

            p = n.getParents()
            if p:
                n = p[0]
            else:
                n = None
        v["dircontent"] = " <b>&raquo;</b> ".join(s[1:])

    if current == "globals":
        basedir = config.get("paths.datadir")
        file_to_edit = None

        if "file_to_edit" in req.params:
            file_to_edit = req.params["file_to_edit"]

        if not file_to_edit:
            d = node.getStartpageDict()
            if d and lang(req) in d:
                file_to_edit = d[lang(req)]

        found = False
        for f in node.getFiles():
            if f.mimetype == "text/html":
                filepath = f.retrieveFile().replace(basedir, "")
                if file_to_edit == filepath:
                    found = True
                    result = edit_editor(req, node, f)
                    if result == "error":
                        logger.error("error editing %r" % f.retrieveFile())
                    break

        if not found:
            edit_editor(req, node, None)

    elif current == "tab_metadata":
        edit_metadata(req, ids)  # undefined
    elif current == "tab_upload":
        edit_upload(req, ids)  # undefined
    elif current == "tab_import":
        edit_import(req, ids)  # undefined
    elif current == "tab_globals":
        req.write("")
    elif current == "tab_lza":
        edit_lza(req, ids)  # undefined
    elif current == "tab_logo":
        edit_logo(req, ids)  # undefined
    else:
        t = current.split("_")[-1]
        if t in editModules.keys():
            c = editModules[t].getContent(req, ids)
            if c:
                content["body"] += c  # use standard method of module
            else:
                logger.debug("empty content")
                return
        else:
            req.setStatus(httpstatus.HTTP_INTERNAL_SERVER_ERROR)
            content["body"] += req.getTAL("web/edit/edit.html", {"module": current}, macro="module_error")

    if req.params.get("style", "") != "popup":  # normal page with header
        v["tabs"] = handletabs(req, ids, tabs)
        v["script"] = content["script"]
        v["body"] = content["body"]
        v["paging"] = showPaging(req, current, ids)
        v["node"] = node
        v["ids"] = req.params.get("ids", "").split(",")
        if req.params.get("ids", "") == "":
            v["ids"] = req.params.get("id", "").split(",")
        v["tab"] = current
        v["operations"] = req.getTAL(
            "web/edit/edit_common.html", {"iscontainer": node.isContainer()}, macro="show_operations"
        )
        user = users.getUserFromRequest(req)
        v["user"] = user
        v["language"] = lang(req)
        v["t"] = translation_t

        v["spc"] = [Menu("sub_header_frontend", "../", target="_parent")]
        if user.isAdmin():
            v["spc"].append(Menu("sub_header_administration", "../admin", target="_parent"))

        if user.isWorkflowEditor():
            v["spc"].append(Menu("sub_header_workflow", "../publish", target="_parent"))

        v["spc"].append(Menu("sub_header_logout", "../logout", target="_parent"))

        # add icons to breadcrumbs
        ipath = "webtree/directory.gif"
        if node and node.isContainer():
            if node.name == "home" or "Arbeitsverzeichnis" in node.name:
                ipath = "webtree/homeicon.gif"
            elif node.name == "Uploads":
                ipath = "webtree/uploadicon.gif"
            elif node.name == "Importe":
                ipath = "webtree/importicon.gif"
            elif node.name == "Inkonsistente Daten":
                ipath = "webtree/faultyicon.gif"
            elif node.name == "Papierkorb":
                ipath = "webtree/trashicon.gif"
            else:
                ipath = getEditorIconPath(node)

        v["dircontent"] += '&nbsp;&nbsp;<img src="' + "/img/" + ipath + '" />'

        return req.writeTAL("web/edit/edit.html", v, macro="frame_content")
示例#2
0
文件: edit.py 项目: hibozzy/mediatum
def content(req):

    user = users.getUserFromRequest(req)

    access = AccessData(req)
    language = lang(req)
    if not access.user.isEditor():
        return req.writeTAL("web/edit/edit.html", {}, macro="error")

    if 'id' in req.params and len(req.params) == 1:
        nid = req.params.get('id')
        try:
            node = tree.getNode(nid)
        except:
            node = None
        if node:
            cmd = "cd (%s %r, %r)" % (nid, node.name, node.type)
            logger.info("%s: %s" % (user.getName(), cmd))
            #logging.getLogger("usertracing").info("%s: in editor %s" % (user.getName(), cmd))
        else:
            cmd = "ERROR-cd to non-existing id=%r" % nid
            logger.error("%s: %s") % (user.getName(), cmd)

    if 'action' in req.params and req.params['action'] == 'upload':
        pass

    content = {'script': '', 'body': ''}
    v = {'dircontent': '', 'notdirectory': 0, 'operations': ''}
    try:
        v['nodeiconpath'] = getEditorIconPath(node)
    except:
        v['nodeiconpath'] = "webtree/directory.gif"

    path = req.path[1:].split("/")
    if len(path) >= 4:
        req.params["style"] = "popup"
        req.params["id"] = path[1]
        req.params["tab"] = path[2]
        req.params["option"] = path[3]
    getEditModules()

    if not access.user.isEditor():
        return req.writeTAL("web/edit/edit.html", {}, macro="error")

    # remove all caches for the frontend area- we might make changes there
    for sessionkey in ["contentarea", "navframe"]:
        try:
            del req.session[sessionkey]
        except:
            pass

    ids = getIDs(req)

    if req.params.get("type", "") == "help" and req.params.get("tab", "") == "upload":
        return upload_help(req)

    if len(ids) > 0:
        node = tree.getNode(ids[0])
    tabs = "content"
    if node.type == "root":
        tabs = "content"
    elif node.id == users.getUploadDir(access.getUser()).id:
        tabs = "upload"
    elif node.id == users.getImportDir(access.getUser()).id:
        tabs = "imports"
    elif hasattr(node, "getDefaultEditTab"):
        tabs = node.getDefaultEditTab()
        v["notdirectory"] = 0

    current = req.params.get("tab", tabs)
    logger.debug("... %s inside %s.%s: ->  !!! current = %r !!!" %
                 (get_user_id(req), __name__, funcname(), current))
    msg = "%s selected editor module is %r" % (user.getName(), current)
    jsfunc = req.params.get("func", "")
    if jsfunc:
        msg = msg + (', js-function: %r' % jsfunc)
    logger.info(msg)

    # some tabs operate on only one file
    # if current in ["files", "view", "upload"]:
    if current in ["files", "upload"]:
        ids = ids[0:1]

    # display current images
    if not tree.getNode(ids[0]).isContainer():
        v["notdirectory"] = 1
        items = []
        if current != "view":
            for id in ids:
                node = tree.getNode(id)
                if hasattr(node, "show_node_image"):
                    if not isDirectory(node) and not node.isContainer():
                        items.append((id, node.show_node_image()))
                    else:
                        items.append(("", node.show_node_image()))
        v["items"] = items
        logger.debug("... %s inside %s.%s: -> display current images: items: %r" %
                     (get_user_id(req), __name__, funcname(), [_t[0] for _t in items]))
        try:
            n = tree.getNode(req.params.get('src', req.params.get('id')))
            if current == 'metadata' and 'save' in req.params:
                pass
            s = []
            while n:
                try:
                    s = ['<a onClick="activateEditorTreeNode(%r); return false;" href="/edit/edit_content?id=%s">%s</a>' %
                         (n.id, n.id, n.getLabel(lang=language))] + s
                except:
                    s = ['<a onClick="activateEditorTreeNode(%r); return false;" href="/edit/edit_content?id=%s">%s</a>' %
                         (n.id, n.id, n.name)] + s

                p = n.getParents()
                if p:
                    n = p[0]
                else:
                    n = None
            v["dircontent"] = ' <b>&raquo;</b> '.join(s[1:])
        except:
            logger.exception('ERROR displaying current images')

    else:  # or current directory
        n = tree.getNode(ids[0])
        s = []
        while n:
            if len(s) == 0:
                try:
                    s = ['%s' % (n.getLabel(lang=language))]
                except:
                    s = ['%s' % (n.name)]
            else:
                try:
                    s = ['<a onClick="activateEditorTreeNode(%r); return false;" href="/edit/edit_content?id=%s">%s</a>' %
                         (n.id, n.id, n.getLabel(lang=language))] + s
                except:
                    s = ['<a onClick="activateEditorTreeNode(%r); return false;" href="/edit/edit_content?id=%s">%s</a>' %
                         (n.id, n.id, n.name)] + s

            p = n.getParents()
            if p:
                n = p[0]
            else:
                n = None
        v["dircontent"] = ' <b>&raquo;</b> '.join(s[1:])

    if current == "globals":
        basedir = config.get("paths.datadir")
        file_to_edit = None

        if "file_to_edit" in req.params:
            file_to_edit = req.params["file_to_edit"]

        if not file_to_edit:
            d = node.getStartpageDict()
            if d and lang(req) in d:
                file_to_edit = d[lang(req)]

        found = False
        for f in node.getFiles():
            if f.mimetype == 'text/html':
                filepath = f.retrieveFile().replace(basedir, '')
                if file_to_edit == filepath:
                    found = True
                    result = edit_editor(req, node, f)
                    if result == "error":
                        logger.error("error editing %r" % f.retrieveFile())
                    break

        if not found:
            edit_editor(req, node, None)

    elif current == "tab_metadata":
        edit_metadata(req, ids)  # undefined
    elif current == "tab_upload":
        edit_upload(req, ids)  # undefined
    elif current == "tab_import":
        edit_import(req, ids)  # undefined
    elif current == "tab_globals":
        req.write("")
    elif current == "tab_lza":
        edit_lza(req, ids)  # undefined
    elif current == "tab_logo":
        edit_logo(req, ids)  # undefined
    else:
        t = current.split("_")[-1]
        if t in editModules.keys():
            c = editModules[t].getContent(req, ids)
            if c:
                content["body"] += c  # use standard method of module
            else:
                logger.debug('empty content')
                return
        else:
            req.setStatus(httpstatus.HTTP_INTERNAL_SERVER_ERROR)
            content["body"] += req.getTAL("web/edit/edit.html", {"module": current}, macro="module_error")

    if req.params.get("style", "") != "popup":  # normal page with header
        v["tabs"] = handletabs(req, ids, tabs)
        v["script"] = content["script"]
        v["body"] = content["body"]
        v["paging"] = showPaging(req, current, ids)
        v["node"] = node
        v["ids"] = req.params.get("ids", "").split(",")
        if req.params.get("ids", "") == "":
            v["ids"] = req.params.get("id", "").split(",")
        v["tab"] = current
        v["operations"] = req.getTAL("web/edit/edit_common.html", {'iscontainer': node.isContainer()}, macro="show_operations")
        user = users.getUserFromRequest(req)
        v['user'] = user
        v['language'] = lang(req)
        v['t'] = translation_t

        v['spc'] = [Menu("sub_header_frontend", "../", target="_parent")]
        if user.isAdmin():
            v['spc'].append(Menu("sub_header_administration", "../admin", target="_parent"))

        if user.isWorkflowEditor():
            v['spc'].append(Menu("sub_header_workflow", "../publish", target="_parent"))

        v['spc'].append(Menu("sub_header_logout", "../logout", target="_parent"))

        # add icons to breadcrumbs
        ipath = 'webtree/directory.gif'
        if node and node.isContainer():
            if node.name == 'home' or 'Arbeitsverzeichnis' in node.name:
                ipath = 'webtree/homeicon.gif'
            elif node.name == 'Uploads':
                ipath = 'webtree/uploadicon.gif'
            elif node.name == 'Importe':
                ipath = 'webtree/importicon.gif'
            elif node.name == 'Inkonsistente Daten':
                ipath = 'webtree/faultyicon.gif'
            elif node.name == 'Papierkorb':
                ipath = 'webtree/trashicon.gif'
            else:
                ipath = getEditorIconPath(node)

        v["dircontent"] += '&nbsp;&nbsp;<img src="' + '/img/' + ipath + '" />'

        return req.writeTAL("web/edit/edit.html", v, macro="frame_content")
示例#3
0
文件: edit.py 项目: hibozzy/mediatum
def frameset(req):
    id = req.params.get("id", tree.getRoot("collections").id)
    tab = req.params.get("tab", None)
    language = lang(req)

    access = AccessData(req)
    if not access.getUser().isEditor():
        req.writeTAL("web/edit/edit.html", {}, macro="error")
        req.writeTAL(
            "web/edit/edit.html", {"id": id, "tab": (tab and "&tab=" + tab) or ""}, macro="edit_notree_permission"
        )
        req.setStatus(httpstatus.HTTP_FORBIDDEN)
        return

    try:
        currentdir = tree.getNode(id)
    except tree.NoSuchNodeError:
        currentdir = tree.getRoot("collections")
        req.params["id"] = currentdir.id
        id = req.params.get("id")

    nodepath = []
    n = currentdir
    while n:
        nodepath = [n] + nodepath
        p = n.getParents()
        if p:
            n = p[0]
        else:
            n = None

    path = nidpath = ["%s" % p.id for p in nodepath]
    containerpath = [("%s" % p.id) for p in nodepath if p.isContainer()]

    user = users.getUserFromRequest(req)
    menu = filterMenu(getEditMenuString(currentdir.getContentType()), user)

    spc = [Menu("sub_header_frontend", "../", target="_parent")]
    if user.isAdmin():
        spc.append(Menu("sub_header_administration", "../admin", target="_parent"))

    if user.isWorkflowEditor():
        spc.append(Menu("sub_header_workflow", "../publish", target="_parent"))

    spc.append(Menu("sub_header_logout", "../logout", target="_parent"))

    def getPathToFolder(node):
        n = node
        path = []
        while n:
            path = ["/%s" % (n.id)] + path
            p = n.getParents()
            if p:
                n = p[0]
            else:
                n = None
        return (node, "".join(path[2:]))

    def _getIDPath(nid, sep="/", containers_only=True):
        res = getIDPaths(nid, access, sep=sep, containers_only=containers_only)
        return res

    folders = {
        "homedir": getPathToFolder(users.getHomeDir(user)),
        "trashdir": getPathToFolder(users.getSpecialDir(user, "trash")),
        "uploaddir": getPathToFolder(users.getSpecialDir(user, "upload")),
        "importdir": getPathToFolder(users.getSpecialDir(user, "import")),
    }

    cmenu = sorted(getContainerTreeTypes(req), key=lambda x: x.getName())
    cmenu_iconpaths = []

    for ct in cmenu:
        ct_name = ct.getName()
        _n = tree.Node("", type=ct_name)
        # translations of ct_name will be offered in editor tree context menu
        cmenu_iconpaths.append([ct, getEditorIconPath(_n), ct_name, translation_t(language, ct_name)])

    # a html snippet may be inserted in the editor header
    header_insert = tree.getRoot("collections").get("system.editor.header.insert." + language).strip()
    help_link = tree.getRoot("collections").get("system.editor.help.link." + language).strip()
    homenodefilter = req.params.get("homenodefilter", "")

    v = {
        "id": id,
        "tab": (tab and "&tab=" + tab) or "",
        "user": user,
        "spc": spc,
        "folders": folders,
        "collectionsid": tree.getRoot("collections").id,
        "basedirs": [tree.getRoot("home"), tree.getRoot("collections")],
        "cmenu": cmenu,
        "cmenu_iconpaths": cmenu_iconpaths,
        "path": path,
        "containerpath": containerpath,
        "language": lang(req),
        "t": translation_t,
        "_getIDPath": _getIDPath,
        "system_editor_header_insert": header_insert,
        "system_editor_help_link": help_link,
        "homenodefilter": homenodefilter,
    }

    req.writeTAL("web/edit/edit.html", v, macro="edit_main")
示例#4
0
文件: edit.py 项目: hibozzy/mediatum
def frameset(req):
    id = req.params.get("id", tree.getRoot("collections").id)
    tab = req.params.get("tab", None)
    language = lang(req)

    access = AccessData(req)
    if not access.getUser().isEditor():
        req.writeTAL("web/edit/edit.html", {}, macro="error")
        req.writeTAL("web/edit/edit.html",
                     {"id": id, "tab": (tab and "&tab=" + tab) or ""}, macro="edit_notree_permission")
        req.setStatus(httpstatus.HTTP_FORBIDDEN)
        return

    try:
        currentdir = tree.getNode(id)
    except tree.NoSuchNodeError:
        currentdir = tree.getRoot("collections")
        req.params["id"] = currentdir.id
        id = req.params.get("id")

    nodepath = []
    n = currentdir
    while n:
        nodepath = [n] + nodepath
        p = n.getParents()
        if p:
            n = p[0]
        else:
            n = None

    path = nidpath = ['%s' % p.id for p in nodepath]
    containerpath = [('%s' % p.id) for p in nodepath if p.isContainer()]

    user = users.getUserFromRequest(req)
    menu = filterMenu(getEditMenuString(currentdir.getContentType()), user)

    spc = [Menu("sub_header_frontend", "../", target="_parent")]
    if user.isAdmin():
        spc.append(
            Menu("sub_header_administration", "../admin", target="_parent"))

    if user.isWorkflowEditor():
        spc.append(Menu("sub_header_workflow", "../publish", target="_parent"))

    spc.append(Menu("sub_header_logout", "../logout", target="_parent"))

    def getPathToFolder(node):
        n = node
        path = []
        while n:
            path = ['/%s' % (n.id)] + path
            p = n.getParents()
            if p:
                n = p[0]
            else:
                n = None
        return (node, "".join(path[2:]))

    def _getIDPath(nid, sep="/", containers_only=True):
        res = getIDPaths(nid, access, sep=sep, containers_only=containers_only)
        return res

    folders = {'homedir': getPathToFolder(users.getHomeDir(user)), 'trashdir': getPathToFolder(users.getSpecialDir(
        user, 'trash')), 'uploaddir': getPathToFolder(users.getSpecialDir(user, 'upload')), 'importdir': getPathToFolder(users.getSpecialDir(user, 'import'))}

    cmenu = sorted(getContainerTreeTypes(req), key=lambda x: x.getName())
    cmenu_iconpaths = []

    for ct in cmenu:
        ct_name = ct.getName()
        _n = tree.Node("", type=ct_name)
        # translations of ct_name will be offered in editor tree context menu
        cmenu_iconpaths.append(
            [ct, getEditorIconPath(_n), ct_name, translation_t(language, ct_name)])

    # a html snippet may be inserted in the editor header
    header_insert = tree.getRoot('collections').get('system.editor.header.insert.' + language).strip()
    help_link = tree.getRoot('collections').get('system.editor.help.link.' + language).strip()
    homenodefilter = req.params.get('homenodefilter', '')

    v = {
        "id": id,
        "tab": (tab and "&tab=" + tab) or "",
        'user': user,
        'spc': spc,
        'folders': folders,
        'collectionsid': tree.getRoot('collections').id,
        "basedirs": [tree.getRoot('home'), tree.getRoot('collections')],
        'cmenu': cmenu,
        'cmenu_iconpaths': cmenu_iconpaths,
        'path': path,
        'containerpath': containerpath,
        'language': lang(req),
        't': translation_t,
        '_getIDPath': _getIDPath,
        'system_editor_header_insert': header_insert,
        'system_editor_help_link': help_link,
        'homenodefilter': homenodefilter,
       }

    req.writeTAL("web/edit/edit.html", v, macro="edit_main")