Пример #1
0
def getExportMasks(regexp):
    exportmasks = [tree.getNode(nid) for nid in tree.getNodesByAttribute('masktype', 'export')]
    exportmasks = [(n, n.name) for n in exportmasks if re.match(regexp, n.name) and n.type == 'mask']
    dict_metadatatype2exportmask = {}
    for exportmask in exportmasks:
        parents = exportmask[0].getParents()
        try:
            mdt_node = [p for p in parents if p.type == 'metadatatype'][0]
            mdt = (mdt_node, mdt_node.name)
            dict_metadatatype2exportmask[mdt] = dict_metadatatype2exportmask.setdefault(mdt, []) + [exportmask]
        except:
            pass
    return dict_metadatatype2exportmask.items()
Пример #2
0
def getExportMasks(regexp):
    exportmasks = [
        tree.getNode(nid)
        for nid in tree.getNodesByAttribute('masktype', 'export')
    ]
    exportmasks = [(n, n.name) for n in exportmasks
                   if re.match(regexp, n.name) and n.type == 'mask']
    dict_metadatatype2exportmask = {}
    for exportmask in exportmasks:
        parents = exportmask[0].getParents()
        try:
            mdt_node = [p for p in parents if p.type == 'metadatatype'][0]
            mdt = (mdt_node, mdt_node.name)
            dict_metadatatype2exportmask[
                mdt] = dict_metadatatype2exportmask.setdefault(
                    mdt, []) + [exportmask]
        except:
            pass
    return dict_metadatatype2exportmask.items()
Пример #3
0
def build_container_group():
    # sets configured with container attributes
    node_list = tree.NodeList(tree.getNodesByAttribute('oai.setname', '*'))
    node_list = node_list.sort_by_fields(field="oai.setname")
    node_list = [node for node in node_list if node.type in ['collection', 'directory']]
    node_list = [node for node in node_list if node.get('oai.setname').strip()]
    node_list = [node for node in node_list if node.get('oai.formats').strip()]

    d_names = OrderedDict()
    for col_node in node_list:
        d_names[str(col_node.id)] = esc(col_node.get('oai.setname'))

    g = OAISetGroup(d_names, descr='group of %d container sets' % len(d_names))

    g.func_getNodesForSetSpec = func_getNodesForSetSpec
    g.func_getSetSpecsForNode = func_getSetSpecsForNode
    g.sortorder = '040'
    g.group_identifier = 'oaigroup_containers'
    return g
Пример #4
0
def build_container_group():
    # sets configured with container attributes
    node_list = tree.NodeList(tree.getNodesByAttribute('oai.setname', '*'))
    node_list = node_list.sort_by_fields(field="oai.setname")
    node_list = [
        node for node in node_list if node.type in ['collection', 'directory']
    ]
    node_list = [node for node in node_list if node.get('oai.setname').strip()]
    node_list = [node for node in node_list if node.get('oai.formats').strip()]

    d_names = OrderedDict()
    for col_node in node_list:
        d_names[str(col_node.id)] = esc(col_node.get('oai.setname'))

    g = OAISetGroup(d_names, descr='group of %d container sets' % len(d_names))

    g.func_getNodesForSetSpec = func_getNodesForSetSpec
    g.func_getSetSpecsForNode = func_getSetSpecsForNode
    g.sortorder = '040'
    g.group_identifier = 'oaigroup_containers'
    return g
Пример #5
0
def getContent(req, ids):
    user = users.getUserFromRequest(req)
    publishdir = tree.getNode(ids[0])
    explicit = tree.getNodesByAttribute("writeaccess", user.getName())
    ret = ""

    actionerror = []
    changes = []
    if "dopublish" in req.params.keys():
        access = AccessData(req)

        objlist = []
        for key in req.params.keys():
            if key.isdigit():
                objlist.append(key)
                src = tree.getNode(req.params.get("id"))

        for obj_id in objlist:
            faultylist = []
            obj = tree.getNode(obj_id)
            for mask in obj.getType().getMasks(
                    type="edit"):  # check required fields
                if access.hasReadAccess(mask) and mask.getName() == obj.get(
                        "edit.lastmask"):
                    for f in mask.validateNodelist([obj]):
                        faultylist.append(f)

            if len(faultylist) > 0:  # object faulty
                actionerror.append(obj_id)
                continue

            for dest_id in req.params.get("destination", "").split(","):
                if dest_id == "":  # no destination given
                    continue

                dest = tree.getNode(dest_id)
                if dest != src and access.hasReadAccess(
                        src) and access.hasWriteAccess(
                            dest) and access.hasWriteAccess(
                                obj) and isDirectory(dest):
                    if not nodeIsChildOfNode(dest, obj):
                        dest.addChild(obj)
                        src.removeChild(obj)

                        if dest.id not in changes:
                            changes.append(dest.id)
                        if src.id not in changes:
                            changes.append(src.id)
                        log.info(
                            "%s published %s (%r, %r) from src %s (%r, %r) to dest %s (%r, %r)"
                            % (
                                user.getName(),
                                obj.id,
                                obj.name,
                                obj.type,
                                src.id,
                                src.name,
                                src.type,
                                dest.id,
                                dest.name,
                                dest.type,
                            ))
                    else:
                        actionerror.append(obj.id)
                        log.error(
                            "Error in publishing of node %r: Destination node %r is child of node."
                            % (obj_id, dest.id))

                if not access.hasReadAccess(src):
                    log.error(
                        "Error in publishing of node %r: source position %r has no read access."
                        % (obj.id, src.id))
                if not access.hasWriteAccess(dest):
                    log.error(
                        "Error in publishing of node %r: destination %r has no write access."
                        % (obj.id, dest.id))
                if not access.hasWriteAccess(obj):
                    log.error(
                        "Error in publishing of node %r: object has no write access."
                        % obj.id)
                if not isDirectory(dest):
                    log.error(
                        "Error in publishing of node %r: destination %r is not a directory."
                        % (obj.id, dest.id))

        v = {}
        v["id"] = publishdir.id
        v["change"] = changes
        ret += req.getTAL("web/edit/modules/publish.html", v, macro="reload")

    # build normal window
    stddir = ""
    stdname = ""
    l = []
    for n in explicit:
        if str(getHomeDir(user).id) != str(n):
            l.append(n)

    if len(l) == 1:
        stddir = str(l[0]) + ","
        stdname = "- " + tree.getNode(l[0]).getName()

    #v = {"id":publishdir.id,"stddir":stddir, "stdname":stdname, "showdir":showdir(req, publishdir, publishwarn=0, markunpublished=1, nodes=[])}
    v = {
        "id":
        publishdir.id,
        "stddir":
        stddir,
        "stdname":
        stdname,
        "showdir":
        showdir(req, publishdir, publishwarn=None, markunpublished=1, nodes=[])
    }
    v["basedir"] = tree.getRoot('collections')
    v["script"] = "var currentitem = '%s';\nvar currentfolder = '%s'" % (
        publishdir.id, publishdir.id)
    v["idstr"] = ids
    v["faultylist"] = actionerror
    ret += req.getTAL("web/edit/modules/publish.html", v, macro="publish_form")
    return ret
