Common App¶
common.constants¶
Here are defined values used in other modules. Those values are
used in enum database fields, in particular with django menus in forms. A lot of
class defined here are derived from the enum.Enum class and common.constants.EnumMixin,
which let to get a enum number value from an Enum object, as described in chapter
6.4.8 of Two scoops of django:
from common.constants import STATUSES
WAITING = STATUSES.get_value("waiting")
WAITING in this example is the numerical representation of waiting status
in the The Unified Internal Database. Other values stored in this modules
are the API endpoints used for BioSamples submission, the different annotation
confidences used in the ontology tables or the fields that are listed within the
batch update views used for fix data in a submission.
Common statuses¶
Statuses are applied for a uid.models.Submission and
biosample.models.Submission and reflect what happened to submissions
and what is possible to do with submission. Here are the main statuses:
WAITING: means a processing phase where no user access is intended to data. While in this status data are checked, submitted or loaded and no update/deletion should occur in this stage. Model and views should have their methods to prevent user access during this phase.
LOADED: means that data were correctly loaded insided The Unified Internal Database. data could be modified but need to be validated before submission
ERROR: error is a status that should never be seen. It mean an issue in InjectTool itself or an error in data import. Entries in such status need to be verified
READY: this status means that the validation is successful, and data could be submitted to biosample.
NEED_REVISION: this status mean an issue in validation, or an error in biosample submission. Data need changes in order to be correctly subitted to biosample.
SUBMITTED: this status mean that data were submitted to biosample and the system is waiting for
USIresponse in order to collectbiosample_idsand complete the submission.COMPLETED: this status means that data were correctly submitted to biosample and that they received a
biosample_id. After such status, you need to refer tobiosample_idto update or change such data.
Status could change as described by this figure:
A subset of such statuses are applied also to uid.models.Animal
and uid.models.Sample objects (LOADED, READY, NEED_REVISION,
SUBMITTED, COMPLETED). Their meaning is the same of submission statuses.
Common confidences¶
This enum.Enum class models annotation confidence in dictionary tables
after annotation with zooma. Even if all annotation statuses are possible, there
are three mainly chosen statuses:
CURATED: means that this ontology term is annotated manually
GOOD and HIGH: those are annotation accuracies as provided by
zooma
common.constants module contents¶
Created on Mon Jun 11 16:05:18 2018
@author: Paolo Cozzi <cozzi@ibba.cnr.it>
common.fields¶
common.fields module contents¶
Created on Tue Oct 30 15:32:58 2018
@author: Paolo Cozzi <cozzi@ibba.cnr.it>
common.forms¶
common.forms module contents¶
Created on Tue Nov 20 16:56:36 2018
@author: Paolo Cozzi <cozzi@ibba.cnr.it>
common.helpers¶
common.helpers module contents¶
Created on Wed Mar 27 12:50:16 2019
@author: Paolo Cozzi <cozzi@ibba.cnr.it>
-
common.helpers.format_attribute(value, terms=None, library_uri='http://purl.obolibrary.org/obo', units=None)[source]¶ Format a generic attribute into biosample dictionary
-
common.helpers.image_timedelta(t1, t2)[source]¶ A function to deal with image time intervals. Returns a number and time unit
-
common.helpers.parse_image_timedelta(interval)[source]¶ A function to parse from a image_timdelta string
-
common.helpers.send_mail_to_admins(email_subject, email_message, default_from='example@mail.com', addresses=['bioinfo.ibba@gmail.com', 'paolo.cozzi@ibba.cnr.it'])[source]¶ Send a mail to all admins
common.storage¶
common.storage module contents¶
Created on Tue Oct 30 15:28:14 2018
@author: Paolo Cozzi <cozzi@ibba.cnr.it>
-
class
common.storage.ProtectedFileSystemStorage(*args, **kwargs)[source]¶ Bases:
django.core.files.storage.FileSystemStorage-
base_location¶
-
base_url¶
-
common.tasks¶
common.tasks module contents¶
Created on Tue Jan 15 16:42:24 2019
@author: Paolo Cozzi <cozzi@ibba.cnr.it>
-
class
common.tasks.BaseTask(*args, **kwargs)[source]¶ Bases:
celery.app.task.TaskBase class to celery tasks. Define logs for on_failure and debug_task
-
action= None¶
-
description= None¶
-
ignore_result= False¶
-
name= None¶
-
on_failure(exc, task_id, args, kwargs, einfo)[source]¶ Error handler.
This is run by the worker when the task fails.
- Parameters
- Returns
The return value of this handler is ignored.
- Return type
-
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¶
-
-
class
common.tasks.NotifyAdminTaskMixin[source]¶ Bases:
objectA mixin to send error message to admins
-
action= None¶
-
-
(task)
common.tasks.cleanupregistration()¶ Cleanup expired registration keys by using Django management command.
-
(task)
common.tasks.clearsessions()¶ Cleanup expired sessions by using Django management command.
-
class
common.tasks.exclusive_task(task_name, lock_id, blocking=False, block_expire=False)[source]¶ Bases:
objectA class decorator to execute an exclusive task by decorating celery.tasks.Task.run (run this task once, others task calls will return already running message without calling task or will wait until other tasks of this type are completed)
- Parameters
-
common.tasks.redis_lock(lock_id, blocking=False, expire=True)[source]¶ This function get a lock relying on a lock name and other status. You can describe more process using the same lock name and give exclusive access to one of them.
- Parameters
- Returns
True if lock acquired, False otherwise
- Return type
common.tests¶
common.tests module contents¶
Created on Wed Mar 27 14:40:44 2019
@author: Paolo Cozzi <cozzi@ibba.cnr.it>
Here I will set all the tests.mixins I want to export outside common.tests
-
class
common.tests.DataSourceMixinTestCase[source]¶ Bases:
objectPlace file in data source directory
-
base_dir= '/home/docs/checkouts/readthedocs.org/user_builds/image-injecttool/checkouts/stable/django-data/image/common/tests'¶
-
dst_path= None¶
-
submission_model= None¶
-
upload_method= None¶
-
uploaded_file= False¶
-
-
class
common.tests.FormMixinTestCase[source]¶ Bases:
common.tests.mixins.GeneralMixinTestCase-
form_class= None¶
-
-
class
common.tests.GeneralMixinTestCase[source]¶ Bases:
common.tests.mixins.LoginMixinTestCase,common.tests.mixins.StatusMixinTestCase,common.tests.mixins.MessageMixinTestCase
-
class
common.tests.InvalidFormMixinTestCase[source]¶ Bases:
common.tests.mixins.StatusMixinTestCase,common.tests.mixins.MessageMixinTestCase
common.views¶
common.views module contents¶
Created on Mon Oct 29 15:33:34 2018
@author: Paolo Cozzi <cozzi@ibba.cnr.it>
-
class
common.views.DeleteMaterialMixin[source]¶ Bases:
common.views.OwnerMixinA common DeleteMixin for Material classes (Sample/Animal)
-
class
common.views.DetailMaterialMixin[source]¶ Bases:
common.views.OwnerMixinA common DetailMixin for Material classes (Sample/Animal)
-
class
common.views.ListMaterialMixin[source]¶ Bases:
common.views.OwnerMixinA common ListMixin for Material classes (Sample/Animal)
-
class
common.views.OwnerMixin[source]¶ Bases:
django.contrib.auth.mixins.LoginRequiredMixin-
get_queryset()[source]¶ Filter base queryset relying on django authenticated sessions:
from common.views import OwnerMixin from django.views.generic import DetailView class MyDetailView(OwnerMixin, DetailView): def get_queryset(self): # call OwnerMixin and DetailView super methods qs = super(MyDetailView, self).get_queryset() # add custom filter to queryset # remeber to return the updated queryset to the caller return qs
-
-
class
common.views.UpdateMaterialMixin[source]¶ Bases:
common.views.OwnerMixinA common UpdateMixin for Material classes (Sample/Animal)
-
validationresult_class= None¶
-