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.FormBased on django.contrib.ath.form
-
base_fields= {'password1': <django.forms.fields.CharField object>, 'password2': <django.forms.fields.CharField object>}¶
-
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
-
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.models¶
biosample.models module contents¶
-
class
biosample.models.Account(id, user, name, team)[source]¶ Bases:
django.db.models.base.Model-
exception
DoesNotExist¶
-
exception
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.parentis aForwardManyToOneDescriptorinstance.
-
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.placeis aForwardOneToOneDescriptorinstance.
-
user_id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
exception
-
class
biosample.models.BaseSubmission(*args, **kwargs)[source]¶ Bases:
django.db.models.base.Model-
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¶
-
exception
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.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
-
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.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
-
exception
-
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¶
-
exception
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.parentis aForwardManyToOneDescriptorinstance.
-
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.parentis aForwardManyToOneDescriptorinstance.
-
team_id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
exception
-
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¶
-
exception
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.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
-
exception
-
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¶
-
exception
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.childrenis aReverseManyToOneDescriptorinstance.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.parentis aForwardManyToOneDescriptorinstance.
-
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.
-
exception
-
class
biosample.models.SubmissionData(id, submission, content_type, object_id)[source]¶ Bases:
django.db.models.base.Model-
exception
DoesNotExist¶
-
exception
MultipleObjectsReturned¶
-
content_object¶ Provide a generic many-to-one relation through the
content_typeandobject_idfields.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.parentis aForwardManyToOneDescriptorinstance.
-
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.parentis aForwardManyToOneDescriptorinstance.
-
submission_id¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
exception
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.BaseTaskPerform 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.BaseTaskSearch 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.OrphanSamplerecord 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
- Returns
A BioSample dictionary object
- Return type
-
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
- Returns
json content of the page
- Return type
-
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.
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:
objectHelper class to deal with submission data
-
__init__(usi_submission, auth)[source]¶ Helper function to have info for a biosample.models.Submission
- Parameters
usi_submission (biosample.models.Submission) – a biosample model Submission instance
auth – a pyUSIrest.auth.Auth instance
-
-
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
SUBMITTEDSubmissionobjects). Iterate through submission to get USI info. CallsFetchStatusHelper
-
fetch_status()[source]¶ Fetch status from pending submissions. Called from
run(), handles exceptions from USI, select allSubmissionobjects withSUBMITTEDstatus from UID and callfetch_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.BaseTaskUpdate 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>¶
-
serializer= 'json'¶
-
store_errors_even_if_ignored= False¶
-
track_started= False¶
-
typing= True¶
-
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:
objecthelper class to split py:class`uid.models.Submission` data in bacthes limited in sizes
-
add_to_submission_data(model)[source]¶ Add a
uid.mixins.BioSampleMixinto abiosample.models.Submissionobject, or create a new one if there are more samples than required
-
create_submission()[source]¶ Create a new
biosample.models.Submissionobject and set sample counter to 0
-
model_in_submission(model)[source]¶ Check if
uid.mixins.BioSampleMixinis already in an opened submission
-
-
class
biosample.tasks.submission.SplitSubmissionTask(*args, **kwargs)[source]¶ Bases:
submissions.tasks.SubmissionTaskMixin,common.tasks.NotifyAdminTaskMixin,common.tasks.BaseTaskSplit 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
SplitSubmissionHelperto splituid.models.Submissiondata. CallSubmitTaskfor each batch of data and then callSubmissionCompleteTaskafter 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.BaseTaskUpdate 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.Submissionstatus
-
serializer= 'json'¶
-
store_errors_even_if_ignored= False¶
-
track_started= False¶
-
typing= True¶
-
update_message(uid_submission, submission_qs, status)[source]¶ Read
biosample.models.Submissionmessage and setuid.models.Submissionmessage
-
-
exception
biosample.tasks.submission.SubmissionError[source]¶ Bases:
ExceptionException call for Error with submissions
-
class
biosample.tasks.submission.SubmissionHelper(submission_id)[source]¶ Bases:
objectAn helper class for submission task, used to deal with pyUSIrest
-
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.Submissiona pyUSIrest submission object
-
mark_fail(message)[source]¶ Set a
ERRORstatus forbiosample.models.Submissionand a message
-
mark_success(message='Waiting for biosample validation')[source]¶ Set a
SUBMITTEDbiosample.models.Submissionand a message
-
property
owner¶ Recover owner from a submission object related with a UID Submission
- Returns
a django
django.contrib.auth.models.Userobject- 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
-
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
-
-
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.Submissionid. 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:
objectA 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
-
class
biosample.views.CreateUserView(**kwargs)[source]¶ Bases:
django.contrib.auth.mixins.LoginRequiredMixin,biosample.views.RegisterMixin,biosample.views.MyFormMixin,django.views.generic.edit.FormViewCreate a new AAP account
-
create_biosample_team(full_name, affiliation)[source]¶ Create a biosample team
- Parameters
- Returns
a pyUSIrest Team instance
biosample.models.ManagedTeam: a model object- Return type
-
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
-
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.FormViewGenerate AAP token. If user is not registered, redirect to accounts registration_activation_complete through TokenMixin. If yes generate token through MyFormMixin
-
form_class¶ alias of
biosample.forms.GenerateTokenForm
-
success_url_message= 'Token generated!'¶
-
template_name= 'biosample/generate_token.html'¶
-
-
class
biosample.views.MyFormMixin[source]¶ Bases:
objectCommon stuff for token generation
-
success_url¶
-
success_url_message= 'Please set this variable'¶
-
-
class
biosample.views.RegisterMixin[source]¶ Bases:
biosample.views.AccountMixinIf a biosample account is already registered, returns to dashboard
-
class
biosample.views.RegisterUserView(**kwargs)[source]¶ Bases:
django.contrib.auth.mixins.LoginRequiredMixin,biosample.views.RegisterMixin,biosample.views.MyFormMixin,django.views.generic.edit.CreateViewRegister an already existent AAP account
-
form_class¶ alias of
biosample.forms.RegisterUserForm
-
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.FormViewCall a submission task. Check that a token exists and that it’s valid
-
form_class¶ alias of
biosample.forms.SubmitForm
-
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.AccountMixinGet common stuff for Token visualization. Redirect to AAP registration if no valid AAP credentials are found for request.user
-
class
biosample.views.TokenView(**kwargs)[source]¶ Bases:
django.contrib.auth.mixins.LoginRequiredMixin,biosample.views.TokenMixin,django.views.generic.base.TemplateViewVisualize token details
-
template_name= 'biosample/token.html'¶
-