Пример #6
0
def getContent(req, ids):
    user = users.getUserFromRequest(req)
    publishdir = tree.getNode(ids[0])
    explicit = tree.getNodesByAttribute("writeaccess", user.getName())
    ret = ""

    actionerror = []
    changes = []
    if "dopublish" in req.params.keys():
        access = AccessData(req)

        objlist = []
        for key in req.params.keys():
            if key.isdigit():
                objlist.append(key)
                src = tree.getNode(req.params.get("id"))

        for obj_id in objlist:
            faultylist = []
            obj = tree.getNode(obj_id)
            for mask in obj.getType().getMasks(type="edit"): # check required fields
                if access.hasReadAccess(mask) and mask.getName()==obj.get("edit.lastmask"):
                    for f in mask.validateNodelist([obj]):
                        faultylist.append(f)

            if len(faultylist)>0: # object faulty
                actionerror.append(obj_id)
                continue

            for dest_id in req.params.get("destination", "").split(","):
                if dest_id=="": # no destination given
                    continue

                dest = tree.getNode(dest_id)
                if dest != src and access.hasReadAccess(src) and access.hasWriteAccess(dest) and access.hasWriteAccess(obj) and isDirectory(dest):
                        if not nodeIsChildOfNode(dest,obj):
                            dest.addChild(obj)
                            src.removeChild(obj)

                            if dest.id not in changes:
                                changes.append(dest.id)
                            if src.id not in changes:
                                changes.append(src.id)
                            log.info("%s published %s (%r, %r) from src %s (%r, %r) to dest %s (%r, %r)" % (
                                      user.getName(),
                                      obj.id, obj.name, obj.type,
                                      src.id, src.name, src.type,
                                      dest.id, dest.name, dest.type,))
                        else:
                            actionerror.append(obj.id)
                            log.error("Error in publishing of node %r: Destination node %r is child of node." % (obj_id, dest.id))

                if not access.hasReadAccess(src):
                    log.error("Error in publishing of node %r: source position %r has no read access." % (obj.id, src.id))
                if not access.hasWriteAccess(dest):
                    log.error("Error in publishing of node %r: destination %r has no write access." % (obj.id, dest.id))
                if not access.hasWriteAccess(obj):
                    log.error("Error in publishing of node %r: object has no write access." % obj.id)
                if not isDirectory(dest):
                    log.error("Error in publishing of node %r: destination %r is not a directory." % (obj.id, dest.id))

        v = {}
        v["id"] = publishdir.id
        v["change"] = changes
        ret += req.getTAL("web/edit/modules/publish.html", v, macro="reload")

    # build normal window
    stddir = ""
    stdname = ""
    l = []
    for n in explicit:
        if str(getHomeDir(user).id)!=str(n):
            l.append(n)

    if len(l)==1:
        stddir = str(l[0])+","
        stdname = "- " + tree.getNode(l[0]).getName()

    #v = {"id":publishdir.id,"stddir":stddir, "stdname":stdname, "showdir":showdir(req, publishdir, publishwarn=0, markunpublished=1, nodes=[])}
    v = {"id":publishdir.id,"stddir":stddir, "stdname":stdname, "showdir":showdir(req, publishdir, publishwarn=None, markunpublished=1, nodes=[])}
    v["basedir"] = tree.getRoot('collections')
    v["script"] = "var currentitem = '%s';\nvar currentfolder = '%s'" %(publishdir.id, publishdir.id)
    v["idstr"] = ids
    v["faultylist"] = actionerror
    ret += req.getTAL("web/edit/modules/publish.html", v, macro="publish_form")
    return ret