Example #1
0
 def handle_error(req, error_msgstr):
     if req:
         errormsg = translation_t(req, error_msgstr)
         req.request["Location"] = build_url_from_path_and_params(
             "content", {
                 "id": importdir.id,
                 "error": errormsg
             })
         req.params["error"] = errormsg
Example #2
0
def import_from_doi(identifier, importdir, req=None):
    import schema.citeproc as citeproc
    import schema.importbase as importbase
    from requests.exceptions import ConnectionError
    doi = identifier
    logger.info("processing DOI import for: %s", doi)
    try:
        doi_extracted = citeproc.extract_and_check_doi(doi)
        new_node = citeproc.import_doi(doi_extracted, importdir)
        return new_node
    except citeproc.InvalidDOI:
        logger.error("Invalid DOI: '%s'", doi)
        if req:
            req.request["Location"] = req.makeLink("content", {"id": importdir.id, "error": translation_t(req, "doi_invalid")})
            req.params["error"] = translation_t(req, "doi_invalid")
    except citeproc.DOINotFound:
        logger.error("DOI not found: '%s'", doi)
        if req:
            req.request["Location"] = req.makeLink("content", {"id": importdir.id, "error": translation_t(req, "doi_unknown")})
            req.params["error"] = translation_t(req, "doi_unknown")
    except importbase.NoMappingFound as e:
        logger.error("no mapping found for DOI: '%s', type '%s'", doi, e.typ)
        if req:
            req.request["Location"] = req.makeLink("content", {"id": importdir.id, "error": translation_t(req, "doi_type_not_mapped")})
            req.params["error"] = translation_t(req, "doi_type_not_mapped")
    except ConnectionError as e:
        msg = "Connection to external server failed: '%s', type '%s'" % (
            doi, e)
        logger.error(msg)
        if req:
            req.request["Location"] = req.makeLink("content", { "id": importdir.id, "error": translation_t(req, "error_connecting_external_server")})
            req.params["error"] = translation_t(req, "doi_error_connecting_external_server")
            req.params["connect_error_msg"] = msg
    else:
        if req:
            req.request["Location"] = req.makeLink("content", {"id": importdir.id})
Example #3
0
    node = tree.getNode(ids[0])
    v = {}
    if node.isContainer():
        schemes = []
        dtypes = []

        access = acl.AccessData(req)
        if access.hasWriteAccess(node):
            schemes = getSchemes(req)
            dtypes = getDatatypes(req, schemes)

        col = node
        if "globalsort" in req.params:
            col.set("sortfield", req.params.get("globalsort"))
        v['collection_sortfield'] = col.get("sortfield")
        sortfields = [SortChoice(translation_t(req, "off"), "")]

        if col.type not in ["root", "collections", "home"]:
            for ntype, num in col.getAllOccurences(acl.AccessData(req)).items():
                if ntype.getSortFields():
                    for sortfield in ntype.getSortFields():
                        sortfields += [SortChoice(sortfield.getLabel(), sortfield.getName())]
                        sortfields += [SortChoice(sortfield.getLabel() + translation_t(req, "descending"), "-" + sortfield.getName())]
                    break
        v['sortchoices'] = sortfields
        v['count'] = len(node.getContentChildren())
        v['language'] = lang(req)
        v['t'] = translation_t

    v.update({
        "id": req.params.get("id"),
Example #4
0
            dtypes = getDatatypes(req, schemes)

        if "globalsort" in req.params:
            node.set("sortfield", req.params.get("globalsort"))
        if req.params.get("sortfield", "") != "":
            v['collection_sortfield'] = req.params.get("sortfield")
        else:
            v['collection_sortfield'] = node.get("sortfield")
        if req.params.get("nodes_per_page", "") != "":
            v['npp_field'] = req.params.get("nodes_per_page",
                                            default_edit_nodes_per_page)
        else:
            v['npp_field'] = node.get("nodes_per_page")
        if not v['npp_field']:
            v['npp_field'] = default_edit_nodes_per_page
        sortfields = [SortChoice(translation_t(req, "off"), "off")]

        if node.type not in ["root", "collections", "home"]:
            sorted_schema_count = node.all_children_by_query(
                q(Node.schema,
                  func.count(Node.schema)).group_by(Node.schema).order_by(
                      func.count(Node.schema).desc()))

            for schema_count in sorted_schema_count:
                metadatatype = q(Metadatatype).filter_by(
                    name=schema_count[0]).first()
                if metadatatype:
                    sort_fields = metadatatype.metafields.filter(
                        Node.a.opts.like("%o%")).all()
                    if sort_fields:
                        for sortfield in sort_fields:
Example #5
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 #6
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 #7
0
 def handle_error(req, error_msgstr):
     if req:
         errormsg = translation_t(req, error_msgstr)
         req.request["Location"] = build_url_from_path_and_params("content", {"id": importdir.id, "error": errormsg})
         req.params["error"] = errormsg
Example #8
0
            schemes = get_permitted_schemas()
            dtypes = getDatatypes(req, schemes)

        if "globalsort" in req.params:
            node.set("sortfield", req.params.get("globalsort"))
        if req.params.get("sortfield", "") != "":
            v['collection_sortfield'] = req.params.get("sortfield")
        else:
            v['collection_sortfield'] = node.get("sortfield")
        if req.params.get("nodes_per_page", "") != "":
            v['npp_field'] = req.params.get("nodes_per_page", default_edit_nodes_per_page)
        else:
            v['npp_field'] = node.get("nodes_per_page")
        if not v['npp_field']:
            v['npp_field'] = default_edit_nodes_per_page
        sortfields = [SortChoice(translation_t(req, "off"), "off")]

        if node.type not in ["root", "collections", "home"]:
            sorted_schema_count = node.all_children_by_query(q(Node.schema, func.count(Node.schema)).group_by(Node.schema).order_by(func.count(Node.schema).desc()))

            for schema_count in sorted_schema_count:
                metadatatype = q(Metadatatype).filter_by(name=schema_count[0]).first()
                if metadatatype:
                    sort_fields = metadatatype.metafields.filter(Node.a.opts.like("%o%")).all()
                    if sort_fields:
                        for sortfield in sort_fields:
                            sortfields += [SortChoice(sortfield.getLabel(), sortfield.name)]
                            sortfields += [SortChoice(sortfield.getLabel() + translation_t(req, "descending"), "-" + sortfield.name)]
                        break

        v['sortchoices'] = sortfields
Example #9
0
        "nodelist":
        items,
        "nav":
        nav,
        "count":
        count,
        "search":
        search_html,
        "query":
        req.query.replace('id=', 'src='),
        "searchparams":
        urllib.urlencode(searchparams),
        "get_ids_from_query":
        get_ids_from_query,
        "edit_all_objects":
        translation_t(lang(req), "edit_all_objects").format(item_count[1]),
        "navigation_height":
        navigation_height,
        "csrf":
        str(req.csrf_token.current_token),
    })
    html = req.getTAL("web/edit/modules/upload.html", v, macro="upload_form")
    delete_g_nodes_entry(req)
    return html


# differs from os.path.split in that it handles windows as well as unix
# filenames
FNAMESPLIT = re.compile(r'(([^/\\]*[/\\])*)([^/\\]*)')