Note

This is a public alpha release, and therefore features and functionality may change and the software and documentation may contain technical bugs or other issues. If you discover any issues please consider registering a GitHub issue.

datasources.models.datasource module

This module contains the Django models necessary to manage the set of data sources.

class datasources.models.datasource.DataSource(*args, **kwargs)[source]

Bases: provenance.models.ProvAbleModel, core.models.BaseAppDataModel

Manage access to a data source API.

Will provide functionality to:

  • Query data (with query params)
  • Query metadata (with query params)
  • Track provenance of the data source itself
  • Track provenance of data accesses
exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

api_key

If the data source API requires an API key use this one

auth_method

Which authentication method to use - defined in datasources.connectors.base.AuthMethod enum

connector_string

Get the string used to locate the resource associated with this data source.

e.g. URL, SQL table identifier, etc.

data_connector

Context manager to construct the data connector for this source.

When the context manager is closed, the number of requests to the external API will be added to the total.

Returns:Data connector instance
data_connector_class

Get the data connector class for this source.

Returns:Data connector class
delete(using=None, keep_parents=False)[source]

Soft delete this object.

encrypted_docs_url

Where to find information about how to use this encrypted data

external_requests

Number of requests sent to the external API since the last reset - reset at midnight by cron job

external_requests_total

Total number of requests sent to the external API

get_absolute_url()[source]

Return URL at which this object may be viewed.

Method must be implemented by inheriting classes.

get_auth_method_display(*, field=<django.db.models.fields.IntegerField: auth_method>)
get_public_permission_level_display(*, field=<django.db.models.fields.IntegerField: public_permission_level>)
has_edit_permission(user: profiles.User) → bool[source]

Does a given user have permission to edit this data source?

Parameters:user – User to check
Returns:User has permission to edit?
has_permission_level(user: profiles.User, level: datasources.models.datasource.UserPermissionLevels) → bool[source]

Does a user have a particular permission level on this data source?

Parameters:
  • user – User to check
  • level – Permission level to check for
Returns:

User has permission?

has_view_permission(user: profiles.User) → bool[source]

Does a user have permission to view this data source in the PEDASI UI?

Parameters:user – User to check
Returns:User has permission?
id

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

is_catalogue

Is this data source a data catalogue?

is_deleted

Has this object been soft deleted?

is_encrypted

Contains encrypted data?

licence

Which licence is this data published under

licence_id

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

metadata_items

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.

objects = <core.models.SoftDeletionManager object>
owner

User who has responsibility for this data source

owner_id

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

plugin_name

Name of plugin which allows interaction with this data source

prov_exempt

Is this data source exempt from PROV tracking - e.g. utility data sources - postcode lookup

public_permission_level

The level of access that users are assumed to have without gaining explicit permission

save(*args, **kwargs)[source]

Save the current instance. Override this in a subclass if you want to control the saving process.

The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.

search_representation

Provide a text representation of this data source to be entered into a search index.

Returns:Text representation of this data source
url

Address at which the API may be accessed

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.

users

Users - linked via a permission table - see UserPermissionLink

class datasources.models.datasource.Licence(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Model representing a licence under which a data source is published e.g. Open Government Licence.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

datasources

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.

get_absolute_url()[source]
id

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

name

Name of the licence - e.g. Open Government License

objects = <django.db.models.manager.Manager object>
owner

User who has responsibility for this licence

owner_id

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

short_name

Short text identifier - e.g. OGL

url

Address at which the licence text may be accessed

version

Licence version - e.g. v2.0

datasources.models.datasource.MAX_LENGTH_REASON = 511

Length of request reason field - must include brief description of project

class datasources.models.datasource.UserPermissionLevels[source]

Bases: enum.IntEnum

User permission levels on data sources.

DATA = 3

Permission to query data via API / UI

META = 2

Permission to query metadata via API / UI

NONE = 0

No permissions

PROV = 4

Permission to query PROV via API / UI

VIEW = 1

Permission to view in PEDASI UI

Bases: django.db.models.base.Model

Model to act as a many to many joining table to handle user permission levels for access to data sources.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

datasource

Data source on which the permissions are being granted

datasource_id

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

get_granted_display(*, field=<django.db.models.fields.IntegerField: granted>)
get_requested_display(*, field=<django.db.models.fields.IntegerField: requested>)
granted

Granted permission level

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>
push_granted

Have permission to push data?

push_requested

Also require permission to push data?

reason

Reason the permission was requested

requested

Requested permission level

user

User being managed

user_id

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