Example #1
0
def edit_tree(req):
    access = AccessData(req)
    language = lang(req)
    user = users.getUserFromRequest(req)
    home_dir = users.getHomeDir(user)
    match_result = ""
    match_error = False

    if req.params.get("key") == "root":
        nodes = core.tree.getRoot("collections").getContainerChildren().sort_by_orderpos()
    elif req.params.get("key") == "home":
        if not user.isAdmin():
            nodes = [home_dir]
        else:
            homenodefilter = req.params.get("homenodefilter", "")
            if homenodefilter:
                nodes = []
                try:
                    pattern = re.compile(homenodefilter)
                    nodes = tree.getRoot("home").getContainerChildren().sort_by_orderpos()
                    # filter out shoppingbags etc.
                    nodes = [n for n in nodes if n.isContainer()]
                    # filter user name - after first "("
                    nodes = filter(lambda n: re.match(homenodefilter, n.getLabel(language).split("(", 1)[-1]), nodes)
                    match_result = "#=%d" % len(nodes)
                except Exception as e:
                    logger.warning("pattern matching for home nodes: %r" % e)
                    match_result = '<span style="color:red">Error: %r</span>' % str(e)
                    match_error = True
                if home_dir not in nodes:
                    if not match_error:
                        match_result = "#=%d+1" % len(nodes)
                    nodes.append(home_dir)
                nodes = tree.NodeList(nodes).sort_by_orderpos()
            else:
                nodes = [home_dir]
    else:
        nodes = core.tree.getNode(req.params.get("key")).getContainerChildren().sort_by_orderpos()
        # filter out shoppingbags etc.
        nodes = [n for n in nodes if n.isContainer()]

    data = []

    # wn 2014-03-14
    # special directories may be handled in a special way by the editor
    special_dir_ids = {}
    special_dir_ids[home_dir.id] = "userhomedir"
    for dir_type in ["upload", "import", "faulty", "trash"]:
        special_dir_ids[users.getSpecialDir(user, dir_type).id] = dir_type

    spec_dirs = ["userhomedir", "upload", "import", "faulty", "trash"]
    spec_dir_icons = ["homeicon.gif", "uploadicon.gif", "importicon.gif", "faultyicon.gif", "trashicon.gif"]

    for node in nodes:

        if not access.hasReadAccess(node):
            continue

        # try:
        #    label = node.getLabel()
        # except:
        #    label = node.getName()
        #
        # c = len(node.getContentChildren())
        #  if c>0:
        #     label += ' <small>(%s)</small>' %(c)

        label = getTreeLabel(node, lang=language)

        nodedata = {
            "title": label,
            "key": node.id,
            "lazy": True,
            "folder": True,
            "readonly": 0,
            "tooltip": "%s (%s)" % (node.getLabel(lang=language), node.id),
        }
        nodedata["icon"] = getEditorIconPath(node, req)

        if len(node.getContainerChildren()) == 0:
            nodedata["lazy"] = False
            nodedata["children"] = []

        if not access.hasWriteAccess(node):
            if req.params.get("key") == "home":
                continue
            nodedata["readonly"] = 1
            nodedata["noLink"] = True

            nodedata["extraClasses"] = "readonly"  # fancytree

        else:
            nodedata["readonly"] = 0

        nodedata["this_node_is_special"] = []
        if node.id in special_dir_ids:
            nodedata["this_node_is_special"] = nodedata["this_node_is_special"] + [special_dir_ids[node.id]]
            if node.id == home_dir.id:
                nodedata["match_result"] = match_result

        data.append(nodedata)

    return req.write(json.dumps(data, indent=4))
Example #2
0
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")
Example #3
0
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")
Example #4
0
def edit_tree(req):
    access = AccessData(req)
    language = lang(req)
    user = users.getUserFromRequest(req)
    home_dir = users.getHomeDir(user)
    match_result = ''
    match_error = False

    if req.params.get('key') == 'root':
        nodes = core.tree.getRoot(
            'collections').getContainerChildren().sort_by_orderpos()
    elif req.params.get('key') == 'home':
        if not user.isAdmin():
            nodes = [home_dir]
        else:
            homenodefilter = req.params.get('homenodefilter', '')
            if homenodefilter:
                nodes = []
                try:
                    pattern = re.compile(homenodefilter)
                    nodes = tree.getRoot('home').getContainerChildren().sort_by_orderpos()
                    # filter out shoppingbags etc.
                    nodes = [n for n in nodes if n.isContainer()]
                    # filter user name - after first "("
                    nodes = filter(lambda n: re.match(homenodefilter, n.getLabel(language).split('(', 1)[-1]), nodes)
                    match_result = '#=%d' % len(nodes)
                except Exception as e:
                    logger.warning('pattern matching for home nodes: %r' % e)
                    match_result = '<span style="color:red">Error: %r</span>' % str(e)
                    match_error = True
                if home_dir not in nodes:
                    if not match_error:
                        match_result = '#=%d+1' % len(nodes)
                    nodes.append(home_dir)
                nodes = tree.NodeList(nodes).sort_by_orderpos()
            else:
                nodes = [home_dir]
    else:
        nodes = core.tree.getNode(
            req.params.get('key')).getContainerChildren().sort_by_orderpos()
        # filter out shoppingbags etc.
        nodes = [n for n in nodes if n.isContainer()]

    data = []

    # wn 2014-03-14
    # special directories may be handled in a special way by the editor
    special_dir_ids = {}
    special_dir_ids[home_dir.id] = 'userhomedir'
    for dir_type in ['upload', 'import', 'faulty', 'trash']:
        special_dir_ids[users.getSpecialDir(user, dir_type).id] = dir_type

    spec_dirs = ['userhomedir', 'upload', 'import', 'faulty', 'trash']
    spec_dir_icons = ["homeicon.gif", "uploadicon.gif",
                      "importicon.gif", "faultyicon.gif", "trashicon.gif"]

    for node in nodes:

        if not access.hasReadAccess(node):
            continue

        # try:
        #    label = node.getLabel()
        # except:
        #    label = node.getName()
        #
        # c = len(node.getContentChildren())
        #  if c>0:
        #     label += ' <small>(%s)</small>' %(c)

        label = getTreeLabel(node, lang=language)

        nodedata = {'title': label, 'key': node.id, 'lazy': True, 'folder': True,
                    'readonly': 0, 'tooltip': '%s (%s)' % (node.getLabel(lang=language),
                                                           node.id)}
        nodedata['icon'] = getEditorIconPath(node, req)

        if len(node.getContainerChildren()) == 0:
            nodedata['lazy'] = False
            nodedata['children'] = []

        if not access.hasWriteAccess(node):
            if req.params.get('key') == 'home':
                continue
            nodedata['readonly'] = 1
            nodedata['noLink'] = True

            nodedata['extraClasses'] = 'readonly'  # fancytree

        else:
            nodedata['readonly'] = 0



        nodedata['this_node_is_special'] = []
        if node.id in special_dir_ids:
            nodedata['this_node_is_special'] = nodedata[
                'this_node_is_special'] + [special_dir_ids[node.id]]
            if node.id == home_dir.id:
                nodedata['match_result'] = match_result

        data.append(nodedata)

    return req.write(json.dumps(data, indent=4))
