Exemplo n.º 1
0
def server(filename):
    print filename

    storage_setup = current_app.config['storage']

    if 'local' in storage_setup and 'absolut_path' in storage_setup['local']:
        STORAGE = storage_setup['local']['absolut_path']
    else:
        STORAGE = '.'

    filename = filename.split('.')[0]

    node = CaliopeDocument.pull(filename)
    file = open(os.path.join(STORAGE, filename), 'rb')
    data = wrap_file(request.environ, file)
    headers = Headers()

    try:
        mimetype = node.mimetype
    except:
        mimetype = 'application/octet-stream'

    rv = current_app.response_class(data,
                                    mimetype=mimetype,
                                    headers=headers,
                                    direct_passthrough=False)
    return rv
Exemplo n.º 2
0
def server(filename):
    print filename

    storage_setup = current_app.config['storage']


    if 'local' in storage_setup and 'absolut_path' in storage_setup['local']:
            STORAGE = storage_setup['local']['absolut_path']
    else:
            STORAGE = '.'

    filename = filename.split('.')[0]

    node = CaliopeDocument.pull(filename)
    file = open(os.path.join(STORAGE, filename), 'rb')
    data = wrap_file(request.environ, file)
    headers = Headers()

    try:
        mimetype  = node.mimetype
    except:
        mimetype = 'application/octet-stream'

    rv = current_app.response_class(data, mimetype=mimetype, headers=headers,
                                        direct_passthrough=False)
    return rv
Exemplo n.º 3
0
    def get_data(cls, uuids):
        rv = list()

        storage_setup = current_app.config['storage']

        if 'local' in storage_setup and 'absolut_path' in storage_setup[
                'local']:
            STORAGE = storage_setup['local']['absolut_path']

        for uuid in uuids:
            vnode = CaliopeDocument.pull(uuid)
            filename = os.path.join(STORAGE, vnode.uuid)
            size = os.stat(filename).st_size
            data = {
                'result':
                'ok',
                'name':
                vnode.filename,
                'size':
                human_readable_size(size),
                'mime':
                vnode.mimetype,
                'id':
                vnode.uuid,
                'thumbnail':
                get_thumbnail(filename,
                              field_name='data',
                              mimetype=vnode.mimetype)
            }
            rv.append(data)

        return rv
Exemplo n.º 4
0
    def get_all_with_thumbnails(cls, context=None, thumbnails=False):
        rv = cls.get_all(context=context, recursive=False)

        # TODO: move to DocumentServices
        user_node = CaliopeUser.index.get(username=LoginManager().get_user())

        storage_setup = current_app.config["storage"]
        if "local" in storage_setup and "absolut_path" in storage_setup["local"]:
            STORAGE = storage_setup["local"]["absolut_path"]

        for form in rv[0]["instances"]:
            # TODO: optimize
            results, metadata = user_node.cypher(
                """
                START form=node:CaliopeStorage(uuid='{uuid}')
                MATCH  pa=(form)-[*1..2]-(file)<-[CALIOPE_DOCUMENT]-(),p_none=(file)<-[?:PARENT*]-()
                WHERE p_none = null and has(file.url)
                return distinct file
                 """.format(
                    uuid=form["uuid"]
                )
            )

            # TODO: use cache to thumbnails
            attachments = list()
            for row in results:
                attachment = row[0]
                file_uuid = attachment["uuid"]
                node = CaliopeDocument.pull(file_uuid)
                if thumbnails:
                    filename = os.path.join(STORAGE, file_uuid)
                    size = os.stat(filename).st_size
                    data = {
                        "uuid": file_uuid,
                        "name": node.filename,
                        "size": human_readable_size(size),
                        "thumbnail": get_thumbnail(filename, field_name="data", mimetype=node.mimetype),
                    }
                else:
                    data = {"uuid": file_uuid, "name": node.filename}
                attachments.append(data)
            form["attachments"] = attachments

        return rv
Exemplo n.º 5
0
    def get_all_with_thumbnails(cls, context=None, thumbnails=False):
        rv = cls.get_all(context=context, recursive=False)

        #TODO: move to DocumentServices
        user_node = CaliopeUser.index.get(username=LoginManager().get_user())

        storage_setup = current_app.config['storage']
        if 'local' in storage_setup and 'absolut_path' in storage_setup['local']:
            STORAGE = storage_setup['local']['absolut_path']

        for form in rv[0]['instances']:
            #TODO: optimize
            results, metadata = user_node.cypher("""
                START form=node:CaliopeStorage(uuid='{uuid}')
                MATCH  pa=(form)-[*1..2]-(file)<-[CALIOPE_DOCUMENT]-(),p_none=(file)<-[?:PARENT*]-()
                WHERE p_none = null and has(file.url)
                return distinct file
                 """.format(uuid=form['uuid']))

            #TODO: use cache to thumbnails
            attachments = list()
            for row in results:
                attachment = row[0]
                file_uuid = attachment['uuid']
                node = CaliopeDocument.pull(file_uuid)
                if thumbnails:
                    filename = os.path.join(STORAGE, file_uuid)
                    size = os.stat(filename).st_size
                    data = {
                        'uuid': file_uuid,
                        'name': node.filename,
                        'size': human_readable_size(size),
                        'thumbnail': get_thumbnail(filename, field_name='data', mimetype=node.mimetype)
                    }
                else:
                    data = {
                        'uuid': file_uuid,
                        'name': node.filename
                    }
                attachments.append(data)
            form['attachments'] = attachments

        return rv
Exemplo n.º 6
0
    def get_data(cls, uuids):
        rv = list()

        storage_setup = current_app.config["storage"]

        if "local" in storage_setup and "absolut_path" in storage_setup["local"]:
            STORAGE = storage_setup["local"]["absolut_path"]

        for uuid in uuids:
            vnode = CaliopeDocument.pull(uuid)
            filename = os.path.join(STORAGE, vnode.uuid)
            size = os.stat(filename).st_size
            data = {
                "result": "ok",
                "name": vnode.filename,
                "size": human_readable_size(size),
                "mime": vnode.mimetype,
                "id": vnode.uuid,
                "thumbnail": get_thumbnail(filename, field_name="data", mimetype=vnode.mimetype),
            }
            rv.append(data)

        return rv
Exemplo n.º 7
0
def get_service():
    CaliopeDocument()
    return DocumentServices(service_class=CaliopeDocument)