heliport.data_source package

Subpackages

Submodules

heliport.data_source.admin module

Registers Django admin pages.

See django.contrib.admin.ModelAdmin from Django documentation.

heliport.data_source.apps module

Django app configuration.

Some HELIPORT hooks can be registered in app config django.apps.AppConfig.ready().

See also Django documentation

class heliport.data_source.apps.DataSourceConfig(app_name, app_module)

Bases: AppConfig

App configuration for data source app.

name = 'heliport.data_source'
ready()

Register object types.

heliport.data_source.interface module

Module with special name “interface” hooks into HELIPORT.

Some functions and heliport.core.app_interaction.Module subclasses are detected by HELIPORT and control how HELIPORT uses this app.

Note that this module must be imported in __init__.py of the django app.

class heliport.data_source.interface.DataSourceModule

Bases: Module

get_url(project)
is_configured(project)
module_id = 'data_source'
name = 'Data Source'
heliport.data_source.interface.get_search_url()
heliport.data_source.interface.serialize_project(project)

heliport.data_source.models module

Contains django.db.models.Model classes for Django ORM.

See Quick example from Django documentation. In HELIPORT the heliport.core.models.DigitalObject can be subclassed for models containing metadata in a project.

class heliport.data_source.models.DataSource(digital_object_id, persistent_id, generated_persistent_id, category, label, label_is_public, description, description_is_public, created, last_modified, last_modified_is_public, deleted, permission, special_heliport_role, is_helper, projects_is_public, owner, members_is_public, digitalobject_ptr, data_source_id, uri, login, generated_inside)

Bases: DigitalObject

exception DoesNotExist

Bases: DoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

PROTOCOL_CHOICES = ['https', 'http', 'ftp', 'ftps', 'file', 'ssh', 'other']
property browser_supported_uri
data_source_id

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

datasource_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.

digitalobject_ptr

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.

digitalobject_ptr_id
generated_inside

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.

generated_inside_id
login

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.

login_id
property path
property protocol
property protocol_path
sub_path(relative_path_str=None)

This function is deprecated as it is specific to ssh directories. The new place is heliport.ssh.SSHDirectory.sub_path().

uri

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

heliport.data_source.serializers module

This module is for serialization into Datacite, RDF and JSON.

The JSON format is used for API endpoints via Django rest framework. Using this, it is typical to put the serializer classes into a “serializers.py” file.

For the serialization into RDF, attributes are described. See heliport.core.attribute_description.BaseAttribute for more detail.

class heliport.data_source.serializers.DataSourceSerializer(*args, **kwargs)

Bases: ModelSerializer

class Meta

Bases: object

fields = ['data_source_id', 'uri', 'description', 'label', 'login', 'projects', 'persistent_id']
model

alias of DataSource

heliport.data_source.tests module

Test the behaviour of this app.

This follows the Writing tests guide in Django.

class heliport.data_source.tests.DataSourceEditTest(methodName='runTest')

Bases: TestCase

Test editing of data sources.

setUp()

Set up project, instances and logged-in heliport users.

test_add_login()

Can add login to an “unowned” data source.

test_foreign_datasource()

Forbid editing someone else’s data source.

test_other_login()

Can’t set data source login to someone else’s login.

test_own_datasource()

Allow editing own data source.

heliport.data_source.urls module

Map django views to urls.

See this Example including explanation from the Django documentation.

heliport.data_source.views module

Contains Django View classes to handle HTTP requests.

See Using class-based views from Django documentation. In HELIPORT heliport.core.mixins are used to create uniform views. Also heliport.core.views.generic.HeliportObjectListView is used to quicly create a typical HELIPORT list view.

class heliport.data_source.views.DataSourceUpdateView(**kwargs)

Bases: HeliportObjectMixin, UpdateView

dispatch(request: HttpRequest, *args: Any, **kwargs: Any) HttpResponse

Don’t allow users to edit a data source that has someone else’s LoginInfo.

This forbids both GET and POST.

fields = ['uri', 'description', 'label', 'login']
form_valid(form)
get_context_data(**kwargs)

Add extra context for rendering template (Called by django base view).

The extra context includes the data sources to show as dicts with extra infos

get_form(*args, **kwargs) BaseModelForm

Add queryset for selectable logins.

get_success_url()
model

alias of DataSource

template_name = 'data_source/data_source.html'
class heliport.data_source.views.DataSourceView(**kwargs)

Bases: HeliportProjectMixin, CreateView

