src/pds_doi_service/core/outputs/osti/osti_record.py
def create_doi_record(self, dois, content_type=CONTENT_TYPE_XML):
        """
        Creates a DOI record from the provided list of Doi objects in the
        specified format.

        Parameters
        ----------
        dois : Doi or list of Dois
            The Doi object to format into the returned record.
        content_type : str
            The type of record to return. Currently, 'xml' and 'json' are
            supported.

        Returns
        -------
        record : str
            The text body of the record created from the provided Doi objects.

        """
        if content_type not in VALID_CONTENT_TYPES:
            raise ValueError("Invalid content type requested, must be one of " f'{",".join(VALID_CONTENT_TYPES)}')

        # If a single DOI was provided, wrap it in a list so the iteration
        # below still works
        if isinstance(dois, Doi):
            dois = [dois]

        rendered_dois = []

        for index, doi in enumerate(dois):
            # Filter out any keys with None as the value, so the string literal
            # "None" is not written out as an XML tag's text body
            doi_fields = dict(filter(lambda elem: elem[1] is not None, doi.__dict__.items()))

            # Escape any necessary HTML characters from the site-url, which is necessary for XML format labels
            if doi.site_url:
                doi_fields["site_url"] = html.escape(doi.site_url)

            # Convert set of keywords back to a semi-colon delimited string
            if doi.keywords:
                doi_fields["keywords"] = ";".join(sorted(map(sanitize_json_string, doi.keywords)))
            else:
                doi_fields.pop("keywords")

            # publication_date is assigned to a Doi object as a datetime,
            # need to convert to a string for the OSTI label. Note that
            # even if we only had the publication year from the PDS4 label,
            # the OSTI schema still expects YYYY-mm-dd format.
            if isinstance(doi.publication_date, datetime):
                doi_fields["publication_date"] = doi.publication_date.strftime("%Y-%m-%d")

            # Same goes for date_record_added and date_record_updated
            if doi.date_record_added and isinstance(doi.date_record_added, datetime):
                doi_fields["date_record_added"] = doi.date_record_added.strftime("%Y-%m-%d")

            if doi.date_record_updated and isinstance(doi.date_record_updated, datetime):
                doi_fields["date_record_updated"] = doi.date_record_updated.strftime("%Y-%m-%d")

            # Remove any extraneous whitespace from title and description
            if doi.title:
                doi_fields["title"] = sanitize_json_string(doi.title)

            if doi.description:
                doi_fields["description"] = sanitize_json_string(doi.description)

            rendered_dois.append(doi_fields)

        template_vars = {"dois": rendered_dois}
        rendered_template = self._template_map[content_type].render(template_vars)

        return rendered_template

        Creates a DOI record from the provided list of Doi objects in the
        specified format.

        Parameters
        ----------
        dois : Doi or list of Dois
            The Doi object to format into the returned record.
        content_type : str
            The type of record to return. Currently, 'xml' and 'json' are
            supported.

        Returns
        -------
        record : str
            The text body of the record created from the provided Doi objects.

        
Creates a DOI record from the provided list of Doi objects in the
specified format.

Parameters

dois : Doi or list of Dois
The Doi object to format into the returned record.
content_type : str
The type of record to return. Currently, 'xml' and 'json' are
supported.

Returns

