Biosample App

The biosample app is responsible of registering users to BioSamples servers, managing their authentications during submission/retrieval and submit and retrieve results from BioSamples servers. It relies on pyUSIrest module for data submission and can override the default endpoints of that module relying on InjectTool configuration (please see Switch to BioSamples production environment). Every time the biosample module is imported during InjectTool instantiation or by calling managent processes this coded is executed to ovverride BioSamples endpoints:

import pyUSIrest.settings

from common.constants import EBI_AAP_API_AUTH, BIOSAMPLE_API_ROOT

# Ovveride pyUSIrest biosample urls, relying on common.constants
if pyUSIrest.settings.AUTH_URL != EBI_AAP_API_AUTH:
    logger.warning("Setting AAP API URL to: %s" % EBI_AAP_API_AUTH)

    # Ovveride Auth.auth_url
    pyUSIrest.settings.AUTH_URL = EBI_AAP_API_AUTH

if pyUSIrest.settings.ROOT_URL != BIOSAMPLE_API_ROOT:
    logger.warning("Setting BIOSAMPLE API ROOT to: %s" % BIOSAMPLE_API_ROOT)

    # Override Root api_root
    pyUSIrest.settings.ROOT_URL = BIOSAMPLE_API_ROOT

EBI_AAP_API_AUTH and BIOSAMPLE_API_ROOT are defined in common.constants and rely on .env configuration file

biosample.forms

biosample.forms module contents

Created on Mon Jun 11 17:20:12 2018

@author: Paolo Cozzi <cozzi@ibba.cnr.it>

class biosample.forms.CreateUserForm(*args, **kwargs)[source]

Bases: common.forms.RequestFormMixin, django.forms.forms.Form

Based on django.contrib.ath.form

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

Initialize self. See help(type(self)) for accurate signature.

base_fields = {'password1': <django.forms.fields.CharField object>, 'password2': <django.forms.fields.CharField object>}
clean_password2()[source]
declared_fields = {'password1': <django.forms.fields.CharField object>, 'password2': <django.forms.fields.CharField object>}
error_messages = {'password_mismatch': "The two password fields didn't match."}
property media

Return all media required to render the widgets on this form.

class biosample.forms.GenerateTokenForm(*args, **kwargs)[source]

Bases: common.forms.RequestFormMixin, django.forms.forms.Form

base_fields = {'name': <django.forms.fields.CharField object>, 'password': <django.forms.fields.CharField object>}
declared_fields = {'name': <django.forms.fields.CharField object>, 'password': <django.forms.fields.CharField object>}
property media

Return all media required to render the widgets on this form.

class biosample.forms.RegisterUserForm(*args, **kwargs)[source]

Bases: common.forms.RequestFormMixin, django.forms.models.ModelForm

class Meta[source]

Bases: object

fields = ('name', 'team')
model

alias of biosample.models.Account

base_fields = {'name': <django.forms.fields.SlugField object>, 'password': <django.forms.fields.CharField object>, 'team': <django.forms.models.ModelChoiceField object>}
declared_fields = {'name': <django.forms.fields.SlugField object>, 'password': <django.forms.fields.CharField object>}
property media

Return all media required to render the widgets on this form.

class biosample.forms.SubmitForm(*args, **kwargs)[source]

Bases: common.forms.RequestFormMixin, django.forms.forms.Form

base_fields = {'name': <django.forms.fields.CharField object>, 'password': <django.forms.fields.CharField object>, 'submission_id': <django.forms.fields.IntegerField object>}
declared_fields = {'name': <django.forms.fields.CharField object>, 'password': <django.forms.fields.CharField object>, 'submission_id': <django.forms.fields.IntegerField object>}
property media

Return all media required to render the widgets on this form.

biosample.helpers

biosample.helpers module contents

Created on Mon Jan 21 12:13:16 2019

@author: Paolo Cozzi <cozzi@ibba.cnr.it>

biosample.helpers.get_auth(user=None, password=None, token=None)[source]

Returns an Auth instance

biosample.helpers.get_manager_auth()[source]

Get an Auth object for imagemanager user

biosample.models

biosample.models module contents

class biosample.models.Account(id, user, name, team)[source]

