Example #1
0
    def test_get_file_download_and_render_links(self, file_one, node):
        mfr_link = get_mfr_url(file_one.target, 'osfstorage')

        # file links with path
        download_link = get_file_download_link(file_one)
        assert download_link == '{}download/{}/'.format(
            settings.DOMAIN, file_one._id)
        assert get_file_render_link(
            mfr_link,
            download_link) == build_expected_render_link(mfr_link,
                                                         download_link,
                                                         with_version=False)

        # file versions link with path
        download_link = get_file_download_link(file_one, version=2)
        assert download_link == '{}download/{}/?revision=2'.format(
            settings.DOMAIN, file_one._id)
        assert get_file_render_link(mfr_link, download_link,
                                    version=2) == build_expected_render_link(
                                        mfr_link, download_link)

        # file links with guid
        file_one.get_guid(create=True)
        download_link = get_file_download_link(file_one)
        assert download_link == '{}download/{}/'.format(
            settings.DOMAIN,
            file_one.get_guid()._id)
        assert get_file_render_link(
            mfr_link,
            download_link) == build_expected_render_link(mfr_link,
                                                         download_link,
                                                         with_version=False)

        # file version links with guid
        download_link = get_file_download_link(file_one, version=2)
        assert download_link == '{}download/{}/?revision=2'.format(
            settings.DOMAIN,
            file_one.get_guid()._id)
        assert get_file_render_link(mfr_link, download_link,
                                    version=2) == build_expected_render_link(
                                        mfr_link, download_link)
Example #2
0
    def get_download_link(self, obj):
        """
        First osfstoragefile on a node - if the node was created for a meeting,
        assuming its first file is the meeting submission.
        """
        if getattr(obj, 'file_id', None):
            submission_file = OsfStorageFile.objects.get(_id=obj.file_id)
        else:
            submission_file = self.get_submission_file(obj)

        if submission_file:
            return get_file_download_link(submission_file)
        return None
Example #3
0
    def serialize_file(cls, preprint, file_node):
        """Serialize an BaseFileNode for submission to Chronos.

        It is currently unclear what MANUSCRIPT_FILE_CATEGORY should be.
        Possible options are:
        * supplementaryMaterial
        * articleContent
        * movie
        * combinedPDF
        * PublicationFiles
        * supportingFile
        * coverLetter

        Note:
            `FILE_DOWNLOAD_URL` MUST be accessible by Chronos as it attempts to download
            all files given to it.

        Args:
            preprint: The Preprint that is being submitted
            file_node: The AbstractFileNode to serialize. Should belong to `preprint`

        Returns:
            The serialized AbstractFileNode
        """
        assert file_node.is_file

        if CHRONOS_USE_FAKE_FILE:
            file_url = CHRONOS_FAKE_FILE_URL
        else:
            file_url = get_file_download_link(file_node)

        return {
            'FILE_DOWNLOAD_URL': file_url,
            'FILE_NAME': file_node.name,
            'MANUSCRIPT_FILE_CATEGORY': 'Publication Files',
        }
Example #4
0
    def serialize_file(cls, preprint, file_node):
        """Serialize an BaseFileNode for submission to Chronos.

        It is currently unclear what MANUSCRIPT_FILE_CATEGORY should be.
        Possible options are:
        * supplementaryMaterial
        * articleContent
        * movie
        * combinedPDF
        * PublicationFiles
        * supportingFile
        * coverLetter

        Note:
            `FILE_DOWNLOAD_URL` MUST be accessible by Chronos as it attempts to download
            all files given to it.

        Args:
            preprint: The Preprint that is being submitted
            file_node: The AbstractFileNode to serialize. Should belong to `preprint`

        Returns:
            The serialized AbstractFileNode
        """
        assert file_node.is_file

        if CHRONOS_USE_FAKE_FILE:
            file_url = CHRONOS_FAKE_FILE_URL
        else:
            file_url = get_file_download_link(file_node)

        return {
            'FILE_DOWNLOAD_URL': file_url,
            'FILE_NAME': file_node.name,
            'MANUSCRIPT_FILE_CATEGORY': 'Publication Files',
        }