Example #1
0
def send_thumbnail2(req):
    try:
        n = tree.getNode(splitpath(req.path)[0])
    except tree.NoSuchNodeError:
        return 404
    for f in n.getFiles():
        if f.getType().startswith("presentat"):
            if os.path.isfile(f.retrieveFile()):
                return req.sendFile(f.retrieveFile(), f.getMimeType())
    # fallback
    for f in n.getFiles():
        if f.getType() == "image":
            if os.path.isfile(f.retrieveFile()):
                return req.sendFile(f.retrieveFile(), f.getMimeType())

    # fallback2
    for p in athana.getFileStorePaths("/img/"):
        for test in [
                "default_thumb_%s_%s.*" %
                (n.getContentType(),
                 n.getSchema()),
                "default_thumb_%s.*" %
                (n.getSchema()),
                "default_thumb_%s.*" %
                (n.getContentType())]:
            #fps = glob.glob(os.path.join(config.basedir, theme.getImagePath(), "img", test))
            fps = glob.glob(os.path.join(config.basedir, p[2:], test))
            if fps:
                thumb_mimetype, thumb_type = utils.utils.getMimeType(fps[0])
                return req.sendFile(fps[0], thumb_mimetype, force=1)
    return 404
Example #2
0
def send_thumbnail2(req):
    try:
        n = tree.getNode(splitpath(req.path)[0])
    except tree.NoSuchNodeError:
        return 404
    for f in n.getFiles():
        if f.getType().startswith("presentat"):
            if os.path.isfile(f.retrieveFile()):
                return req.sendFile(f.retrieveFile(), f.getMimeType())
    # fallback
    for f in n.getFiles():
        if f.getType() == "image":
            if os.path.isfile(f.retrieveFile()):
                return req.sendFile(f.retrieveFile(), f.getMimeType())

    # fallback2
    for p in athana.getFileStorePaths("/img/"):
        for test in [
                "default_thumb_%s_%s.*" % (n.getContentType(), n.getSchema()),
                "default_thumb_%s.*" % (n.getSchema()),
                "default_thumb_%s.*" % (n.getContentType())
        ]:
            #fps = glob.glob(os.path.join(config.basedir, theme.getImagePath(), "img", test))
            fps = glob.glob(os.path.join(config.basedir, p[2:], test))
            if fps:
                thumb_mimetype, thumb_type = utils.utils.getMimeType(fps[0])
                return req.sendFile(fps[0], thumb_mimetype, force=1)
    return 404
Example #3
0
def _send_thumbnail(thumb_type, req):
    try:
        nid = node_id_from_req_path(req)
    except ValueError:
        return 400

    version_id = version_id_from_req(req)

    node_or_version = get_node_or_version(nid, version_id, Data)

    if not node_or_version.has_read_access():
        return 404

    FileVersion = version_class(File)
    if version_id:
        version = node_or_version
        files = version.files.filter_by(
            filetype=thumb_type, transaction_id=version.transaction_id).all()
        if not files:
            # files may be None if in this version only metadata changed
            # then try previous transaction_ids
            files = version.files.filter(FileVersion.filetype==thumb_type, FileVersion.transaction_id<=version.transaction_id). \
                order_by(FileVersion.transaction_id.desc())
        for f in files:
            if f.exists:
                return req.sendFile(f.abspath, f.mimetype)

        ntype, schema = version.type, version.schema
    else:
        # no version id given
        # XXX: better to use scalar(), but we must ensure that we have no dupes first
        node = node_or_version
        for f in node.files.filter_by(filetype=thumb_type):
            if f.exists:
                return req.sendFile(f.abspath, f.mimetype)

        try:
            ntype, schema = node.type, node.schema
        except NoResultFound:
            return 404

    for p in athana.getFileStorePaths("/img/"):
        for test in [
                "default_thumb_%s_%s.*" % (ntype, schema),
                "default_thumb_%s.*" % schema,
                "default_thumb_%s.*" % ntype
        ]:
            fps = glob.glob(os.path.join(p, test))
            if fps:
                thumb_mimetype, thumb_type = utils.utils.getMimeType(fps[0])
                return req.sendFile(fps[0], thumb_mimetype, force=1)

    return req.sendFile(config.basedir + "/web/img/questionmark.png",
                        "image/png",
                        force=1)