Bases: django.db.models.base.Model

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
team

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

team_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

user

Accessor to the related object on the forward side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Restaurant.place is a ForwardOneToOneDescriptor instance.

user_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class biosample.models.BaseSubmission(*args, **kwargs)[source]

Bases: django.db.models.base.Model

class Meta[source]

Bases: object

abstract = False
created_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
get_next_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=True, **kwargs)
get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
get_previous_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=False, **kwargs)
get_status_display(*, field=<django.db.models.fields.SmallIntegerField: status>)
message

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

samples_count

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

samples_status

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

status

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

updated_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

usi_submission_name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class biosample.models.ManagedTeam(id, name)[source]

Bases: django.db.models.base.Model

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

account_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

classmethod get_teams()[source]
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
orphansample_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

class biosample.models.OrphanSample(id, submission, biosample_id, found_at, ignore, name, team, status, removed, removed_at)[source]

Bases: django.db.models.base.Model

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

biosample_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

found_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_found_at(*, field=<django.db.models.fields.DateTimeField: found_at>, is_next=True, **kwargs)
get_previous_by_found_at(*, field=<django.db.models.fields.DateTimeField: found_at>, is_next=False, **kwargs)
get_status_display(*, field=<django.db.models.fields.SmallIntegerField: status>)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

ignore

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
removed

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

removed_at

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

status

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

submission

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

submission_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

team

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

team_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class biosample.models.OrphanSubmission(id, usi_submission_name, created_at, updated_at, message, status, samples_count, samples_status)[source]

Bases: biosample.models.BaseSubmission

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
get_next_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=True, **kwargs)
get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
get_previous_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
submission_data

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

class biosample.models.Submission(id, usi_submission_name, created_at, updated_at, message, status, samples_count, samples_status, uid_submission)[source]

