Citation Auto Generation (Serializer Classes)

Citation records (and other records) are auto-filled with additional content through the Serializer classes from django rest framework. All auto-generation and validation steps are centralised in the Serializer classes, with very little functionality being required from the Views classes except for rendering changes.

The process for updating a record is as follows:
  • UI/API view registers a change to a record.

  • Serializer is instantiated and the data is validated.

  • Serializer is then used to create/update records (serializer.save)
    • Provided data is filtered to remove unknown arguments (mostly from the API)

    • The fill_data_parameters serializer method fills in new parameters, and instantiates sub-records (i.e institutions, funders, parties)

    • The publication workflow is executed if required.

    • The update is made via the create/update instance functions that route changes through the Kafka system if it is in use.

See below for a list of the functions used to fill content in the records.

citations.serializers.mint_doi_for_data(data: dict, id: str) dict | None[source]

‘Data’ is the partially serialized content for the record to be published.

  • Expand all creators (proper serialization)

  • Expand all funders

  • Expand all references

  • Send data to publish record

This function is considered a ‘core’ function because it relies on access to the models of this application.

citations.serializers.institution_mappings(institution_id: str, project_id: str = 'cmip7') str[source]

Apply known institution mappings given the institution_id which is most likely the acronym.

citations.serializers.title_from_facets(data: dict, raise_exceptions: bool = True) str | list | None[source]

Validate by generating the expected title from the facets.

Facet title generation is project_id specific. If the project_id is not contained in the data, this function should not be run, but will return a None value.

citations.serializers.obtain_all_references(data: dict) dict[source]

Obtain Citation references from the EMD (ESGVOC)

Prevent adding a reference if it already exists.

citations.serializers.assemble_license_info(data: dict) str[source]

Determine the paragraph of text to use for the license.

citations.serializers.abstract_from_esgvoc(data: dict)[source]

Determine the paragraph of abstract text from esgvoc parameters.

citations.serializers.chain_new_objects(data: dict, serializer: ModelSerializer, model: type[Model], filter_kwargs: list, optionals: list = None, allow_update: bool = False) str[source]

Create new model instances if required, or return the ID of the existing instance.

This includes locating the existing record based on some filter kwargs (normally just the ID) to identify the existing instance.

class citations.serializers.GenericSerializerMixin(*args, **kwargs)[source]
to_internal_value(data)[source]

Dict of native values <- Dict of primitive datatypes.

filter_data(validated_data: dict) dict[source]

Filter out unrecognised parameters.

Also runs the fill_data_parameters method to auto-generate content.

replace_id_relations(validated_data: dict) dict[source]

Replace relations like primary in the citations model with primary_id

create(validated_data)[source]

Create and return a model instance given validated data.

update(instance, validated_data: dict)[source]

Update and return an existing instance, given the validated data.

class citations.serializers.InstitutionsSerializer(*args, **kwargs)[source]
fill_data_parameters(data)[source]

Auto-fill content into the data dict.

class citations.serializers.PartiesSerializer(*args, **kwargs)[source]
fill_data_parameters(data)[source]

Auto-fill content into the data dict.

class citations.serializers.FundingStreamsSerializer(*args, **kwargs)[source]
fill_data_parameters(data)[source]

Auto-fill content into the data dict.

class citations.serializers.ReferencesSerializer(*args, **kwargs)[source]
fill_data_parameters(data)[source]

No data filling for references

class citations.serializers.CitationsSerializer(*args, **kwargs)[source]
create(validated_data)[source]

Apply extra validation to the citation record.

This validates the search_facets if they have been provided to this record.

fill_data_parameters(data: dict)[source]

Update the data in a POST request.

Locate or create references based on the provided information.

citations.serializers.handle_update(table: str, method: str, content: dict)[source]

Handle ANY ORM Request updates here.

This function is passed to the Kafka update system, and will be called directly if the Kafka Internal Queue is disabled.