deposit.protocol module

exception deposit.protocol.DepositError[source]

Bases: exceptions.Exception

The exception to raise when something wrong happens during the deposition process

class deposit.protocol.DepositResult(identifier=None, splash_url=None, pdf_url=None, logs=None, status=u'published', message=None)[source]

Bases: object

Small object containing the result of a deposition process. This object will be stored in two rows in the database: in a BareOaiRecord and in a DepositRecord.

status should be one of DEPOSIT_STATUS_CHOICES

class deposit.protocol.RepositoryProtocol(repository, **kwargs)[source]

Bases: object

The protocol for a repository where papers can be deposited. Actual implementations should inherit from this class.

form_class

alias of BaseMetadataForm

get_bound_form(data)[source]

Returns a bound version of the form, with the given data. Here, data is expected to come from a POST request generated by the user, ready for validation.

get_form()[source]

Returns the form where the user will be able to give additional metadata. It is prefilled with the initial data from get_form_initial_data

get_form_initial_data()[source]

Returns the form’s initial values.

init_deposit(paper, user)[source]

Called when a user starts considering depositing a paper to a repository.

Parameters:
  • paper – The paper to be deposited.
  • user – The user submitting the deposit.
Returns:

a boolean indicating if the repository can be used in this case.

log(line)[source]

Logs a line in the protocol log.

log_request(r, expected_status_code, error_msg)[source]

Logs an HTTP request and raises an error if the status code is unexpected.

protocol_identifier()[source]

Returns an identifier for the protocol.

refresh_deposit_status(deposit_record)[source]

Given the DepositRecord created by a previous deposit, update its deposit status. This function will be called regularly, so that we can stay in sync with the deposit while it makes it way through the pipeline in the repository.

By default this does not do anything (i.e. leaves the DepositRecord unchanged).

Parameters:deposit_record – the DepositRecord to update
submit_deposit(pdf, form, dry_run=False)[source]

Submit a paper to the repository. This is expected to raise DepositError if something goes wrong.

Parameters:
  • pdf – Filename to the PDF file to submit
  • form – The form returned by get_form and completed by the user.
  • dry_run – if True, should
Returns:

a DepositResult object.

submit_deposit_wrapper(*args, **kwargs)[source]

Wrapper of the submit_deposit method (that should not need to be reimplemented). It catches DepositErrors raised in the deposit process and adds the logs to its return value.