Bases: biosample.models.BaseSubmission

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
get_next_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=True, **kwargs)
get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
get_previous_by_updated_at(*, field=<django.db.models.fields.DateTimeField: updated_at>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
submission_data

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

uid_submission

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

uid_submission_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class biosample.models.SubmissionData(id, submission, content_type, object_id)[source]

Bases: django.db.models.base.Model

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

content_object

Provide a generic many-to-one relation through the content_type and object_id fields.

This class also doubles as an accessor to the related object (similar to ForwardManyToOneDescriptor) by adding itself as a model attribute.

content_type

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

content_type_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

name_limit = <Q: (OR: (AND: ('app_label', 'uid'), ('model', 'animal')), (AND: ('app_label', 'uid'), ('model', 'sample')))>
object_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
submission

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

submission_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

biosample.tasks

Biosample tasks are splitted in two main modules, retrieval and submission and classes are defined in modules accordingly if they are used for submission or for retrieval of biosample data. Biosample submission is accomplished in parallel: after starting a submission with SubmitView a SplitSubmissionTask is called in order to split submission data in batches as described in biosample.models.Submission. Then it will start a SubmitTask in order to submit a single batch of data in a new process, able to create a new USI submission. Finally a SubmissionCompleteTask is called after each SubmitTask using a celery.chord, which is a special type of task that is executed after only after other task. This task in particoular marks the submission process as completed in order to be controlled by FetchStatusTask, which if the task able to get statuses and retrieve biosample ids. The retrieval process is performed regularly every 15 minutes by the FetchStatusTask task. If the biosample submission is successful, this task will retrieve the biosample_id back to InjectTool database. Otherwise it will mark objects with NEED_REVISION status. After each submission batches is retrieved with success, the whole submission process is completed by the RetrievalCompleteTask, which is called after each batch object for a submission has been requested.

biosample.tasks module contents

Created on Thu Nov 14 16:06:10 2019

@author: Paolo Cozzi <paolo.cozzi@ibba.cnr.it>

class biosample.tasks.cleanup.CleanUpTask(*args, **kwargs)[source]

Bases: common.tasks.NotifyAdminTaskMixin, common.tasks.BaseTask

Perform biosample.models cleanup by selecting old completed submission and remove them from database

description = 'Clean biosample models'
ignore_result = False
name = 'Clean biosample models'
priority = None
rate_limit = None
reject_on_worker_lost = None
request_stack = <celery.utils.threads._LocalStack object>
run(**kwargs)

The body of the task executed by workers.

serializer = 'json'
store_errors_even_if_ignored = False
track_started = False
typing = True
class biosample.tasks.cleanup.SearchOrphanTask(*args, **kwargs)[source]

Bases: common.tasks.NotifyAdminTaskMixin, common.tasks.BaseTask

Search accross biosamples for objects not present in UID

description = 'Track BioSamples IDs not present in UID'
ignore_result = False
name = 'Search Orphan BioSamples IDs'
priority = None
rate_limit = None
reject_on_worker_lost = None
request_stack = <celery.utils.threads._LocalStack object>
run(**kwargs)

The body of the task executed by workers.

serializer = 'json'
store_errors_even_if_ignored = False
track_started = False
typing = True
biosample.tasks.cleanup.check_orphan_sample(sample)[source]

Get a BioSample record and check if such BioSampleId is registered into InjectTool UID. If Such record is not present, create a new biosample.models.OrphanSample record object in the BioSample orphan table

Parameters

sample (dict) – a BioSample record.

Returns

Return type

None.

async biosample.tasks.cleanup.check_samples()[source]

Get all records from BioSamples submitted by the InjectTool manager auth managed domains, and call check_orphan_sample for each of them

Returns

Return type

None.

async biosample.tasks.cleanup.fecth_biosample(session: aiohttp.client.ClientSession, accession: str, base_url: yarl.URL = URL('https://wwwdev.ebi.ac.uk/biosamples/samples'), headers: dict = {'Accept': 'application/hal+json'}) → Awaitable[dict][source]

Collect a single BioSample object from EBI

Parameters
  • session (aiohttp.ClientSession) – an async session object.

  • accession (str) – a BioSample accession ID.

  • base_url (URL, optional) – DESCRIPTION. The default is BIOSAMPLE_BASE_URL.

  • headers (dict, optional) – DESCRIPTION. The default is HEADERS.

Returns

A BioSample dictionary object

Return type

typing.Awaitable[dict]

async biosample.tasks.cleanup.fetch_url(session, url, params=<MultiDict('size': 500, 'filter': 'attr:project:IMAGE')>, headers=None) → Awaitable[dict][source]

Fetch a generic url, read data as json and return a promise

Parameters
  • session (aiohttp.ClientSession) – an async session object.

  • url (str) – the desidered url

  • params (MultiDict, optional) – Additional params for request. The default is BIOSAMPLE_PARAMS.

  • headers (dict) – Additional HEADER information

Returns

json content of the page

Return type

typing.Awaitable[dict]

biosample.tasks.cleanup.filter_managed_biosamples(session: aiohttp.client.ClientSession, data: dict, managed_domains: list)[source]

Parse data from a BioSample results page and yield samples managed by InjectTool users.

Parameters
  • session (aiohttp.ClientSession) – an async session object.

  • data (dict) – biosample data read from BIOSAMPLE_URL.

  • managed_domains (list) – A list of AAP domains, as returned from pyUSIrest.auth.Auth.get_domains().

Yields

sample (dict) – a BioSample record.

biosample.tasks.cleanup.get_biosamples(url=URL('https://wwwdev.ebi.ac.uk/biosamples/accessions'), params=<MultiDict('size': 500, 'filter': 'attr:project:IMAGE')>, managed_domains=[])[source]

Get all samples from BioSamples for the IMAGE project. Fecth Biosample once, determines how many pages to request and return only accession records managed by InjectTool

Parameters
  • url (str, optional) – The desidered URL. The default is BIOSAMPLE_ACCESSION_ENDPOINT.

  • params (MultiDict, optional) – Additional params for request. The default is BIOSAMPLE_PARAMS.

  • managed_domains (list) – A list of AAP domains, as returned from pyUSIrest.auth.Auth.get_domains().

Yields

sample (dict) – a BioSample record.

biosample.tasks.cleanup.get_orphan_samples(limit=None)[source]

Iterate for all BioSample orphaned records which are not yet removed and are tracked for removal, get minimal data from BioSample and return a dictionary which can be used to patch a BioSample id with a new BioSample submission in order to remove a BioSamples record (publish the BioSample record after 1000 years from Now).

Yields

new_data (dict) – payload to submit to BioSample in order to remove a BioSamples record.

async biosample.tasks.cleanup.parse_json(response, url)[source]

Helper function to parse json data

Created on Tue Jul 16 11:25:03 2019

@author: Paolo Cozzi <cozzi@ibba.cnr.it>

class biosample.tasks.retrieval.FetchStatusHelper(usi_submission, auth)[source]

Bases: object

Helper class to deal with submission data

__init__(usi_submission, auth)[source]

Helper function to have info for a biosample.models.Submission

Parameters
check_submission_status()[source]

Check submission status, finalize submission, check errors etc

complete()[source]

Complete a submission and fetch biosample names

finalize()[source]

Finalize a submission by closing document and send it to biosample

sample_has_errors(sample, table, pk)[source]

Helper metod to mark a (animal/sample) with its own errors. Table sould be Animal or Sample to update the approriate object. Sample is a USI sample object

Parameters
  • sample (pyUSIrest.usi.sample) – a USI sample object

  • table (str) – Animal or Sample, mean the table where this object should be searched

  • pk (int) – table primary key

submission_has_issues()[source]

Check that biosample submission has not issues. For example, that it will remain in the same status for a long time

Returns

True if an issue is detected

Return type

bool

class biosample.tasks.retrieval.FetchStatusTask(*args, **kwargs)[source]

Bases: common.tasks.NotifyAdminTaskMixin, common.tasks.BaseTask

description = 'Fetch biosample using USI API'
fetch_queryset(queryset)[source]

Fetch biosample against a queryset (a list of SUBMITTED Submission objects). Iterate through submission to get USI info. Calls FetchStatusHelper

fetch_status()[source]

Fetch status from pending submissions. Called from run(), handles exceptions from USI, select all Submission objects with SUBMITTED status from UID and call fetch_queryset() with this data

ignore_result = False
name = 'Fetch USI status'
priority = None
rate_limit = None
reject_on_worker_lost = None
request_stack = <celery.utils.threads._LocalStack object>
run(**kwargs)

The body of the task executed by workers.

serializer = 'json'
store_errors_even_if_ignored = False
track_started = False
typing = True
class biosample.tasks.retrieval.RetrievalCompleteTask(*args, **kwargs)[source]

Bases: submissions.tasks.SubmissionTaskMixin, common.tasks.BaseTask

Update submission status after fetching status

action = 'biosample retrieval'
description = 'Check submission status after retrieval nd update stuff'
ignore_result = False
name = 'Complete Retrieval Process'
priority = None
rate_limit = None
reject_on_worker_lost = None
request_stack = <celery.utils.threads._LocalStack object>
run(*args, **kwargs)[source]

Fetch submission data and then update UID submission status

serializer = 'json'
store_errors_even_if_ignored = False
track_started = False
typing = True
update_message(uid_submission, submission_qs, status)[source]

Read biosample.models.Submission message and set uid.models.Submission message relying on status

update_validationsummary(uid_submission)[source]

Update validationsummary message after our USI submission is completed (with errors or not)

Created on Thu Jul 18 14:14:06 2019

@author: Paolo Cozzi <cozzi@ibba.cnr.it>

class biosample.tasks.submission.SplitSubmissionHelper(uid_submission)[source]

Bases: object

helper class to split py:class`uid.models.Submission` data in bacthes limited in sizes

__init__(uid_submission)[source]

Initialize self. See help(type(self)) for accurate signature.

add_to_submission_data(model)[source]

Add a uid.mixins.BioSampleMixin to a biosample.models.Submission object, or create a new one if there are more samples than required

create_submission()[source]

Create a new biosample.models.Submission object and set sample counter to 0

model_in_submission(model)[source]

Check if uid.mixins.BioSampleMixin is already in an opened submission

process_data()[source]

Add animal and its samples to a submission

process_model(model)[source]

Test for a model in a biosample submission. Ignore a model if status is not READY

class biosample.tasks.submission.SplitSubmissionTask(*args, **kwargs)[source]

Bases: submissions.tasks.SubmissionTaskMixin, common.tasks.NotifyAdminTaskMixin, common.tasks.BaseTask

Split submission data in chunks in order to submit data through multiple tasks/processes and with smaller submissions

action = 'biosample submission'
description = 'Split submission data in chunks'
ignore_result = False
name = 'Split submission data'
priority = None
rate_limit = None
reject_on_worker_lost = None
request_stack = <celery.utils.threads._LocalStack object>
run(submission_id)[source]

Call SplitSubmissionHelper to split uid.models.Submission data. Call SubmitTask for each batch of data and then call SubmissionCompleteTask after all data were submitted

serializer = 'json'
store_errors_even_if_ignored = False
track_started = False
typing = True
class biosample.tasks.submission.SubmissionCompleteTask(*args, **kwargs)[source]

Bases: submissions.tasks.SubmissionTaskMixin, common.tasks.NotifyAdminTaskMixin, common.tasks.BaseTask

Update submission status after batch submission

action = 'biosample submission'
description = 'Check submission status and update stuff'
ignore_result = False
name = 'Complete Submission Process'
priority = None
rate_limit = None
reject_on_worker_lost = None
request_stack = <celery.utils.threads._LocalStack object>
run(*args, **kwargs)[source]

Fetch submission data and then update uid.models.Submission status

serializer = 'json'
store_errors_even_if_ignored = False
track_started = False
typing = True
update_message(uid_submission, submission_qs, status)[source]

Read biosample.models.Submission message and set uid.models.Submission message

exception biosample.tasks.submission.SubmissionError[source]

Bases: Exception

Exception call for Error with submissions

class biosample.tasks.submission.SubmissionHelper(submission_id)[source]

Bases: object

An helper class for submission task, used to deal with pyUSIrest

__init__(submission_id)[source]

Initialize self. See help(type(self)) for accurate signature.

add_samples()[source]

Iterate over sample data (animal/sample) and call create_or_update_sample (if model is in READY state)

create_or_update_sample(model)[source]

Add or patch a sample into USI submission document. Can be animal or sample

Parameters

model (uid.mixins.BioSampleMixin) – An animal or sample object

create_submission()[source]

Create a new USI submission object

Returns

pyUSIrest.usi.Submission a pyUSIrest submission object

mark_fail(message)[source]

Set a ERROR status for biosample.models.Submission and a message

mark_submission(status, message)[source]
mark_success(message='Waiting for biosample validation')[source]

Set a SUBMITTED biosample.models.Submission and a message

property owner

Recover owner from a submission object related with a UID Submission

Returns

a django django.contrib.auth.models.User object

Return type

Submission.owner

read_samples()[source]

Read sample in a USI submission document and set submitted_samples attribute

read_token()[source]

Read token from REDIS database and set root attribute with a pyUSIrest.usi.Root instance

Returns

the read token

Return type

str

recover_submission()[source]

Try to recover a USI submission document or raise Exception. If not defined, return false

start_submission()[source]

Get a USI submission document. Recover submission if possible, create a new one if not defined. If recovered submission is closed, raise an error

property team_name

Recover team_name from a submission object

Returns

the team name

Return type

str

property usi_submission_name

Get/set biosample submission id from database

Returns

the biosample USI submission identifier

Return type

str

class biosample.tasks.submission.SubmitTask(*args, **kwargs)[source]

Bases: common.tasks.NotifyAdminTaskMixin, common.tasks.BaseTask

description = 'Submit to Biosample using USI'
ignore_result = False
name = 'Submit to Biosample'
priority = None
rate_limit = None
reject_on_worker_lost = None
request_stack = <celery.utils.threads._LocalStack object>
run(usi_submission_id)[source]

Run task. Instantiate a SubmissionHelper with the provided biosample.models.Submission id. Read token from database, start or recover a submission, add samples to it and then mark a status for it

serializer = 'json'
store_errors_even_if_ignored = False
track_started = False
typing = True

biosample.views

biosample.views module contents

class biosample.views.AccountMixin[source]

Bases: object

A generic mixin associated with biosample.models. You need to costomize account_found and account_not_found in to do a custom redirect in case a manager account is found or not

account_found(request, *args, **kwargs)[source]
account_not_found(request, *args, **kwargs)[source]
dispatch(request, *args, **kwargs)[source]
class biosample.views.CreateUserView(**kwargs)[source]

Bases: django.contrib.auth.mixins.LoginRequiredMixin, biosample.views.RegisterMixin, biosample.views.MyFormMixin, django.views.generic.edit.FormView

Create a new AAP account

add_biosample_user_to_team(form, user_id, team, managed_team)[source]
create_biosample_team(full_name, affiliation)[source]

Create a biosample team

Parameters
  • full_name (str) – the user full name (Name + Surname)

  • affiliation (str) – the organization the user belongs to

Returns

a pyUSIrest Team instance biosample.models.ManagedTeam: a model object

Return type

pyUSIrest.usi.Team

create_biosample_user(form, full_name, affiliation)[source]

Create a biosample user

Parameters
  • form (CreateUserForm) –

  • full_name (str) – the user full name (Name + Surname)

  • affiliation (str) – the organization the user belongs to

Returns

a biosamples user id

Return type

str

deal_with_errors(error_message, exception)[source]

Add messages to view for encountered errors

Parameters
  • error_message (str) – An informative text

  • exception (Exception) – an exception instance

form_class

alias of biosample.forms.CreateUserForm

form_valid(form)[source]

Create a new team in with biosample manager user, then create a new user and register it

get_form_kwargs()[source]

Override get_form_kwargs

success_url_message = 'AAP Account created'
template_name = 'biosample/create_user.html'
class biosample.views.GenerateTokenView(**kwargs)[source]

Bases: django.contrib.auth.mixins.LoginRequiredMixin, biosample.views.TokenMixin, biosample.views.MyFormMixin, django.views.generic.edit.FormView

Generate AAP token. If user is not registered, redirect to accounts registration_activation_complete through TokenMixin. If yes generate token through MyFormMixin

dispatch(request, *args, **kwargs)[source]
form_class

alias of biosample.forms.GenerateTokenForm

form_valid(form)[source]

If the form is valid, redirect to the supplied URL.

success_url_message = 'Token generated!'
template_name = 'biosample/generate_token.html'
class biosample.views.MyFormMixin[source]

Bases: object

Common stuff for token generation

form_invalid(form)[source]
generate_token(form)[source]

Generate token from form instance

get_form_kwargs()[source]
get_success_url()[source]

Override default function

success_url
success_url_message = 'Please set this variable'
class biosample.views.RegisterMixin[source]

Bases: biosample.views.AccountMixin

If a biosample account is already registered, returns to dashboard

account_found(request, *args, **kwargs)[source]

If a user has been registered, redirect to dashboard

class biosample.views.RegisterUserView(**kwargs)[source]

Bases: django.contrib.auth.mixins.LoginRequiredMixin, biosample.views.RegisterMixin, biosample.views.MyFormMixin, django.views.generic.edit.CreateView

Register an already existent AAP account

form_class

alias of biosample.forms.RegisterUserForm

form_valid(form)[source]

If the form is valid, save the associated model.

success_url_message = 'Account registered'
template_name = 'biosample/register_user.html'
class biosample.views.SubmitView(**kwargs)[source]

Bases: django.contrib.auth.mixins.LoginRequiredMixin, biosample.views.TokenMixin, biosample.views.MyFormMixin, django.views.generic.edit.FormView

Call a submission task. Check that a token exists and that it’s valid

form_class

alias of biosample.forms.SubmitForm

form_valid(form)[source]

If the form is valid, redirect to the supplied URL.

get_success_url()[source]

Override default function

start_submission(auth, submission)[source]

Change submission status and submit data with a valid token

submission_id = None
template_name = 'biosample/submit.html'
class biosample.views.TokenMixin[source]

Bases: biosample.views.AccountMixin

Get common stuff for Token visualization. Redirect to AAP registration if no valid AAP credentials are found for request.user

account_not_found(request, *args, **kwargs)[source]

If a user has not an account, redirect to activation complete

get_initial()[source]

Returns the initial data to use for forms on this view.

class biosample.views.TokenView(**kwargs)[source]

Bases: django.contrib.auth.mixins.LoginRequiredMixin, biosample.views.TokenMixin, django.views.generic.base.TemplateView

Visualize token details

get_context_data(**kwargs)[source]
template_name = 'biosample/token.html'