예제 #1
0
파일: utils.py 프로젝트: chokribr/invenio-1
def _get_document(uuid):
    """Get the document fullpath.

    :param str uuid: The document's uuid
    """
    from invenio.modules.documents.api import Document
    from invenio.modules.documents.errors import (DocumentNotFound,
                                                  DeletedDocument)

    try:
        document = Document.get_document(uuid)
    except (DocumentNotFound, DeletedDocument):
        path = _simulate_file_not_found()
    else:
        path = document.get('uri', ''), document.is_authorized()
    finally:
        return path
예제 #2
0
파일: utils.py 프로젝트: chokribr/invenio-1
def get_record_documents(recid, filename):
    """Yield LegacyBibDoc files from Documents."""
    from invenio.modules.records.api import get_record
    from invenio.modules.documents.api import Document
    from invenio.legacy.bibdocfile.api import decompose_file

    record = get_record(recid)
    duuids = [
        uuid for (k, uuid) in record.get('_documents', []) if k == filename
    ]

    for duuid in duuids:
        document = Document.get_document(duuid)
        if not document.is_authorized(current_user):
            current_app.logger.info(
                "Unauthorized access to /{recid}/files/{filename} "
                "({document}) by {current_user}".format(
                    recid=recid,
                    filename=filename,
                    document=document,
                    current_user=current_user))
            continue

        if document.get(
                'linked',
                False) and (document.get('uri').startswith('http://')
                            or document.get('uri').startswith('https://')):
            url = document.get('uri')
        else:
            url = url_for('record.file', recid=recid, filename=filename)

        (dummy, name, superformat) = decompose_file(filename)

        class LegacyBibDoc(object):
            def __init__(self, **kwargs):
                for key, value in kwargs.items():
                    setattr(self, key, value)

            def get_full_path(self):
                return document.get('uri')

            def get_recid(self):
                return recid

        yield LegacyBibDoc(name=name, superformat=superformat, url=url)
예제 #3
0
파일: utils.py 프로젝트: Theer108/invenio
def _get_document(uuid):
    """Get the document fullpath.

    :param str uuid: The document's uuid
    """
    from invenio.modules.documents.api import Document
    from invenio.modules.documents.errors import (
        DocumentNotFound, DeletedDocument
    )

    try:
        document = Document.get_document(uuid)
    except (DocumentNotFound, DeletedDocument):
        path = _simulate_file_not_found()
    else:
        path = document.get('uri', ''), document.is_authorized()
    finally:
        return path
예제 #4
0
파일: api.py 프로젝트: chokribr/invenio-1
    def get_image(cls, uuid):
        """Return the image object.

        :param str uuid: The document uuid
        :returns: a :class:`~invenio.modules.multimedia.api.MultimediaImage`
                  instance
        """
        try:
            document = Document.get_document(uuid)
        except DocumentNotFound:
            raise MultimediaImageNotFound(
                "The requested image {0} not found".format(uuid))

        if not document.get('uri'):
            raise MultimediaImageNotFound(
                "The requested image {0} not found".format(uuid))

        image = Image.open(document['uri'])
        return cls(image)
예제 #5
0
파일: api.py 프로젝트: SCOAP3/invenio
    def get_image(cls, uuid):
        """Return the image object.

        :param str uuid: The document uuid
        :returns: a :class:`~invenio.modules.multimedia.api.MultimediaImage`
                  instance
        """
        try:
            document = Document.get_document(uuid)
        except DocumentNotFound:
            raise MultimediaImageNotFound(
                "The requested image {0} not found".format(uuid))

        if not document.get('uri'):
            raise MultimediaImageNotFound(
                "The requested image {0} not found".format(uuid))

        image = Image.open(document['uri'])
        return cls(image)
예제 #6
0
파일: utils.py 프로젝트: dset0x/invenio
def get_record_documents(recid, filename):
    """Yield LegacyBibDoc files from Documents."""
    from invenio_records.api import get_record
    from invenio.modules.documents.api import Document
    from invenio.legacy.bibdocfile.api import decompose_file

    record = get_record(recid)
    duuids = [uuid for (k, uuid) in record.get('_documents', [])
              if k == filename]

    for duuid in duuids:
        document = Document.get_document(duuid)
        if not document.is_authorized(current_user):
            current_app.logger.info(
                "Unauthorized access to /{recid}/files/{filename} "
                "({document}) by {current_user}".format(
                    recid=recid, filename=filename, document=document,
                    current_user=current_user))
            continue

        if document.get('linked', False) and (
                document.get('uri').startswith('http://') or
                document.get('uri').startswith('https://')):
            url = document.get('uri')
        else:
            url = url_for('record.file', recid=recid, filename=filename)

        (dummy, name, superformat) = decompose_file(filename)

        class LegacyBibDoc(object):
            def __init__(self, **kwargs):
                for key, value in kwargs.items():
                    setattr(self, key, value)

            def get_full_path(self):
                return document.get('uri')

            def get_recid(self):
                return recid

        yield LegacyBibDoc(name=name, superformat=superformat, url=url)
 def setUp(self):
     """Run before the test."""
     from invenio.modules.documents.api import Document
     self.document = Document.create({'title': 'J.A.R.V.I.S'})
     self.path = tempfile.mkdtemp()
 def setUp(self):
     """Run before the test."""
     from invenio.modules.documents.api import Document
     self.document = Document.create({'title': 'Test restrictions'})
 def setUp(self):
     """Run before the test."""
     from invenio.modules.documents.api import Document
     self.document = Document.create({'title': 'J.A.R.V.I.S'})
     self.path = tempfile.mkdtemp()
    def setUp(self):
        """Run before the test."""
        from invenio.modules.documents.api import Document

        self.document = Document.create({"title": "Test restrictions"})