fields = ['uri', 'description', 'label', 'login']
form_valid(form)
get_context_data(**kwargs)

Add extra context for rendering template (Called by django base view).

The extra context includes the data sources to show as dicts with extra infos.

get_form(*args, **kwargs) BaseModelForm
get_success_url()
model

alias of DataSource

post(request, *args, **kwargs)
template_name = 'data_source/data_source.html'
class heliport.data_source.views.DataSourceViewSet(**kwargs)

Bases: HeliportModelViewSet

Data Source.

filterset_fields = ['data_source_id', 'label', 'uri', 'persistent_id', 'projects']
get_queryset()
serializer_class

alias of DataSourceSerializer

class heliport.data_source.views.DownloadFile(obj: ObjType = None, project: Project = None, user: HeliportUser = None)

Bases: OpenAction

Action that downloads some FileObj (see base class).

property applicable: bool

this action is applicable for heliport.core.digital_object_aspects.FileObj instances.

icon = 'fa-file'

The font awesome icon possibly used for this action

name = 'Download'

The name shown to user

class heliport.data_source.views.GeneralDataSourceOpenView(**kwargs)

Bases: HeliportProjectMixin, DetailView

Can handle all heliport.core.digital_object_aspects.DirectoryObj and heliport.core.digital_object_aspects.FileObj instances. They could be subclasses of heliport.core.models.DigitalObject or just generally heliport.core.digital_object_resolution.Resolvable.

Files are presented for download and content directories is visualized.

extend_by_file_info(path_obj, context, start_time)

Set info attribute on path_obj to dict returned by heliport.core.digital_object_aspects.FileOrDirectory.get_file_info().

Does nothing if current time is already more than three seconds after start_time because some get_file_info implementations might be slow.

get(request, *args, **kwargs)

Respond to http get (this is called by django).

get_digital_object(context)

Get a heliport.core.digital_object_interface.GeneralDigitalObject instance from the provided URL query parameters using typical resolution.

get_directory_response(obj: DirectoryObj, exit_context: Context)

Construct context and render template to show content of directory.

get_file_response(file_obj: FileObj, context)

Construct a streaming response for downloading the file.

model

alias of Project

pk_url_kwarg = 'project'
class heliport.data_source.views.OpenAction(obj: ObjType = None, project: Project = None, user: HeliportUser = None)

Bases: Action, ABC

Base class for Action that opens digital objects using GeneralDataSourceOpenView.

applicable() bool

Check applicability by testing if link() is successful on this instance.

This should be overwritten in subclasses to be more specific.

construct a link to GeneralDataSourceOpenView specific to current project and digital object.

class heliport.data_source.views.OpenDirectory(obj: ObjType = None, project: Project = None, user: HeliportUser = None)

Bases: OpenAction

Action that opens some DirectoryObj by showing a preview (see base class).

property applicable: bool

this action is applicable for heliport.core.digital_object_aspects.DirectoryObj instances.

icon = 'fa-folder-open'

The font awesome icon possibly shown to user

name = 'Open'

The name shown to user

class heliport.data_source.views.SSHDataSourceOpenView(**kwargs)

Bases: HeliportObjectMixin, DetailView

This is the legacy way of showing a directory or downloading a file that is a data source with ssh protocol. The new way is to register the ssh files/directories in heliport.ssh.views.SSHListView and open it using GeneralDataSourceOpenView.

static format_size(size)

Format file size in bytes to human-readable units.

static format_time(mtime)

Formats absolute time in seconds to human-readable string.

get(request, *args, **kwargs)

Respond to GET request.

Check if data source is file directory or directory. Download Files using a streaming response (ssh connection is closed when django closes file). Show directory using template.

model

alias of DataSource

class heliport.data_source.views.SearchView(**kwargs)

Bases: HeliportLoginRequiredMixin, TemplateView

get_context_data(**kwargs)

Add extra context for rendering template (Called by django base view).

The extra context includes the search results.

template_name = 'data_source/search.html'
class heliport.data_source.views.SubDataSourceCreateView(**kwargs)

Bases: HeliportObjectMixin, DetailView

model

alias of DataSource

post(request, *args, **kwargs)
heliport.data_source.views.data_source_by_path(project, path, parent_data_source)

Module contents

App to store metadata about general data used in the HELIPORT project.

The interface module is imported to the top level of the package for HELIPORT app interface discovery (see heliport.core.app_interaction.get_heliport_apps()).