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.forms module

Forms for usage in core HELIPORT views.

class heliport.data_source.forms.DataSourceForm(*args, context: Context, instance: DataSource | None = None, **kwargs)

Bases: ModelForm

Form for creating and updating data sources.

class Media

Bases: object

Specify javascript that is required by the form.

js = ['core/js/row_show.js']
class Meta

Bases: object

Form config.

fields = ['label', 'description', 'uri', 'login']
model

alias of DataSource

alpine_data = "{protocol: '', path: '', url: ''}"
base_fields = {'description': <django.forms.fields.CharField object>, 'label': <django.forms.fields.CharField object>, 'link': <django.forms.fields.CharField object>, 'login': <django.forms.models.ModelChoiceField object>, 'path': <django.forms.fields.CharField object>, 'protocol': <django.forms.fields.ChoiceField object>, 'server_address': <django.forms.fields.CharField object>, 'ssh_login': <django.forms.models.ModelChoiceField object>, 'uri': <django.forms.fields.CharField object>}
clean_path()

Validate path.

clean_server_address()

Validate server_address.

clean_ssh_login()

Validate ssh_login.

clean_uri()

Validate uri.

declared_fields = {'description': <django.forms.fields.CharField object>, 'label': <django.forms.fields.CharField object>, 'link': <django.forms.fields.CharField object>, 'login': <django.forms.models.ModelChoiceField object>, 'path': <django.forms.fields.CharField object>, 'protocol': <django.forms.fields.ChoiceField object>, 'server_address': <django.forms.fields.CharField object>, 'ssh_login': <django.forms.models.ModelChoiceField object>, 'uri': <django.forms.fields.CharField object>}
property media
save(commit=True)

Save the data source setting the relevant properties.

template_name = 'core/base/form.html'

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: DigitalObjectModule

get_url(project)

Return the URL for the entry point of this module.

is_configured(project)

Check whether there are any kinds of data sources in the project.

module_id = 'data_source'
name = 'Data Sources'
property object_class

DataSource.

heliport.data_source.interface.get_search_url()

Return the search URL for this app.

This URL is used to implement the global HELIPORT string search.

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']
access(context: Context)

Get permission checker for this object and context.

See heliport.core.models.DigitalObject.access() for base implementation.

There is also a check that only gives write permission if the current user owns the login.

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
property server_address

The server address part of the path.

This is always the first part of the path before the first “/”.

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', 'namespace_str']
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.DataSourceView(*args, **kwargs)

Bases: HeliportCreateAndUpdateView

View To list and edit data sources including those from other apps.

get_context_data(**kwargs)

Get extra rendering context.

list_url: str = 'data_source:list'

This is required by the default implementation of get_response() to redirect back to the list after successful operation. See also HeliportObjectListView.list_url for a similar concept.

post(request, *args, **kwargs)

Handle deletion, creation and updating using the appropriate form.

template_name = 'data_source/data_source.html'
update_url: str = 'data_source:update'

This is required by the default implementation of get_response() to redirect back to the list after unsuccessful operation. See also HeliportObjectListView.update_url for a similar concept.

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)
heliport.data_source.views.data_source_classes() dict[Type[DigitalObject], DigitalObjectModule]

Get all data source classes in HELIPORT.

The result is a dict mapping the classes to a module that manges them.

heliport.data_source.views.data_source_forms() dict[str, Type[BaseForm]]

Get form classes for data sources.

The result is a dict mapping module_id to form class. Only modules that have a form class are included.

heliport.data_source.views.data_source_modules() dict[str, DigitalObjectModule]

Get all HELIPORT modules that represent a file or directory.

The result is a dict mapping module_id to module instance.

heliport.data_source.views.form_module_for(data_source: DigitalObject)

Get module that can handle data_source and that has a form class.

Return None if no such module is found.

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()).