record : str
The text body of the record created from the provided Doi objects.
Creates a DOI record from the provided list of Doi objects in the specified format . Parameters dois : Doi or list of Dois The Doi object to format into the returned record . content_type : str The type of record to return . Currently ' xml ' and ' json ' are supported . Returns record : str The text body of the record created from the provided Doi objects .
def create_doi_record(self, dois, content_type=CONTENT_TYPE_XML):
        if content_type not in VALID_CONTENT_TYPES:
            raise ValueError("Invalid content type requested, must be one of " f'{",".join(VALID_CONTENT_TYPES)}')
        if isinstance(dois, Doi):
            dois = [dois]
        rendered_dois = []
        for index, doi in enumerate(dois):
            doi_fields = dict(filter(lambda elem: elem[1] is not None, doi.__dict__.items()))
            if doi.site_url:
                doi_fields["site_url"] = html.escape(doi.site_url)
            if doi.keywords:
                doi_fields["keywords"] = ";".join(sorted(map(sanitize_json_string, doi.keywords)))
            else:
                doi_fields.pop("keywords")
            if isinstance(doi.publication_date, datetime):
                doi_fields["publication_date"] = doi.publication_date.strftime("%Y-%m-%d")
            if doi.date_record_added and isinstance(doi.date_record_added, datetime):
                doi_fields["date_record_added"] = doi.date_record_added.strftime("%Y-%m-%d")
            if doi.date_record_updated and isinstance(doi.date_record_updated, datetime):
                doi_fields["date_record_updated"] = doi.date_record_updated.strftime("%Y-%m-%d")
            if doi.title:
                doi_fields["title"] = sanitize_json_string(doi.title)
            if doi.description:
                doi_fields["description"] = sanitize_json_string(doi.description)
            rendered_dois.append(doi_fields)
        template_vars = {"dois": rendered_dois}
        rendered_template = self._template_map[content_type].render(template_vars)
        return rendered_template
def create_doi_record ( self , dois , content_type = CONTENT_TYPE_XML ) : if content_type not in VALID_CONTENT_TYPES : raise ValueError ( "Invalid content type requested, must be one of " f'{",".join(VALID_CONTENT_TYPES)}' ) if isinstance ( dois , Doi ) : dois = [ dois ] rendered_dois = [ ] for index , doi in enumerate ( dois ) : doi_fields = dict ( filter ( lambda elem : elem [ 1 ] is not None , doi . __dict__ . items ( ) ) ) if doi . site_url : doi_fields [ "site_url" ] = html . escape ( doi . site_url ) if doi . keywords : doi_fields [ "keywords" ] = ";" . join ( sorted ( map ( sanitize_json_string , doi . keywords ) ) ) else : doi_fields . pop ( "keywords" ) if isinstance ( doi . publication_date , datetime ) : doi_fields [ "publication_date" ] = doi . publication_date . strftime ( "%Y-%m-%d" ) if doi . date_record_added and isinstance ( doi . date_record_added , datetime ) : doi_fields [ "date_record_added" ] = doi . date_record_added . strftime ( "%Y-%m-%d" ) if doi . date_record_updated and isinstance ( doi . date_record_updated , datetime ) : doi_fields [ "date_record_updated" ] = doi . date_record_updated . strftime ( "%Y-%m-%d" ) if doi . title : doi_fields [ "title" ] = sanitize_json_string ( doi . title ) if doi . description : doi_fields [ "description" ] = sanitize_json_string ( doi . description ) rendered_dois . append ( doi_fields ) template_vars = { "dois" : rendered_dois } rendered_template = self . _template_map [ content_type ] . render ( template_vars ) return rendered_template
Creates a DOI record from the provided list of Doi objects in the
specified format.
Creates a DOI record from the provided list of Doi objects in the specified format .
"""
        Creates a DOI record from the provided list of Doi objects in the
        specified format.

        Parameters
        ----------
        dois : Doi or list of Dois
            The Doi object to format into the returned record.
        content_type : str
            The type of record to return. Currently, 'xml' and 'json' are
            supported.

        Returns
        -------
        record : str
            The text body of the record created from the provided Doi objects.

        """ # If a single DOI was provided, wrap it in a list so the iteration # below still works # Filter out any keys with None as the value, so the string literal # "None" is not written out as an XML tag's text body # Escape any necessary HTML characters from the site-url, which is necessary for XML format labels # Convert set of keywords back to a semi-colon delimited string # publication_date is assigned to a Doi object as a datetime, # need to convert to a string for the OSTI label. Note that # even if we only had the publication year from the PDS4 label, # the OSTI schema still expects YYYY-mm-dd format. # Same goes for date_record_added and date_record_updated # Remove any extraneous whitespace from title and description
self
dois
content_type