Пример #1
0
    def test_csl_multiple_authors(self):
        # Nodes with multiple contributors generate valid CSL-data
        user = UserFactory()
        self.node.add_contributor(user)
        self.node.save()

        assert_equal(
            self.node.csl,
            {
                'publisher': 'Open Science Framework',
                'author': [
                    {
                        'given': self.node.creator.given_name,
                        'family': self.node.creator.family_name,
                    },
                    {
                        'given': user.given_name,
                        'family': user.family_name,
                    }
                ],
                'URL': self.node.display_absolute_url,
                'issued': datetime_to_csl(self.node.logs.latest().date),
                'title': self.node.title,
                'type': 'webpage',
                'id': self.node._id,
            },
        )
Пример #2
0
    def test_csl_multiple_authors(self):
        # Nodes with multiple contributors generate valid CSL-data
        user = UserFactory()
        self.node.add_contributor(user)
        self.node.save()

        assert_equal(
            self.node.csl,
            {
                'publisher':
                'Open Science Framework',
                'author': [{
                    'given': self.node.creator.given_name,
                    'family': self.node.creator.family_name,
                }, {
                    'given': user.given_name,
                    'family': user.family_name,
                }],
                'URL':
                self.node.display_absolute_url,
                'issued':
                datetime_to_csl(self.node.logs.latest().date),
                'title':
                self.node.title,
                'type':
                'webpage',
                'id':
                self.node._id,
            },
        )
Пример #3
0
    def csl(self):  # formats node information into CSL format for citation parsing
        """a dict in CSL-JSON schema

        For details on this schema, see:
            https://github.com/citation-style-language/schema#csl-json-schema
        """
        csl = {
            'id': self._id,
            'title': sanitize.unescape_entities(self.title),
            'author': [
                contributor.csl_name(self._id)  # method in auth/model.py which parses the names of authors
                for contributor in self.visible_contributors
            ],
            'type': 'webpage',
            'URL': self.display_absolute_url,
            'publisher': 'OSF Preprints' if self.provider.name == 'Open Science Framework' else self.provider.name
        }

        article_doi = self.article_doi
        preprint_doi = self.preprint_doi

        if article_doi:
            csl['DOI'] = article_doi
        elif preprint_doi and self.is_published and self.preprint_doi_created:
            csl['DOI'] = preprint_doi

        if self.date_published:
            csl['issued'] = datetime_to_csl(self.date_published)

        return csl
Пример #4
0
    def csl(self):  # formats node information into CSL format for citation parsing
        """a dict in CSL-JSON schema

        For details on this schema, see:
            https://github.com/citation-style-language/schema#csl-json-schema
        """
        csl = {
            'id': self._id,
            'title': sanitize.unescape_entities(self.title),
            'author': [
                contributor.csl_name(self._id)  # method in auth/model.py which parses the names of authors
                for contributor in self.visible_contributors
            ],
            'type': 'webpage',
            'URL': self.display_absolute_url,
            'publisher': 'OSF Preprints' if self.provider.name == 'Open Science Framework' else self.provider.name
        }

        article_doi = self.article_doi
        preprint_doi = self.preprint_doi

        if article_doi:
            csl['DOI'] = article_doi
        elif preprint_doi and self.is_published and self.preprint_doi_created:
            csl['DOI'] = preprint_doi

        if self.date_published:
            csl['issued'] = datetime_to_csl(self.date_published)

        return csl
Пример #5
0
    def test_datetime_to_csl(self):
        # Convert a datetime instance to csl's date-variable schema
        now = timezone.now()

        assert_equal(
            datetime_to_csl(now),
            {'date-parts': [[now.year, now.month, now.day]]},
        )
Пример #6
0
    def test_datetime_to_csl(self):
        # Convert a datetime instance to csl's date-variable schema
        now = timezone.now()

        assert_equal(
            datetime_to_csl(now),
            {'date-parts': [[now.year, now.month, now.day]]},
        )
Пример #7
0
 def test_csl_single_author(self):
     # Nodes with one contributor generate valid CSL-data
     assert_equal(
         self.node.csl,
         {
             'publisher': 'Open Science Framework',
             'author': [{
                 'given': self.node.creator.given_name,
                 'family': self.node.creator.family_name,
             }],
             'URL': self.node.display_absolute_url,
             'issued': datetime_to_csl(self.node.logs.latest().date),
             'title': self.node.title,
             'type': 'webpage',
             'id': self.node._id,
         },
     )
Пример #8
0
 def test_csl_single_author(self):
     # Nodes with one contributor generate valid CSL-data
     assert_equal(
         self.node.csl,
         {
             'publisher': 'Open Science Framework',
             'author': [{
                 'given': self.node.creator.given_name,
                 'family': self.node.creator.family_name,
             }],
             'URL': self.node.display_absolute_url,
             'issued': datetime_to_csl(self.node.logs.latest().date),
             'title': self.node.title,
             'type': 'webpage',
             'id': self.node._id,
         },
     )
Пример #9
0
def preprint_csl(preprint, node):
    csl = node.csl

    csl['id'] = preprint._id
    csl['publisher'] = preprint.provider.name
    csl['URL'] = display_absolute_url(preprint)

    if preprint.original_publication_date:
        csl['issued'] = datetime_to_csl(preprint.original_publication_date)

    if csl.get('DOI'):
        csl.pop('DOI')

    doi = preprint.article_doi
    if doi:
        csl['DOI'] = doi

    return csl
Пример #10
0
def preprint_csl(preprint, node):
    csl = node.csl

    csl['id'] = preprint._id
    csl['publisher'] = 'OSF Preprints' if preprint.provider.name == 'Open Science Framework' else preprint.provider.name
    csl['URL'] = display_absolute_url(preprint)

    if preprint.original_publication_date:
        csl['issued'] = datetime_to_csl(preprint.original_publication_date)

    if csl.get('DOI'):
        csl.pop('DOI')

    article_doi = preprint.article_doi
    preprint_doi = preprint.preprint_doi

    if article_doi:
        csl['DOI'] = article_doi
    elif preprint_doi and preprint.is_published and preprint.preprint_doi_created:
        csl['DOI'] = preprint_doi
    return csl
Пример #11
0
def preprint_csl(preprint, node):
    csl = node.csl

    csl['id'] = preprint._id
    csl['publisher'] = 'OSF Preprints' if preprint.provider.name == 'Open Science Framework' else preprint.provider.name
    csl['URL'] = display_absolute_url(preprint)

    if preprint.original_publication_date:
        csl['issued'] = datetime_to_csl(preprint.original_publication_date)

    if csl.get('DOI'):
        csl.pop('DOI')

    article_doi = preprint.article_doi
    preprint_doi = preprint.preprint_doi

    if article_doi:
        csl['DOI'] = article_doi
    elif preprint_doi and preprint.is_published and preprint.preprint_doi_created:
        csl['DOI'] = preprint_doi
    return csl