Example #5
0
def edit_tree(req):
    access = AccessData(req)
    language = lang(req)
    user = users.getUserFromRequest(req)
    home_dir = users.getHomeDir(user)
    match_result = ''
    match_error = False

    if req.params.get('key') == 'root':
        nodes = core.tree.getRoot(
            'collections').getContainerChildren().sort_by_orderpos()
    elif req.params.get('key') == 'home':
        if not user.isAdmin():
            nodes = [home_dir]
        else:
            homenodefilter = req.params.get('homenodefilter', '')
            if homenodefilter:
                nodes = []
                try:
                    pattern = re.compile(homenodefilter)
                    nodes = tree.getRoot('home').getContainerChildren().sort_by_orderpos()
                    # filter out shoppingbags etc.
                    nodes = [n for n in nodes if n.isContainer()]
                    # filter user name - after first "("
                    nodes = filter(lambda n: re.match(homenodefilter, n.getLabel(language).split('(', 1)[-1]), nodes)
                    match_result = '#=%d' % len(nodes)
                except Exception as e:
                    logger.warning('pattern matching for home nodes: %r' % e)
                    match_result = '<span style="color:red">Error: %r</span>' % str(e)
                    match_error = True
                if home_dir not in nodes:
                    if not match_error:
                        match_result = '#=%d+1' % len(nodes)
                    nodes.append(home_dir)
                nodes = tree.NodeList(nodes).sort_by_orderpos()
            else:
                nodes = [home_dir]
    else:
        nodes = core.tree.getNode(
            req.params.get('key')).getContainerChildren().sort_by_orderpos()
        # filter out shoppingbags etc.
        nodes = [n for n in nodes if n.isContainer()]

    data = []

    # wn 2014-03-14
    # special directories may be handled in a special way by the editor
    special_dir_ids = {}
    special_dir_ids[home_dir.id] = 'userhomedir'
    for dir_type in ['upload', 'import', 'faulty', 'trash']:
        special_dir_ids[users.getSpecialDir(user, dir_type).id] = dir_type

    spec_dirs = ['userhomedir', 'upload', 'import', 'faulty', 'trash']
    spec_dir_icons = ["homeicon.gif", "uploadicon.gif",
                      "importicon.gif", "faultyicon.gif", "trashicon.gif"]

    for node in nodes:

        if not access.hasReadAccess(node):
            continue

        # try:
        #    label = node.getLabel()
        # except:
        #    label = node.getName()
        #
        # c = len(node.getContentChildren())
        #  if c>0:
        #     label += ' <small>(%s)</small>' %(c)

        label = getTreeLabel(node, lang=language)

        nodedata = {'title': label, 'key': node.id, 'lazy': True, 'folder': True,
                    'readonly': 0, 'tooltip': '%s (%s)' % (node.getLabel(lang=language),
                                                           node.id)}
        nodedata['icon'] = getEditorIconPath(node, req)

        if len(node.getContainerChildren()) == 0:
            nodedata['lazy'] = False
            nodedata['children'] = []

        if not access.hasWriteAccess(node):
            if req.params.get('key') == 'home':
                continue
            nodedata['readonly'] = 1
            nodedata['noLink'] = True

            nodedata['extraClasses'] = 'readonly'  # fancytree

        else:
            nodedata['readonly'] = 0

        nodedata['this_node_is_special'] = []
        if node.id in special_dir_ids:
            nodedata['this_node_is_special'] = nodedata[
                'this_node_is_special'] + [special_dir_ids[node.id]]
            if node.id == home_dir.id:
                nodedata['match_result'] = match_result

        data.append(nodedata)

    return req.write(json.dumps(data, indent=4))