scidatacontainer_db API
Models
- class scidatacontainer_db.models.DataSet(*args, **kwargs)
Bases:
DataSetBaseRepresentation of a ZDC dataset after parsing.
- Parameters:
id (UUIDField) – UUID primary key
_replaced_by_field_id (OneToOneField) – Other instance that replaces this instance. Don’t use this field but the getter and setter functions
datasetbase_ptr_id (OneToOneField) – Datasetbase ptr
owner_id (ForeignKey) – Owner of the dataset
upload_time (DateTimeField) – Datetime of server uplaod
complete (BooleanField) – Complete flag to ensure overwrite protection
valid (BooleanField) – Valid flag to mark erroneous datasets
invalidation_comment (TextField) – Comment to describe why this dataset is invalid
size (IntegerField) – Size of the dataset in bytes
server_path (CharField) – File path to find the file on the server
created (DateTimeField) – Creation timestamp of the container
storage_time (DateTimeField) – Timestamp of storage of the container
static (BooleanField) – Flag for static containers
container_type_id (ForeignKey) – ContainerType of this dataset
hash (CharField) – Hash of the container
model_version (CharField) – Version of the data model
author (CharField) – Author
email (EmailField) – Email
organization (CharField) – Affiliation of the author
comment (TextField) – Comment
title (CharField) – Title
description (TextField) – Description
timestamp (DateTimeField) – Timestamp
doi (CharField) – Doi
license (TextField) – Name or text of the license
- exception DoesNotExist
Bases:
DoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- get_read_perm_group_list()
Get a list of groups that have read only permission for this object.
- get_read_perm_user_list()
Get a list of users that have read only permission for this object.
- get_write_perm_group_list()
Get a list of groups that have read and write permission for this object.
- get_write_perm_user_list()
Get a list of users that have read and write permission for this object.
- update_attributes(d, user)
Update a :model:`scidatacontainer_db.DataSet` instance with the information in the dictionary d. It first ensures that the user is the owner of the DataSet.
- class scidatacontainer_db.models.DataSetBase(*args, **kwargs)
Bases:
ModelBase Model of a :model:`scidatacontainer_db.DataSet`. It is required for DataSets that are unknown to the server. For example if an unknown ID is found in the :model:`scidatacontainer_db.DataSetBase`.replaces attribute, an instance of DataSetBase is created. It can be later on replaced by uploading this dataset without breaking the relations imposed by replaced_by or replaces.
- Parameters:
id (UUIDField) – UUID primary key
_replaced_by_field_id (OneToOneField) – Other instance that replaces this instance. Don’t use this field but the getter and setter functions
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- property is_replaced: bool
Returna true if the model instance is replaced by another DataSet.
- property replaced_by
Other object that replaces this instance. This might be None.
- property replaces
Other object that is replaced by this instance. This might by None.
- class scidatacontainer_db.models.ContainerType(*args, **kwargs)
Bases:
ModelModel to represent the container type of a dataset.
- Parameters:
dbid (UUIDField) – UUID primary key
name (CharField) – Name of the container type
id (CharField) – Identifier of the container type
version (CharField) – Version of the container type
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- classmethod to_ContainerType(pt)
Convert a dictionary as found in a ZDC container into a :model:`scidatacontainer_db.ContainerType` instance.
- class scidatacontainer_db.models.File(*args, **kwargs)
Bases:
ModelModel to represent a File from the content of a dataset. If the file is a JSON file, the content will be saved, too.
- Parameters:
id (UUIDField) – UUID primary key
name (CharField) – File name inside the ZDC dataset
size (IntegerField) – File size in bytes
content (JSONField) – Dictionary containing the content of a JSON file
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- class scidatacontainer_db.models.Keyword(*args, **kwargs)
Bases:
ModelModel to represent a Keyword of a DataSet.
- Parameters:
id (UUIDField) – UUID primary key
name (CharField) – String representation of a keyword
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- class scidatacontainer_db.models.Software(*args, **kwargs)
Bases:
ModelModel to represent a Software package used in a dataset.
- Parameters:
dbid (UUIDField) – UUID primary_key
name (CharField) – Name of the Software package
version (CharField) – Version of the software package
id (CharField) – Identifier of the software package
id_type (CharField) – Type of the given identifier
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- classmethod to_Software(pt)
Convert a dictionary as found in a ZDC container into a :model:`scidatacontainer_db.Software` instance.
Views
- class scidatacontainer_db.views.IndexView(**kwargs)
Bases:
LoginRequiredMixin,ListViewDisplay a list of :model:`scidatacontainer_db.DataSet`
Template :template:`scidatacontainer_db/index.html`
- get_context_data(**kwargs)
Context Data function to enable pagination.
- get_queryset()
Get the list of :model:`scidatacontainer_db.DataSet` objects to display. It only provides :model:`scidatacontainer_db.DataSet` objects that the user is allowed to read and filters for the search query.
- class scidatacontainer_db.views.DetailView(**kwargs)
Bases:
LoginRequiredMixin,DetailViewDisplay the detailed information of a single :model:`scidatacontainer_db.DataSet`.
Template :template:`scidatacontainer_db/detail.html`
- get(request, pk)
Handle a GET request. If this :model:`scidatacontainer_db:DataSet` is marked invalid, a warning message will be shown. If it was replaced by a successor :model:`scidatacontainer_db.DataSet`, a warning message will be shown and the user is redirected to the successor.
- get_object()
Get a :model:`scidatacontainer_db.DataSet` instance and make sure the requesting user has read permissions.
- class scidatacontainer_db.views.UploadFileView(**kwargs)
Bases:
LoginRequiredMixin,ViewUpload a file and parse its content.
- class scidatacontainer_db.views.DownloadFileView(**kwargs)
Bases:
LoginRequiredMixin,DetailViewProvide a ::model::scidatacontainer_db.DataSet as a FileResponse.
- class scidatacontainer_db.views.UpdatePermissionsView(**kwargs)
Bases:
LoginRequiredMixin,UpdateViewDisplay a permission modification page and handle a POST request to change them.
Context
usersList of all available users.
groupsList of all available groups.
r_usersList of users with read-only permission.
w_usersList of users with read and write permission.
rw_usersList of users with read-only or read-and-write permission.
r_groupsList of groups with read-only permission.
w_groupsList of groups with read and write permission.
rw_groupsList of groups with read-only or read-and-write permission.
Template
:template:`scidatacontainer_db/update_permissions.html`
- get_context_data(**kwargs)
Prepare context data for the template.
- get_object()
Check permission while finding the :model:`scidatacontainer_db.DataSet`.
- post(request, pk)
Handle POST requests to update the permissions on an object.
- class scidatacontainer_db.views.InvalidationView(**kwargs)
Bases:
LoginRequiredMixin,SingleObjectMixin,ViewHandle the request from the invalidation modal.
It handles PATCH and POST requests. POST request require _method set to patch to enable PATCH requests even thought web browsers don’t support PATCH requests.
- patch(request, pk)
Handle a PATCH request.
If the user is the owner of a :model:`scidatacontainer_db.DataSet`, store the invalidation reason and unset the valid flag. Afterwards, redirect to the overview page.
- post(request, pk)
Handle a POST request. This is a forward to the patch method if _method is patch.
- class scidatacontainer_db.views.ApiKeyView(**kwargs)
Bases:
LoginRequiredMixin,ListViewView to list a users API keys. A post request can be used to generate a new API key.
Template
:template:`scidatacontainer_db/api_keys.html`
- get_context_data(**kwargs)
Context Data function to enable pagination.
- get_queryset()
Filter :model:`knox.AuthToken` instances to show only the ones from the requesting user.
- model
alias of
AuthToken
- post(request)
Handle a POST request for key generation or deletion.
- class scidatacontainer_db.views.LoginView(**kwargs)
Bases:
LoginViewDisplay a login page.
Template
- class scidatacontainer_db.views.LogoutView(**kwargs)
Bases:
LogoutViewLogout a user and redirect to index page.
REST API Views
- class scidatacontainer_db.api_views.DataSetViewSet(**kwargs)
Bases:
ReadOnlyModelViewSet,CreateModelMixin- get_queryset()
Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.
This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.
You may want to override this if you need to provide different querysets depending on the incoming request.
(Eg. return a list of items that is specific to the user)
- serializer_class
alias of
DataSetSerializer
- class scidatacontainer_db.api_views.DataSetViewSet(**kwargs)
Bases:
ReadOnlyModelViewSet,CreateModelMixin- get_queryset()
Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.
This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.
You may want to override this if you need to provide different querysets depending on the incoming request.
(Eg. return a list of items that is specific to the user)
- serializer_class
alias of
DataSetSerializer
- class scidatacontainer_db.api_views.ContainerTypeViewSet(**kwargs)
Bases:
PermissionFilteredReadOnlyViewSet- model
alias of
ContainerType
- serializer_class
alias of
ContainerTypeSerializer
- class scidatacontainer_db.api_views.FileViewSet(**kwargs)
Bases:
PermissionFilteredReadOnlyViewSet- serializer_class
alias of
FileSerializer
- class scidatacontainer_db.api_views.KeywordViewSet(**kwargs)
Bases:
PermissionFilteredReadOnlyViewSet- serializer_class
alias of
KeywordSerializer
- class scidatacontainer_db.api_views.SoftwareViewSet(**kwargs)
Bases:
PermissionFilteredReadOnlyViewSet- serializer_class
alias of
SoftwareSerializer
- class scidatacontainer_db.api_views.PermissionFilteredReadOnlyViewSet(**kwargs)
Bases:
ReadOnlyModelViewSet- get_queryset()
Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.
This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.
You may want to override this if you need to provide different querysets depending on the incoming request.
(Eg. return a list of items that is specific to the user)
Parsers
- class scidatacontainer_db.parsers.BaseParser
Bases:
ABCBase class for file format specific parsers. Parsers should inherit from this class because it ensures the validation of the meta data.
- class scidatacontainer_db.parsers.ZipContainerParser
Bases:
BaseParserParser implementing the file type specific routines for .ZIP based containers.
Utils
- class scidatacontainer_db.utils.ensure_read_permission(user: User, dataset)
Bases:
Checks if the user has read permission for a given DataSet. Raises a PermissionDenied Exception otherwise.
- Parameters:
user – User object of requesting user.
dataset – DataSet that the user wants to read.
- Raises:
django.core.exceptions.PermissionDenied – If the user doesn’t have
read permissions.
- class scidatacontainer_db.utils.ensure_owner(user: User, dataset)
Bases:
Checks if the user is the owner of a given DataSet. Raises a PermissionDenied Exception otherwise.
- Parameters:
user – User object of requesting user.
dataset – DataSet to check the ownership.
- Raises:
django.core.exceptions.PermissionDenied – If the user isn’t the
owner.
- class scidatacontainer_db.utils.APIResponse(data=None, status=None, template_name=None, headers=None, exception=False, content_type=None, reason=None)
Bases:
ResponseCustom Response derived from rest_framewort.response.Response to set the reason phrase on creation of the response.
- class scidatacontainer_db.utils.MetaDBError
Bases:
ExceptionExcetption raised by various function and caught by the request handling views. The status code and reason_phrase stored in the instances will be part of the response.