Esempio n. 1
0
class UIObjectSchema(Schema):
    """Schema for dumping extra information for the UI."""

    publication_date_l10n_medium = FormatEDTF(
        attribute='metadata.publication_date', format='medium')

    publication_date_l10n_long = FormatEDTF(
        attribute='metadata.publication_date', format='long')

    created_date_l10n_long = FormatDate(attribute='created', format='long')

    updated_date_l10n_long = FormatDate(attribute='updated', format='long')

    resource_type = VocabularyTitleField('resource_type',
                                         attribute='metadata.resource_type')

    # access_right = fields.Nested(AccessRightSchema, attribute='access')

    creators = fields.Function(partial(make_affiliation_index, 'creators'))

    contributors = fields.Function(
        partial(make_affiliation_index, 'contributors'))

    languages = fields.Function(
        partial(localize_vocabulary_list, 'languages', 'title'))

    description_stripped = StrippedHTML(attribute="metadata.description")

    version = fields.Function(record_version)
Esempio n. 2
0
class UIObjectSchema(Schema):
    """Schema for dumping extra information for the UI."""

    publication_date_l10n_medium = FormatEDTF(
        attribute='metadata.publication_date', format='medium')

    publication_date_l10n_long = FormatEDTF(
        attribute='metadata.publication_date', format='long')

    created_date_l10n_long = FormatDate(attribute='created', format='long')

    updated_date_l10n_long = FormatDate(attribute='updated', format='long')

    resource_type = fields.Nested(
        ResourceTypeL10NSchema,
        attribute='metadata.resource_type'
    )

    access_status = AccessStatusField(attribute='access')

    creators = fields.Function(partial(make_affiliation_index, 'creators'))

    contributors = fields.Function(
        partial(make_affiliation_index, 'contributors'))

    languages = fields.List(
        fields.Nested(LanguageL10NSchema),
        attribute='metadata.languages',
    )

    description_stripped = StrippedHTML(attribute="metadata.description")

    version = fields.Function(record_version)
Esempio n. 3
0
class UIObjectSchema(Schema):
    """Schema for dumping extra information for the UI."""

    publication_date_l10n_medium = FormatEDTF(
        attribute='metadata.publication_date', format='medium')

    publication_date_l10n_long = FormatEDTF(
        attribute='metadata.publication_date', format='long')

    created_date_l10n_long = FormatDate(attribute='created', format='long')

    updated_date_l10n_long = FormatDate(attribute='updated', format='long')

    resource_type = fields.Nested(
        VocabularyL10Schema,
        attribute='metadata.resource_type'
    )

    additional_titles = fields.List(
        fields.Nested(AdditionalTitlesSchema),
        attribute='metadata.additional_titles'
    )

    access_status = AccessStatusField(attribute='access')

    creators = fields.Function(partial(make_affiliation_index, 'creators'))

    contributors = fields.Function(
        partial(make_affiliation_index, 'contributors'))

    languages = fields.List(
        fields.Nested(VocabularyL10Schema),
        attribute='metadata.languages',
    )

    subjects = fields.List(
        fields.Nested(VocabularyL10Schema),
        attribute='metadata.subjects',
    )

    description_stripped = StrippedHTML(attribute="metadata.description")

    version = fields.Function(record_version)

    related_identifiers = fields.List(
        fields.Nested(RelatedIdentifiersSchema()),
        attribute="metadata.related_identifiers"
    )

    additional_descriptions = fields.List(
        fields.Nested(AdditionalDescriptionsSchema()),
        attribute="metadata.additional_descriptions"
    )

    dates = fields.List(
        fields.Nested(DatesSchema()),
        attribute="metadata.dates"
    )
Esempio n. 4
0
class DatesSchema(Schema):
    """Localization of dates."""

    date = fields.String()
    type = fields.Nested(
        VocabularyL10Schema,
        attribute='type'
    )
    description = StrippedHTML(attribute='description')
Esempio n. 5
0
class AdditionalDescriptionsSchema(Schema):
    """Localization of additional descriptions."""

    description = StrippedHTML(attribute='description')
    type = fields.Nested(
        VocabularyL10Schema,
        attribute='type'
    )
    lang = fields.Nested(
        VocabularyL10Schema,
        attribute='lang'
    )
Esempio n. 6
0
class CSLJSONSchema(Schema):
    """CSL Marshmallow Schema."""

    id_ = SanitizedUnicode(data_key="id", attribute="id")
    type_ = fields.Method("get_type", data_key="type")
    title = SanitizedUnicode(attribute="metadata.title")
    abstract = StrippedHTML(attribute="metadata.description")
    author = fields.List(fields.Nested(CSLCreatorSchema),
                         attribute="metadata.creators")
    issued = fields.Method("get_issued")
    language = fields.Method("get_language")
    version = SanitizedUnicode(attribute="metadata.version")
    note = fields.Method("get_note")
    doi = fields.Method("get_doi", data_key="DOI")
    isbn = fields.Method("get_isbn", data_key="ISBN")
    issn = fields.Method("get_issn", data_key="ISSN")
    publisher = SanitizedUnicode(attribute="metadata.publisher")

    def _read_resource_type(self, id_):
        """Retrieve resource type record using service."""
        rec = vocabulary_service.read(("resourcetypes", id_), system_identity)
        return rec._record

    def get_type(self, obj):
        """Get resource type."""
        resource_type = obj["metadata"].get(
            "resource_type",
            {"id": "publication-article"}
        )

        resource_type_record = self._read_resource_type(resource_type["id"])
        props = resource_type_record["props"]
        return props.get("csl", "article")  # article is CSL "Other"

    def get_issued(self, obj):
        """Get issued dates."""
        try:
            parsed = parse_edtf(obj["metadata"].get("publication_date"))
        except EDTFParseException:
            return missing

        if isinstance(parsed, Date):
            parts = add_if_not_none(parsed.year, parsed.month, parsed.day)
            return {"date-parts": [parts]}
        elif isinstance(parsed, Interval):
            d1 = parsed.lower
            d2 = parsed.upper
            return {
                "date-parts": [
                    add_if_not_none(d1.year, d1.month, d1.day),
                    add_if_not_none(d2.year, d2.month, d2.day),
                ]
            }
        else:
            return missing

    def get_language(self, obj):
        """Get language."""
        metadata = obj["metadata"]
        languages = metadata.get("languages")

        return languages[0]["id"] if languages else missing

    def get_doi(self, obj):
        """Get DOI."""
        return obj["pids"].get("doi", {}).get("identifier", missing)

    def get_isbn(self, obj):
        """Get ISBN."""
        identifiers = obj["metadata"].get("identifiers", [])
        for identifier in identifiers:
            if identifier["scheme"] == "ISBN":
                return identifier["identifier"]

        return missing

    def get_issn(self, obj):
        """Get ISSN."""
        identifiers = obj["metadata"].get("identifiers", [])
        for identifier in identifiers:
            if identifier["scheme"] == "ISSN":
                return identifier["identifier"]

        return missing

    def get_note(self, obj):
        """Get note from funders."""
        funding = obj["metadata"].get("funding")
        if funding:
            funder = funding[0]["funder"]
            note = f"Funding by {funder['name']}"
            scheme = funder.get("scheme", "").upper()
            identifier = funder.get("identifier", "")

            if scheme:
                note = note + " " + scheme
            if identifier:
                note = note + " " + identifier + "."

            return note

        return missing