Example #4
0
def _send_thumbnail(thumb_type, req):
    try:
        nid = node_id_from_req_path(req)
    except ValueError:
        return 400


    version_id = version_id_from_req(req)

    node_or_version = get_node_or_version(nid, version_id, Data)

    if not node_or_version.has_read_access():
        return 404

    FileVersion = version_class(File)
    if version_id:
        version = node_or_version
        files = version.files.filter_by(filetype=thumb_type, transaction_id=version.transaction_id).all()
        if not files:
            # files may be None if in this version only metadata changed
            # then try previous transaction_ids
            files = version.files.filter(FileVersion.filetype==thumb_type, FileVersion.transaction_id<=version.transaction_id). \
                order_by(FileVersion.transaction_id.desc())
        for f in files:
            if f.exists:
                return req.sendFile(f.abspath, f.mimetype)

        ntype, schema = version.type, version.schema
    else:
        # no version id given
        # XXX: better to use scalar(), but we must ensure that we have no dupes first
        node = node_or_version
        for f in node.files.filter_by(filetype=thumb_type):
            if f.exists:
                return req.sendFile(f.abspath, f.mimetype)

        try:
            ntype, schema = node.type, node.schema
        except NoResultFound:
            return 404

    for p in athana.getFileStorePaths("/img/"):
        for test in ["default_thumb_%s_%s.*" % (ntype, schema),
                     "default_thumb_%s.*" % schema,
                     "default_thumb_%s.*" % ntype]:
            fps = glob.glob(os.path.join(p, test))
            if fps:
                thumb_mimetype, thumb_type = utils.utils.getMimeType(fps[0])
                return req.sendFile(fps[0], thumb_mimetype, force=1)

    return req.sendFile(config.basedir + "/web/img/questionmark.png", "image/png", force=1)
Example #5
0
def send_thumbnail(req):
    try:
        n = tree.getNode(splitpath(req.path)[0])
    except tree.NoSuchNodeError:
        return 404
    for f in n.getFiles():
        if f.getType() == "thumb":
            if os.path.isfile(f.retrieveFile()):
                return req.sendFile(f.retrieveFile(), f.getMimeType())

    for p in athana.getFileStorePaths("/img/"):
        for test in [
                "default_thumb_%s_%s.*" % (n.getContentType(), n.getSchema()),
                "default_thumb_%s.*" % (n.getSchema()),
                "default_thumb_%s.*" % (n.getContentType())
        ]:
            fps = glob.glob(os.path.join(config.basedir, p[2:], test))
            if fps:
                thumb_mimetype, thumb_type = utils.utils.getMimeType(fps[0])
                return req.sendFile(fps[0], thumb_mimetype, force=1)
    return req.sendFile(config.basedir + "/web/img/questionmark.png",
                        "image/png",
                        force=1)
Example #6
0
def send_thumbnail(req):
    try:
        n = tree.getNode(splitpath(req.path)[0])
    except tree.NoSuchNodeError:
        return 404
    for f in n.getFiles():
        if f.getType() == "thumb":
            if os.path.isfile(f.retrieveFile()):
                return req.sendFile(f.retrieveFile(), f.getMimeType())

    for p in athana.getFileStorePaths("/img/"):
        for test in [
                "default_thumb_%s_%s.*" %
                (n.getContentType(),
                 n.getSchema()),
                "default_thumb_%s.*" %
                (n.getSchema()),
                "default_thumb_%s.*" %
                (n.getContentType())]:
            fps = glob.glob(os.path.join(config.basedir, p[2:], test))
            if fps:
                thumb_mimetype, thumb_type = utils.utils.getMimeType(fps[0])
                return req.sendFile(fps[0], thumb_mimetype, force=1)
    return req.sendFile(config.basedir + "/web/img/questionmark.png", "image/png", force=1)