Client
TeSLA CE CLient package
client
TeSLA CE CLient Module
Client
TeSLA CE Client class
config
property
readonly
Get current module configuration
Returns:
| Type | Description |
|---|---|
dict |
Module configuration |
module
property
readonly
Get current module information
Returns:
| Type | Description |
|---|---|
dict |
Module information |
provider
property
readonly
Access to the Provider related methods
Returns:
| Type | Description |
|---|---|
ProviderClient |
Provider controller object |
v1
property
readonly
Access to the old API v1 methods
Returns:
| Type | Description |
|---|---|
ClientV1 |
Old API v1 controller object |
vle
property
readonly
Access to the VLE related methods
Returns:
| Type | Description |
|---|---|
VleClient |
VLE controller object |
get_next(self, list)
Get the next group of results from a list
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
list |
dict |
List of results |
required |
Returns:
| Type | Description |
|---|---|
dict |
Next group of results |
Source code in tesla_ce_client/client.py
def get_next(self, list):
"""
Get the next group of results from a list
:param list: List of results
:type list: dict
:return: Next group of results
:rtype: dict
"""
if 'next' in list and list['next'] is not None:
return self._connector.get(list['next'])
return None
get_previous(self, list)
Get the previous group of results from a list
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
list |
dict |
List of results |
required |
Returns:
| Type | Description |
|---|---|
dict |
Previous group of results |
Source code in tesla_ce_client/client.py
def get_previous(self, list):
"""
Get the previous group of results from a list
:param list: List of results
:type list: dict
:return: Previous group of results
:rtype: dict
"""
if 'previous' in list and list['previous'] is not None:
return self._connector.get(list['previous'])
return None
connector
Connector
Connector class to manage connections with the APIs
config
property
readonly
Access to module configuration
Returns:
| Type | Description |
|---|---|
dict |
Module configuration |
module
property
readonly
Access to module data
Returns:
| Type | Description |
|---|---|
dict |
Module configuration |
__init__(self, api_url, role_id, secret_id, verify_ssl=True)
special
Default constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_url |
str |
TeSLA API URL |
required |
role_id |
str |
RoleId to authenticate with Vault |
required |
secret_id |
str |
SecretId to authenticate with Vault |
required |
verify_ssl |
bool |
Whether to verify certificate of the server |
True |
Source code in tesla_ce_client/connector.py
def __init__(self, api_url, role_id, secret_id, verify_ssl=True):
"""
Default constructor.
:param api_url: TeSLA API URL
:type api_url: str
:param role_id: RoleId to authenticate with Vault
:type role_id: str
:param secret_id: SecretId to authenticate with Vault
:type secret_id: str
:param verify_ssl: Whether to verify certificate of the server
:type verify_ssl: bool
"""
if api_url is None:
raise TeslaConfigException('Missing API URL')
if role_id is None or secret_id is None:
raise TeslaConfigException('Missing credentials')
# Store initial configuration
self._api_url = api_url
self._role_id = role_id
self._secret_id = secret_id
self._verify_ssl = verify_ssl
# Check API_URL
if self._api_url.endswith('/'):
self._api_url = self._api_url[:-1]
# Authenticate with the API
self._authenticate()
delete(self, url)
Execute a DELETE HTTP request
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url |
str |
Url to send the request |
required |
Returns:
| Type | Description |
|---|---|
dict |
The response to the request |
Source code in tesla_ce_client/connector.py
def delete(self, url):
"""
Execute a DELETE HTTP request
:param url: Url to send the request
:type url: str
:return: The response to the request
:rtype: dict
"""
return self.executor('delete', url=url)
executor(self, method, url, body=None)
Execute an HTTP request
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method |
str |
Method to be used (get, post, put, delete, patch) |
required |
url |
str |
Url to send the request |
required |
body |
dict |
Data to include in the request |
None |
Returns:
| Type | Description |
|---|---|
dict |
The response to the request |
Source code in tesla_ce_client/connector.py
def executor(self, method, url, body=None):
"""
Execute an HTTP request
:param method: Method to be used (get, post, put, delete, patch)
:type method: str
:param url: Url to send the request
:type url: str
:param body: Data to include in the request
:type body: dict
:return: The response to the request
:rtype: dict
"""
# Build the request url
if url.startswith(self._api_url):
# Absolute url
request_url = url
else:
# Relative url
if url.startswith('/'):
request_url = '{}{}'.format(self._api_url, url)
else:
request_url = '{}/{}'.format(self._api_url, url)
request_url = request_url.replace('//', '/')
request_url = request_url.replace(':/', '://')
# Call the method
headers = {'Authorization': 'JWT {}'.format(self._get_token())}
resp = requests.request(method=method, url=request_url, json=body, headers=headers, verify=self._verify_ssl)
# Take actions with the response
self._check_response_status(resp.status_code, resp.content)
# Consider the no content response
if resp.status_code == 204:
return None
return resp.json()
get(self, url)
Execute a GET HTTP request
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url |
str |
Url to send the request |
required |
Returns:
| Type | Description |
|---|---|
dict |
The response to the request |
Source code in tesla_ce_client/connector.py
def get(self, url):
"""
Execute a GET HTTP request
:param url: Url to send the request
:type url: str
:return: The response to the request
:rtype: dict
"""
return self.executor('get', url=url)
get_provider_id(self)
Obtain the provider ID for current Provider
Returns:
| Type | Description |
|---|---|
int |
Provider ID if current module is a Provider, or None if provided credentials are not for a Provider |
Source code in tesla_ce_client/connector.py
def get_provider_id(self):
"""
Obtain the provider ID for current Provider
:return: Provider ID if current module is a Provider, or None if provided credentials are not for a Provider
:rtype: int
"""
if 'provider_id' in self._module:
return self._module['provider_id']
return None
get_vle_id(self)
Obtain the vle ID for current VLE
Returns:
| Type | Description |
|---|---|
int |
VLE ID if current module is a VLE, or None if provided credentials are not for a VLE |
Source code in tesla_ce_client/connector.py
def get_vle_id(self):
"""
Obtain the vle ID for current VLE
:return: VLE ID if current module is a VLE, or None if provided credentials are not for a VLE
:rtype: int
"""
if 'vle_id' in self._module:
return self._module['vle_id']
return None
patch(self, url, body=None)
Execute a PATCH HTTP request
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url |
str |
Url to send the request |
required |
body |
dict |
Data to include in the request |
None |
Returns:
| Type | Description |
|---|---|
dict |
The response to the request |
Source code in tesla_ce_client/connector.py
def patch(self, url, body=None):
"""
Execute a PATCH HTTP request
:param url: Url to send the request
:type url: str
:param body: Data to include in the request
:type body: dict
:return: The response to the request
:rtype: dict
"""
return self.executor('patch', url=url, body=body)
post(self, url, body=None)
Execute a POST HTTP request
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url |
str |
Url to send the request |
required |
body |
dict |
Data to include in the request |
None |
Returns:
| Type | Description |
|---|---|
dict |
The response to the request |
Source code in tesla_ce_client/connector.py
def post(self, url, body=None):
"""
Execute a POST HTTP request
:param url: Url to send the request
:type url: str
:param body: Data to include in the request
:type body: dict
:return: The response to the request
:rtype: dict
"""
return self.executor('post', url=url, body=body)
put(self, url, body=None)
Execute a PUT HTTP request
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url |
str |
Url to send the request |
required |
body |
dict |
Data to include in the request |
None |
Returns:
| Type | Description |
|---|---|
dict |
The response to the request |
Source code in tesla_ce_client/connector.py
def put(self, url, body=None):
"""
Execute a PUT HTTP request
:param url: Url to send the request
:type url: str
:param body: Data to include in the request
:type body: dict
:return: The response to the request
:rtype: dict
"""
return self.executor('put', url=url, body=body)
exception
Exception definition module
BadRequestException
Class raises when a bad request error is found accessing the API
InternalException
Class raises when an unexpected error is found accessing the API
LockedResourceException
Class raises when trying to access a locked resource
NotImplementedException
Class raises when a not implemented method is called
ObjectNotFoundException
Class raises when a requested object does not exist
TeslaAuthException
Class to raise authentication related exceptions
TeslaConfigException
Class to raise configuration exceptions
TeslaException
Base class to raise exceptions
TeslaNotFoundException
Class raises when object is not found
TeslaVaultException
Class to raise vault related exceptions
tesla_report_exception(exception=None)
Send given exception to the Sentry Error Tracking system
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exception |
|
Exception (optional) |
None |
Returns:
| Type | Description |
|---|---|
|
Issue id or None if tracking is not enabled |
Source code in tesla_ce_client/exception.py
def tesla_report_exception(exception=None):
"""
Send given exception to the Sentry Error Tracking system
:param exception: Exception (optional)
:return: Issue id or None if tracking is not enabled
"""
if os.getenv('SENTRY_ENABLED') in ['1', 1, 'True', 'yes', 'true'] and os.getenv('SENTRY_DSN') is not None:
return capture_exception(exception)
return None
provider
special
TeSLA CE VLE Course Activities cLient package
client
TeSLA CE VLE client module
ProviderClient
Provider client class
enrolment
property
readonly
Access to the Provider enrolment related methods
Returns:
| Type | Description |
|---|---|
Enrolment |
Enrolment controller object |
notification
property
readonly
Access to the Provider notification related methods
Returns:
| Type | Description |
|---|---|
Notification |
Notification controller object |
verification
property
readonly
Access to the Provider verification related methods
Returns:
| Type | Description |
|---|---|
Verification |
Verification controller object |
__init__(self, connector)
special
Default constructor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connector |
Union[Connect,] |
Connector object |
required |
Source code in tesla_ce_client/provider/client.py
def __init__(self, connector):
"""
Default constructor
:param connector: Connector object
:type connector: Connector
"""
# Connector object -> Connector
self._connector = connector
get(self, provider_id=None)
Get a VLE
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider_id |
int |
Identifier of the provider. If not provided take it from module configuration |
None |
Returns:
| Type | Description |
|---|---|
dict |
Provider object |
Source code in tesla_ce_client/provider/client.py
def get(self, provider_id=None):
"""
Get a VLE
:param provider_id: Identifier of the provider. If not provided take it from module configuration
:type provider_id: int
:return: Provider object
:rtype: dict
"""
if provider_id is None:
provider_id = self._connector.get_provider_id()
return self._connector.get('/api/v2/provider/{}/'.format(provider_id))
enrolment
TeSLA CE Enrolment Client module
Enrolment
Enrolment Client class
__init__(self, connector)
special
Default constructor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connector |
Union[Connect,] |
Connector object |
required |
Source code in tesla_ce_client/provider/enrolment.py
def __init__(self, connector):
"""
Default constructor
:param connector: Connector object
:type connector: Connector
"""
# Connector object -> Connector
self._connector = connector
get_available_samples(self, provider_id, learner_id)
Get the list of available validated enrolment samples that are not used in current model
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider_id |
int |
Provider ID |
required |
learner_id |
str |
The learner UUID |
required |
result |
dict |
Enrolment samples |
required |
Source code in tesla_ce_client/provider/enrolment.py
def get_available_samples(self, provider_id, learner_id):
"""
Get the list of available validated enrolment samples that are not used in current model
:param provider_id: Provider ID
:type provider_id: int
:param learner_id: The learner UUID
:type learner_id: str
:param result: Enrolment samples
:type result: dict
"""
return self._connector.get('/api/v2/provider/{}/enrolment/{}/available_samples/'.format(
provider_id, learner_id))
get_model(self, provider_id, learner_id)
Get learner model for a provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider_id |
int |
Provider ID |
required |
learner_id |
str |
The learner UUID |
required |
Returns:
| Type | Description |
|---|---|
dict |
Learner model |
Source code in tesla_ce_client/provider/enrolment.py
def get_model(self, provider_id, learner_id):
"""
Get learner model for a provider.
:param provider_id: Provider ID
:type provider_id: int
:param learner_id: The learner UUID
:type learner_id: str
:return: Learner model
:rtype: dict
"""
return self._connector.get('/api/v2/provider/{}/enrolment/{}/'.format(provider_id, learner_id))
get_model_lock(self, provider_id, learner_id, task_id)
Get learner model for a provider ready to be modified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider_id |
int |
Provider ID |
required |
learner_id |
str |
The learner UUID |
required |
task_id |
str |
Task UUID value. It will allow to update the model. |
required |
Returns:
| Type | Description |
|---|---|
dict |
Learner model |
Source code in tesla_ce_client/provider/enrolment.py
def get_model_lock(self, provider_id, learner_id, task_id):
"""
Get learner model for a provider ready to be modified.
:param provider_id: Provider ID
:type provider_id: int
:param learner_id: The learner UUID
:type learner_id: str
:param task_id: Task UUID value. It will allow to update the model.
:type task_id: str
:return: Learner model
:rtype: dict
"""
try:
return self._connector.post('/api/v2/provider/{}/enrolment/'.format(provider_id),
body={
'learner_id': learner_id,
'task_id': task_id
})
except exception.BadRequestException as exc:
if 'Model is locked' in exc.value:
raise exception.LockedResourceException("Model is locked")
get_model_samples(self, provider_id, learner_id)
Get the list of enrolment samples used in current model
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider_id |
int |
Provider ID |
required |
learner_id |
str |
The learner UUID |
required |
result |
dict |
Enrolment samples |
required |
Source code in tesla_ce_client/provider/enrolment.py
def get_model_samples(self, provider_id, learner_id):
"""
Get the list of enrolment samples used in current model
:param provider_id: Provider ID
:type provider_id: int
:param learner_id: The learner UUID
:type learner_id: str
:param result: Enrolment samples
:type result: dict
"""
return self._connector.get('/api/v2/provider/{}/enrolment/{}/used_samples/'.format(
provider_id, learner_id))
get_sample(self, provider_id, learner_id, sample_id)
Get enrolment sample
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider_id |
int |
Provider ID |
required |
learner_id |
str |
The learner UUID |
required |
sample_id |
int |
Sample id |
required |
Returns:
| Type | Description |
|---|---|
dict |
Enrolment sample |
Source code in tesla_ce_client/provider/enrolment.py
def get_sample(self, provider_id, learner_id, sample_id):
"""
Get enrolment sample
:param provider_id: Provider ID
:type provider_id: int
:param learner_id: The learner UUID
:type learner_id: str
:param sample_id: Sample id
:type sample_id: int
:return: Enrolment sample
:rtype: dict
"""
return self._connector.get('/api/v2/provider/{}/enrolment/{}/sample/{}/'.format(provider_id,
learner_id,
sample_id))
get_sample_validation(self, provider_id, learner_id, sample_id, validation_id)
Get validation result for an enrolment sample
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider_id |
int |
Provider ID |
required |
learner_id |
str |
The learner UUID |
required |
sample_id |
int |
Sample id |
required |
validation_id |
int |
Sample validation id |
required |
result |
dict |
Validation result |
required |
Source code in tesla_ce_client/provider/enrolment.py
def get_sample_validation(self, provider_id, learner_id, sample_id, validation_id):
"""
Get validation result for an enrolment sample
:param provider_id: Provider ID
:type provider_id: int
:param learner_id: The learner UUID
:type learner_id: str
:param sample_id: Sample id
:type sample_id: int
:param validation_id: Sample validation id
:type validation_id: int
:param result: Validation result
:type result: dict
"""
return self._connector.get('/api/v2/provider/{}/enrolment/{}/sample/{}/validation/{}/'.format(
provider_id, learner_id, sample_id, validation_id))
get_sample_validation_list(self, provider_id, learner_id, sample_id)
Get validation result for an enrolment sample
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider_id |
int |
Provider ID |
required |
learner_id |
str |
The learner UUID |
required |
sample_id |
int |
Sample id |
required |
result |
dict |
Validation results |
required |
Source code in tesla_ce_client/provider/enrolment.py
def get_sample_validation_list(self, provider_id, learner_id, sample_id):
"""
Get validation result for an enrolment sample
:param provider_id: Provider ID
:type provider_id: int
:param learner_id: The learner UUID
:type learner_id: str
:param sample_id: Sample id
:type sample_id: int
:param result: Validation results
:type result: dict
"""
return self._connector.get('/api/v2/provider/{}/enrolment/{}/sample/{}/validation/'.format(
provider_id, learner_id, sample_id))
save_model(self, provider_id, learner_id, task_id, model)
Get learner model for a provider ready to be modified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider_id |
int |
Provider ID |
required |
learner_id |
str |
The learner UUID |
required |
task_id |
str |
Task UUID value. It will allow to update the model. |
required |
Returns:
| Type | Description |
|---|---|
dict |
Learner model |
Source code in tesla_ce_client/provider/enrolment.py
def save_model(self, provider_id, learner_id, task_id, model):
"""
Get learner model for a provider ready to be modified.
:param provider_id: Provider ID
:type provider_id: int
:param learner_id: The learner UUID
:type learner_id: str
:param task_id: Task UUID value. It will allow to update the model.
:type task_id: str
:return: Learner model
:rtype: dict
"""
try:
# Upload the new model to storage
if not self._connector._verify_ssl:
resp = requests.post(model['model_upload_url']['url'], data=model['model_upload_url']['fields'],
files={'file': io.StringIO(simplejson.dumps(model['model']))}, verify=False)
else:
resp = requests.post(model['model_upload_url']['url'], data=model['model_upload_url']['fields'],
files={'file': io.StringIO(simplejson.dumps(model['model']))})
# Check given response
self._connector._check_response_status(resp.status_code, resp.content)
return self._connector.put('/api/v2/provider/{}/enrolment/{}/'.format(provider_id, learner_id),
body={
'learner_id': learner_id,
'task_id': task_id,
'percentage': model['percentage'],
'can_analyse': model['can_analyse'],
'used_samples': model['used_samples']
})
except exception.BadRequestException as exc:
if 'Model is locked' in exc.value:
raise exception.LockedResourceException("Model is locked")
set_sample_status(self, provider_id, learner_id, sample_id, status)
Change sample status
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider_id |
int |
Provider ID |
required |
learner_id |
str |
The learner UUID |
required |
sample_id |
int |
Sample id |
required |
status |
SampleValidationStatus |
Sample's status. Valid status: 0 validating, 1 valid, 2 error, 3 timeout, 4 waiting external service |
required |
Returns:
| Type | Description |
|---|---|
|
Source code in tesla_ce_client/provider/enrolment.py
def set_sample_status(self, provider_id, learner_id, sample_id, status):
"""
Change sample status
:param provider_id: Provider ID
:type provider_id: int
:param learner_id: The learner UUID
:type learner_id: str
:param sample_id: Sample id
:type sample_id: int
:param status: Sample's status. Valid status: 0 validating, 1 valid, 2 error, 3 timeout, 4 waiting external
service
:type status: SampleValidationStatus
:return:
"""
raise exception.NotImplementedException()
'''
This should be the endpoint in the API, but now not exists
return self._connector.post('/api/v2/provider/{}/enrolment/{}/sample/{}/status/'.format(
provider_id, learner_id, sample_id), body={"status": status.value})
'''
set_sample_validation(self, provider_id, learner_id, sample_id, validation_id, result)
Store validation result for an enrolment sample
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider_id |
int |
Provider ID |
required |
learner_id |
str |
The learner UUID |
required |
sample_id |
int |
Sample id |
required |
validation_id |
int |
Sample Validation id |
required |
result |
dict |
Validation result |
required |
Source code in tesla_ce_client/provider/enrolment.py
def set_sample_validation(self, provider_id, learner_id, sample_id, validation_id, result):
"""
Store validation result for an enrolment sample
:param provider_id: Provider ID
:type provider_id: int
:param learner_id: The learner UUID
:type learner_id: str
:param sample_id: Sample id
:type sample_id: int
:param validation_id: Sample Validation id
:type validation_id: int
:param result: Validation result
:type result: dict
"""
return self._connector.put('/api/v2/provider/{}/enrolment/{}/sample/{}/validation/{}/'.format(
provider_id, learner_id, sample_id, validation_id), body=result)
set_sample_validation_status(self, provider_id, learner_id, sample_id, validation_id, status)
Change sample validation status
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider_id |
int |
Provider ID |
required |
learner_id |
str |
The learner UUID |
required |
sample_id |
int |
Sample id |
required |
validation_id |
int |
Validation id |
required |
status |
SampleValidationStatus |
Sample's status. Valid status: 0 validating, 1 valid, 2 error, 3 timeout, 4 waiting external service |
required |
Returns:
| Type | Description |
|---|---|
|
Source code in tesla_ce_client/provider/enrolment.py
def set_sample_validation_status(self, provider_id, learner_id, sample_id, validation_id, status):
"""
Change sample validation status
:param provider_id: Provider ID
:type provider_id: int
:param learner_id: The learner UUID
:type learner_id: str
:param sample_id: Sample id
:type sample_id: int
:param validation_id: Validation id
:type validation_id: int
:param status: Sample's status. Valid status: 0 validating, 1 valid, 2 error, 3 timeout, 4 waiting external
service
:type status: SampleValidationStatus
:return:
"""
return self._connector.post('/api/v2/provider/{}/enrolment/{}/sample/{}/validation/{}/status/'.format(
provider_id, learner_id, sample_id, validation_id), body={"status": status.value})
unlock_model(self, provider_id, learner_id, task_id)
Unlock the learner model for a provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider_id |
int |
Provider ID |
required |
learner_id |
str |
The learner UUID |
required |
task_id |
str |
Task UUID value. It will allow to update the model. |
required |
Source code in tesla_ce_client/provider/enrolment.py
def unlock_model(self, provider_id, learner_id, task_id):
"""
Unlock the learner model for a provider.
:param provider_id: Provider ID
:type provider_id: int
:param learner_id: The learner UUID
:type learner_id: str
:param task_id: Task UUID value. It will allow to update the model.
:type task_id: str
"""
self._connector.post('/api/v2/provider/{}/enrolment/{}/unlock/'.format(provider_id, learner_id),
body={
'token': task_id
})
SampleValidationStatus
SampleValidationStatus definition
notification
TeSLA CE Notifications Client module
Notification
Notifications Client class
__init__(self, connector)
special
Default constructor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connector |
Union[Connect,] |
Connector object |
required |
Source code in tesla_ce_client/provider/notification.py
def __init__(self, connector):
"""
Default constructor
:param connector: Connector object
:type connector: Connector
"""
self._connector = connector
delete(self, provider_id, notification_id)
Get a notification for a provider
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider_id |
int |
Identifier of the provider |
required |
notification_id |
int |
Id of the notification |
required |
Source code in tesla_ce_client/provider/notification.py
def delete(self, provider_id, notification_id):
"""
Get a notification for a provider
:param provider_id: Identifier of the provider
:type provider_id: int
:param notification_id: Id of the notification
:type notification_id: int
"""
self._connector.delete('/api/v2/provider/{}/notification/{}/'.format(provider_id, notification_id))
get(self, provider_id, notification_id)
Get a notification for a provider
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider_id |
int |
Identifier of the provider |
required |
notification_id |
int |
Id of the notification |
required |
Returns:
| Type | Description |
|---|---|
dict |
Notification object |
Source code in tesla_ce_client/provider/notification.py
def get(self, provider_id, notification_id):
"""
Get a notification for a provider
:param provider_id: Identifier of the provider
:type provider_id: int
:param notification_id: Id of the notification
:type notification_id: int
:return: Notification object
:rtype: dict
"""
return self._connector.get('/api/v2/provider/{}/notification/{}/'.format(provider_id, notification_id))
update_or_create(self, provider_id, key, when, info=None)
Updates or create a notification for a given provider
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider_id |
int |
Identifier of the provider |
required |
key |
str |
Key of the notification |
required |
Returns:
| Type | Description |
|---|---|
Notification |
Created or updated Notification |
Source code in tesla_ce_client/provider/notification.py
def update_or_create(self, provider_id, key, when, info=None):
"""
Updates or create a notification for a given provider
:param provider_id: Identifier of the provider
:type provider_id: int
:param key: Key of the notification
:type key: str
:return: Created or updated Notification
:rtype: Notification
"""
return self._connector.post('/api/v2/provider/{}/notification/'.format(provider_id),
body={
'key': key,
'when': when.isoformat(),
'info': info
})
verification
TeSLA CE Verification Client module
RequestResultStatus
RequestResultStatus definition
Verification
Verification Client class
__init__(self, connector)
special
Default constructor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connector |
Union[Connect,] |
Connector object |
required |
Source code in tesla_ce_client/provider/verification.py
def __init__(self, connector):
"""
Default constructor
:param connector: Connector object
:type connector: Connector
"""
# Connector object -> Connector
self._connector = connector
get_provider_request_result(self, provider_id, request_id)
Get verification request result for a provider
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider_id |
int |
Provider ID |
required |
request_id |
int |
Request result id |
required |
Returns:
| Type | Description |
|---|---|
dict |
Verification request result |
Source code in tesla_ce_client/provider/verification.py
def get_provider_request_result(self, provider_id, request_id):
"""
Get verification request result for a provider
:param provider_id: Provider ID
:type provider_id: int
:param request_id: Request result id
:type request_id: int
:return: Verification request result
:rtype: dict
"""
return self._connector.get('/api/v2/provider/{}/request/{}/'.format(provider_id, request_id))
set_provider_request_result(self, provider_id, request_id, result)
Store validation result for a verification request for a provider
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider_id |
int |
Provider ID |
required |
request_id |
int |
Request result id |
required |
result |
dict |
Verification result |
required |
Source code in tesla_ce_client/provider/verification.py
def set_provider_request_result(self, provider_id, request_id, result):
"""
Store validation result for a verification request for a provider
:param provider_id: Provider ID
:type provider_id: int
:param request_id: Request result id
:type request_id: int
:param result: Verification result
:type result: dict
"""
if 'audit' in result:
result['audit_data'] = result['audit']
del result['audit']
return self._connector.put('/api/v2/provider/{}/request/{}/'.format(provider_id, request_id), body=result)
set_provider_request_status(self, provider_id, request_id, status)
Change provider request status
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider_id |
int |
Provider ID |
required |
request_id |
int |
Request result id |
required |
status |
RequestResultStatus |
Request's status. Valid status: 1 ok, 2 error, 3 timeout, 6 processing, 7 waiting external service |
required |
Returns:
| Type | Description |
|---|---|
|
Source code in tesla_ce_client/provider/verification.py
def set_provider_request_status(self, provider_id, request_id, status):
"""
Change provider request status
:param provider_id: Provider ID
:type provider_id: int
:param request_id: Request result id
:type request_id: int
:param status: Request's status. Valid status: 1 ok, 2 error, 3 timeout, 6 processing, 7 waiting external
service
:type status: RequestResultStatus
:return:
"""
return self._connector.post('/api/v2/provider/{}/request/{}/status/'.format(provider_id, request_id),
body={"status": status.value})
v1
special
Client for API version 1
api
TeSLA API v1 Client
rt
TeSLA Reporting Tool API client
tep
TeSLA eAssessment Portal API client
tip
TeSLA Identity Provider API client
TipClient
getTeslaId(self, mail)
Get the learner ID from learner mail
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mail |
str |
A learner mail |
required |
Source code in tesla_ce_client/v1/tip.py
def getTeslaId(self, mail):
"""
Get the learner ID from learner mail
:param mail: A learner mail
:type mail: str
"""
return self._connector.post('api/v1/tip/users/id', {"mail": mail})
getTeslaIds(self, mails)
Get the learner ID of a list of learner mails
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mails |
list |
List of learner mails |
required |
Source code in tesla_ce_client/v1/tip.py
def getTeslaIds(self, mails):
"""
Get the learner ID of a list of learner mails
:param mails: List of learner mails
:type mails: list
"""
return self._connector.post('api/v1/tip/users/multiple/id', {"mails": mails})
v1
TeSLA CE API v1 Client module
V1
V1 Client class
__init__(self, connector)
special
Default constructor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connector |
Union[Connect,] |
Connector object |
required |
Source code in tesla_ce_client/v1/v1.py
def __init__(self, connector):
"""
Default constructor
:param connector: Connector object
:type connector: Connector
"""
self.tip = TipClient(connector)
self.tep = TepClient(connector)
self.rt = RtClient(connector)
self.api = ApiClient(connector)
vle
special
TeSLA CE VLE Course Activities cLient package
client
TeSLA CE VLE client module
VleClient
VLE client class
course
property
readonly
Access to the VLE course related methods
Returns:
| Type | Description |
|---|---|
VleCourseClient |
Course controller object |
__init__(self, connector)
special
Default constructor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connector |
Union[Connect,] |
Connector object |
required |
Source code in tesla_ce_client/vle/client.py
def __init__(self, connector):
"""
Default constructor
:param connector: Connector object
:type connector: Connector
"""
# Connector object -> Connector
self._connector = connector
get(self, vle_id=None)
Get a VLE
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vle_id |
int |
Identifier of the vle. If not provided take it from module configuration |
None |
Returns:
| Type | Description |
|---|---|
dict |
VLE object |
Source code in tesla_ce_client/vle/client.py
def get(self, vle_id=None):
"""
Get a VLE
:param vle_id: Identifier of the vle. If not provided take it from module configuration
:type vle_id: int
:return: VLE object
:rtype: dict
"""
if vle_id is None:
vle_id = self._connector.get_vle_id()
return self._connector.get('api/v2/vle/{}/'.format(vle_id))
get_launcher(self, vle_user_uid, vle_id=None, target='DASHBOARD', ttl=120, target_url=None, session_id=None)
Create a launcher for a user
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vle_user_uid |
str |
Identifier of the user in the vle. |
required |
vle_id |
int |
Identifier of the vle. If not provided take it from module configuration |
None |
target |
str |
The target for the launcher. Accepted values are "dashboard" (default) and "lapi". |
'DASHBOARD' |
target_url |
str |
The url where launcher is expected to be redirected. |
None |
ttl |
int |
The amount of time this launcher will be valid |
120 |
session_id |
int |
The assessment session linked to this launcher |
None |
Returns:
| Type | Description |
|---|---|
dict |
Launcher id and token |
Source code in tesla_ce_client/vle/client.py
def get_launcher(self, vle_user_uid, vle_id=None, target="DASHBOARD", ttl=120, target_url=None, session_id=None):
"""
Create a launcher for a user
:param vle_user_uid: Identifier of the user in the vle.
:type vle_user_uid: str
:param vle_id: Identifier of the vle. If not provided take it from module configuration
:type vle_id: int
:param target: The target for the launcher. Accepted values are "dashboard" (default) and "lapi".
:type target: str
:param target_url: The url where launcher is expected to be redirected.
:type target_url: str
:param ttl: The amount of time this launcher will be valid
:type ttl: int
:param session_id: The assessment session linked to this launcher
:type session_id: int
:return: Launcher id and token
:rtype: dict
"""
if vle_id is None:
vle_id = self._connector.get_vle_id()
data = {
"vle_user_uid": vle_user_uid,
"target": target,
"ttl": ttl,
"session_id": session_id,
"target_url": target_url
}
return self._connector.post('api/v2/vle/{}/launcher/'.format(vle_id), data)
list_instruments(self, vle_id=None)
Get the list of instruments
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vle_id |
int |
Identifier of the vle. If not provided take it from module configuration |
None |
Returns:
| Type | Description |
|---|---|
dict |
List of instruments |
Source code in tesla_ce_client/vle/client.py
def list_instruments(self, vle_id=None):
"""
Get the list of instruments
:param vle_id: Identifier of the vle. If not provided take it from module configuration
:type vle_id: int
:return: List of instruments
:rtype: dict
"""
if vle_id is None:
vle_id = self._connector.get_vle_id()
return self._connector.get('api/v2/vle/{}/instrument/'.format(vle_id))
course
special
TeSLA CE VLE Course Client module
activity
special
TeSLA CE VLE Course Activities cLient package
client
TeSLA CE VLE Course Activity client module
VleCourseActivityClient
VLE Course Activity client class
result
property
readonly
Access to the VLE course activity results related methods
Returns:
| Type | Description |
|---|---|
VleCourseActivityResultsClient |
Activity results controller object |
__init__(self, connector)
special
Default constructor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connector |
Union[Connect,] |
Connector object |
required |
Source code in tesla_ce_client/vle/course/activity/client.py
def __init__(self, connector):
"""
Default constructor
:param connector: Connector object
:type connector: Connector
"""
# Connector object -> Connector
self._connector = connector
add_instrument(self, course_id, activity_id, instrument_id, active, required, options=None, alternative_to=None, vle_id=None)
Add a new instrument to the activity
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
course_id |
int |
Identifier of the course |
required |
activity_id |
int |
Activity ID |
required |
instrument_id |
int |
Id of the instrument |
required |
active |
bool |
Whether this instrument is active |
required |
required |
bool |
Whether this instrument is required |
required |
options |
dict |
Options for this instrument |
None |
alternative_to |
int |
Instrument assignment this instrument is an alternative to |
None |
vle_id |
int |
Identifier of the vle. If not provided take it from module configuration |
None |
Returns:
| Type | Description |
|---|---|
dict |
Instrument assignment data |
Source code in tesla_ce_client/vle/course/activity/client.py
def add_instrument(self, course_id, activity_id, instrument_id, active, required, options=None,
alternative_to=None, vle_id=None):
"""
Add a new instrument to the activity
:param course_id: Identifier of the course
:type course_id: int
:param activity_id: Activity ID
:type activity_id: int
:param instrument_id: Id of the instrument
:type instrument_id: int
:param active: Whether this instrument is active
:type active: bool
:param required: Whether this instrument is required
:type required: bool
:param options: Options for this instrument
:type options: dict
:param alternative_to: Instrument assignment this instrument is an alternative to
:type alternative_to: int
:param vle_id: Identifier of the vle. If not provided take it from module configuration
:type vle_id: int
:return: Instrument assignment data
:rtype: dict
"""
if vle_id is None:
vle_id = self._connector.get_vle_id()
return self._connector.post('api/v2/vle/{}/course/{}/activity/{}/instrument/'.format(
vle_id, course_id, activity_id),
body={
"instrument": instrument_id,
"active": active,
"required": required,
"options": options,
"alternative_to": alternative_to
}
)
add_or_update_instrument(self, course_id, activity_id, instrument_id, active, required, options=None, alternative_to=None, vle_id=None)
Add a new instrument to the activity or update the information if this instrument already is assigned
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
course_id |
int |
Identifier of the course |
required |
activity_id |
int |
Activity ID |
required |
instrument_id |
int |
Id of the instrument |
required |
active |
bool |
Whether this instrument is active |
required |
required |
bool |
Whether this instrument is required |
required |
options |
dict |
Options for this instrument |
None |
alternative_to |
int |
Instrument assignment this instrument is an alternative to |
None |
vle_id |
int |
Identifier of the vle. If not provided take it from module configuration |
None |
Returns:
| Type | Description |
|---|---|
dict |
Instrument assignment data |
Source code in tesla_ce_client/vle/course/activity/client.py
def add_or_update_instrument(self, course_id, activity_id, instrument_id, active, required, options=None,
alternative_to=None, vle_id=None):
"""
Add a new instrument to the activity or update the information if this instrument already is assigned
:param course_id: Identifier of the course
:type course_id: int
:param activity_id: Activity ID
:type activity_id: int
:param instrument_id: Id of the instrument
:type instrument_id: int
:param active: Whether this instrument is active
:type active: bool
:param required: Whether this instrument is required
:type required: bool
:param options: Options for this instrument
:type options: dict
:param alternative_to: Instrument assignment this instrument is an alternative to
:type alternative_to: int
:param vle_id: Identifier of the vle. If not provided take it from module configuration
:type vle_id: int
:return: Instrument assignment data
:rtype: dict
"""
assignment = self.find_instrument(course_id, activity_id, instrument_id)
if assignment is None:
resp = self.add_instrument(course_id, activity_id, instrument_id,active, required, options, alternative_to,
vle_id)
else:
resp = self.update_instrument(course_id, activity_id, assignment['id'], instrument_id, active, required,
options, alternative_to, vle_id)
return resp
create(self, course_id, vle_activity_type, vle_activity_id, name, description, enabled=True, start=None, end=None, conf=None, vle_id=None)
Create a new activity
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
course_id |
int |
Id of the course |
required |
vle_activity_type |
str |
Type of the activity in the VLE |
required |
vle_activity_id |
str |
ID of the activity in the VLE |
required |
name |
str |
Name of the activity |
required |
description |
str |
Description of the course |
required |
enabled |
bool |
Whether this activity is enabled for TeSLA |
True |
start |
datetime |
Start date of the course |
None |
end |
datetime |
End date of the course |
None |
conf |
dict |
Additional configuration for the activity |
None |
vle_id |
int |
Identifier of the vle. If not provided take it from module configuration |
None |
Returns:
| Type | Description |
|---|---|
|
New created course |
Source code in tesla_ce_client/vle/course/activity/client.py
def create(self, course_id, vle_activity_type, vle_activity_id, name, description, enabled=True, start=None,
end=None, conf=None, vle_id=None):
"""
Create a new activity
:param course_id: Id of the course
:type course_id: int
:param vle_activity_type: Type of the activity in the VLE
:type vle_activity_type: str
:param vle_activity_id: ID of the activity in the VLE
:type vle_activity_id: str
:param name: Name of the activity
:type name: str
:param description: Description of the course
:type description: str
:param enabled: Whether this activity is enabled for TeSLA
:type enabled: bool
:param start: Start date of the course
:type start: datetime
:param end: End date of the course
:type end: datetime
:param conf: Additional configuration for the activity
:type conf: dict
:param vle_id: Identifier of the vle. If not provided take it from module configuration
:type vle_id: int
:return: New created course
"""
if vle_id is None:
vle_id = self._connector.get_vle_id()
return self._connector.post('api/v2/vle/{}/course/{}/activity/'.format(vle_id, course_id), body={
"vle_activity_type": vle_activity_type,
"vle_activity_id": vle_activity_id,
"name": name,
"description": description,
"enabled": enabled,
"start": start,
"end": end,
"conf": conf
})
find_by_vle_id(self, course_id, vle_activity_type, vle_activity_id, vle_id=None)
Find an activity using the VLE identifiers
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
course_id |
int |
Identifier of the course |
required |
vle_activity_type |
str |
Type of the activity in the VLE |
required |
vle_activity_id |
str |
Activity ID in the VLE |
required |
vle_id |
int |
Identifier of the vle. If not provided take it from module configuration |
None |
Returns:
| Type | Description |
|---|---|
dict |
Activity data |
Source code in tesla_ce_client/vle/course/activity/client.py
def find_by_vle_id(self, course_id, vle_activity_type, vle_activity_id, vle_id=None):
"""
Find an activity using the VLE identifiers
:param course_id: Identifier of the course
:type course_id: int
:param vle_activity_type: Type of the activity in the VLE
:type vle_activity_type: str
:param vle_activity_id: Activity ID in the VLE
:type vle_activity_id: str
:param vle_id: Identifier of the vle. If not provided take it from module configuration
:type vle_id: int
:return: Activity data
:rtype: dict
"""
if vle_id is None:
vle_id = self._connector.get_vle_id()
result = self._connector.get('api/v2/vle/{}/course/{}/activity/?vle_activity_type={}&vle_activity_id={}'.format(
vle_id, course_id, vle_activity_type, vle_activity_id)
)
if result['count'] == 1:
return result['results'][0]
return None
find_instrument(self, course_id, activity_id, instrument_id, vle_id=None)
Find an assigned instrument
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
course_id |
int |
Identifier of the course |
required |
activity_id |
int |
Activity ID |
required |
instrument_id |
int |
Id of the instrument |
required |
vle_id |
int |
Identifier of the vle. If not provided take it from module configuration |
None |
Returns:
| Type | Description |
|---|---|
dict |
List of instrument assignments |
Source code in tesla_ce_client/vle/course/activity/client.py
def find_instrument(self, course_id, activity_id, instrument_id, vle_id=None):
"""
Find an assigned instrument
:param course_id: Identifier of the course
:type course_id: int
:param activity_id: Activity ID
:type activity_id: int
:param instrument_id: Id of the instrument
:type instrument_id: int
:param vle_id: Identifier of the vle. If not provided take it from module configuration
:type vle_id: int
:return: List of instrument assignments
:rtype: dict
"""
if vle_id is None:
vle_id = self._connector.get_vle_id()
result = self._connector.get('api/v2/vle/{}/course/{}/activity/{}/instrument/?instrument_id={}'.format(
vle_id, course_id, activity_id, instrument_id),
)
if result['count'] == 1:
return result['results'][0]
return None
get(self, course_id, activity_id, vle_id=None)
Get an activity
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
course_id |
int |
Identifier of the course |
required |
activity_id |
int |
Identifier of the activity |
required |
vle_id |
int |
Identifier of the vle. If not provided take it from module configuration |
None |
Returns:
| Type | Description |
|---|---|
dict |
Activity data |
Source code in tesla_ce_client/vle/course/activity/client.py
def get(self, course_id, activity_id, vle_id=None):
"""
Get an activity
:param course_id: Identifier of the course
:type course_id: int
:param activity_id: Identifier of the activity
:type activity_id: int
:param vle_id: Identifier of the vle. If not provided take it from module configuration
:type vle_id: int
:return: Activity data
:rtype: dict
"""
if vle_id is None:
vle_id = self._connector.get_vle_id()
return self._connector.get('api/v2/vle/{}/course/{}/activity/{}/'.format(vle_id, course_id, activity_id))
get_instruments(self, course_id, activity_id, vle_id=None)
Get the instrument configuration for a given activity
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
course_id |
int |
Identifier of the course |
required |
activity_id |
int |
Activity ID |
required |
vle_id |
int |
Identifier of the vle. If not provided take it from module configuration |
None |
Returns:
| Type | Description |
|---|---|
dict |
Activity data |
Source code in tesla_ce_client/vle/course/activity/client.py
def get_instruments(self, course_id, activity_id, vle_id=None):
"""
Get the instrument configuration for a given activity
:param course_id: Identifier of the course
:type course_id: int
:param activity_id: Activity ID
:type activity_id: int
:param vle_id: Identifier of the vle. If not provided take it from module configuration
:type vle_id: int
:return: Activity data
:rtype: dict
"""
if vle_id is None:
vle_id = self._connector.get_vle_id()
return self._connector.get('api/v2/vle/{}/course/{}/activity/{}/instrument/'.format(
vle_id, course_id, activity_id)
)
list(self, course_id, vle_id=None)
Get the list of activities
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
course_id |
str |
Identifier of the course. |
required |
vle_id |
int |
Identifier of the vle. If not provided take it from module configuration |
None |
Returns:
| Type | Description |
|---|---|
list |
List of activities |
Source code in tesla_ce_client/vle/course/activity/client.py
def list(self, course_id, vle_id=None):
"""
Get the list of activities
:param course_id: Identifier of the course.
:type course_id: str
:param vle_id: Identifier of the vle. If not provided take it from module configuration
:type vle_id: int
:return: List of activities
:rtype: list
"""
if vle_id is None:
vle_id = self._connector.get_vle_id()
return self._connector.get('api/v2/vle/{}/course/{}/activity/'.format(vle_id, course_id))
update(self, course_id, activity_id, vle_activity_type, vle_activity_id, name, description, enabled=True, start=None, end=None, conf=None, vle_id=None)
Update an activity
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
course_id |
int |
Id of the course |
required |
activity_id |
int |
Id of the activity |
required |
vle_activity_type |
str |
Type of the activity in the VLE |
required |
vle_activity_id |
str |
ID of the activity in the VLE |
required |
name |
str |
Name of the activity |
required |
description |
str |
Description of the course |
required |
enabled |
bool |
Whether this activity is enabled for TeSLA |
True |
start |
datetime |
Start date of the course |
None |
end |
datetime |
End date of the course |
None |
conf |
dict |
Additional configuration for the activity |
None |
vle_id |
int |
Identifier of the vle. If not provided take it from module configuration |
None |
Returns:
| Type | Description |
|---|---|
|
New updated activity |
Source code in tesla_ce_client/vle/course/activity/client.py
def update(self, course_id, activity_id, vle_activity_type, vle_activity_id, name, description, enabled=True,
start=None, end=None, conf=None, vle_id=None):
"""
Update an activity
:param course_id: Id of the course
:type course_id: int
:param activity_id: Id of the activity
:type activity_id: int
:param vle_activity_type: Type of the activity in the VLE
:type vle_activity_type: str
:param vle_activity_id: ID of the activity in the VLE
:type vle_activity_id: str
:param name: Name of the activity
:type name: str
:param description: Description of the course
:type description: str
:param enabled: Whether this activity is enabled for TeSLA
:type enabled: bool
:param start: Start date of the course
:type start: datetime
:param end: End date of the course
:type end: datetime
:param conf: Additional configuration for the activity
:type conf: dict
:param vle_id: Identifier of the vle. If not provided take it from module configuration
:type vle_id: int
:return: New updated activity
"""
if vle_id is None:
vle_id = self._connector.get_vle_id()
return self._connector.put('api/v2/vle/{}/course/{}/activity/{}/'.format(vle_id, course_id, activity_id),
body={
"vle_activity_type": vle_activity_type,
"vle_activity_id": vle_activity_id,
"name": name,
"description": description,
"enabled": enabled,
"start": start,
"end": end,
"conf": conf
})
update_instrument(self, course_id, activity_id, assignment_id, instrument_id, active, required, options=None, alternative_to=None, vle_id=None)
Update an instrument configuration for a given activity
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
course_id |
int |
Identifier of the course |
required |
activity_id |
int |
Activity ID |
required |
assignment_id |
int |
Instrument assignment ID |
required |
instrument_id |
int |
Id of the instrument |
required |
active |
bool |
Whether this instrument is active |
required |
required |
bool |
Whether this instrument is required |
required |
options |
dict |
Options for this instrument |
None |
alternative_to |
int |
Instrument assignment this instrument is an alternative to |
None |
vle_id |
int |
Identifier of the vle. If not provided take it from module configuration |
None |
Returns:
| Type | Description |
|---|---|
dict |
Instrument assignment data |
Source code in tesla_ce_client/vle/course/activity/client.py
def update_instrument(self, course_id, activity_id, assignment_id, instrument_id, active, required, options=None,
alternative_to=None, vle_id=None):
"""
Update an instrument configuration for a given activity
:param course_id: Identifier of the course
:type course_id: int
:param activity_id: Activity ID
:type activity_id: int
:param assignment_id: Instrument assignment ID
:type assignment_id: int
:param instrument_id: Id of the instrument
:type instrument_id: int
:param active: Whether this instrument is active
:type active: bool
:param required: Whether this instrument is required
:type required: bool
:param options: Options for this instrument
:type options: dict
:param alternative_to: Instrument assignment this instrument is an alternative to
:type alternative_to: int
:param vle_id: Identifier of the vle. If not provided take it from module configuration
:type vle_id: int
:return: Instrument assignment data
:rtype: dict
"""
if vle_id is None:
vle_id = self._connector.get_vle_id()
return self._connector.put('api/v2/vle/{}/course/{}/activity/{}/instrument/{}/'.format(
vle_id, course_id, activity_id, assignment_id),
body={
"instrument": instrument_id,
"active": active,
"required": required,
"options": options,
"alternative_to": alternative_to
}
)
results
special
TeSLA CE VLE Course Activities cLient package
client
TeSLA CE VLE Course Activity results client module
VleCourseActivityResultsClient
VLE Course Activity client class
__init__(self, connector)
special
Default constructor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connector |
Union[Connect,] |
Connector object |
required |
Source code in tesla_ce_client/vle/course/activity/results/client.py
def __init__(self, connector):
"""
Default constructor
:param connector: Connector object
:type connector: Connector
"""
# Connector object -> Connector
self._connector = connector
get(self, course_id, activity_id, report_id, vle_id=None)
Get the detail of a single result
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
course_id |
str |
Identifier of the course. |
required |
activity_id |
int |
Identifier of the activity |
required |
report_id |
int |
Identifier of the report |
required |
vle_id |
int |
Identifier of the vle. If not provided take it from module configuration |
None |
Returns:
| Type | Description |
|---|---|
object |
Result detail |
Source code in tesla_ce_client/vle/course/activity/results/client.py
def get(self, course_id, activity_id, report_id, vle_id=None):
"""
Get the detail of a single result
:param course_id: Identifier of the course.
:type course_id: str
:param activity_id: Identifier of the activity
:type activity_id: int
:param report_id: Identifier of the report
:type report_id: int
:param vle_id: Identifier of the vle. If not provided take it from module configuration
:type vle_id: int
:return: Result detail
:rtype: object
"""
if vle_id is None:
vle_id = self._connector.get_vle_id()
return self._connector.get('api/v2/vle/{}/course/{}/activity/{}/report/{}/'.format(vle_id,
course_id,
activity_id,
report_id))
list(self, course_id, activity_id, vle_id=None)
Get the list of results for an activity
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
course_id |
str |
Identifier of the course. |
required |
activity_id |
int |
Identifier of the activity |
required |
vle_id |
int |
Identifier of the vle. If not provided take it from module configuration |
None |
Returns:
| Type | Description |
|---|---|
list |
List of results for the activity |
Source code in tesla_ce_client/vle/course/activity/results/client.py
def list(self, course_id, activity_id, vle_id=None):
"""
Get the list of results for an activity
:param course_id: Identifier of the course.
:type course_id: str
:param activity_id: Identifier of the activity
:type activity_id: int
:param vle_id: Identifier of the vle. If not provided take it from module configuration
:type vle_id: int
:return: List of results for the activity
:rtype: list
"""
if vle_id is None:
vle_id = self._connector.get_vle_id()
return self._connector.get('api/v2/vle/{}/course/{}/activity/{}/report/'.format(vle_id,
course_id,
activity_id))
list_requests(self, course_id, activity_id, learner_id, instrument=None, vle_id=None)
Get the list of learner requests for an activity
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
course_id |
str |
Identifier of the course. |
required |
activity_id |
int |
Identifier of the activity |
required |
instrument |
int |
Filter requests for provided instrument |
None |
vle_id |
int |
Identifier of the vle. If not provided take it from module configuration |
None |
Returns:
| Type | Description |
|---|---|
list |
List of results for the activity |
Source code in tesla_ce_client/vle/course/activity/results/client.py
def list_requests(self, course_id, activity_id, learner_id, instrument=None, vle_id=None):
"""
Get the list of learner requests for an activity
:param course_id: Identifier of the course.
:type course_id: str
:param activity_id: Identifier of the activity
:type activity_id: int
:param activity_id: Identifier of the activity
:type activity_id: int
:param instrument: Filter requests for provided instrument
:type instrument: int
:param vle_id: Identifier of the vle. If not provided take it from module configuration
:type vle_id: int
:return: List of results for the activity
:rtype: list
"""
if vle_id is None:
vle_id = self._connector.get_vle_id()
if instrument is None:
return self._connector.get('api/v2/vle/{}/course/{}/activity/{}/learner/{}/request/'.format(vle_id,
course_id,
activity_id,
learner_id)
)
return self._connector.get('api/v2/vle/{}/course/{}/activity/{}/learner/{}/request/?instruments={}'.format(
vle_id,
course_id,
activity_id,
learner_id,
instrument)
)
client
TeSLA CE VLE Activity client module
VleCourseClient
VLE Course client class
activity
property
readonly
Access to the VLE course activity related methods
Returns:
| Type | Description |
|---|---|
VleCourseActivityClient |
Activity controller object |
learner
property
readonly
Access to the VLE course learner related methods
Returns:
| Type | Description |
|---|---|
VleCourseLearnerClient |
Learner controller object |
__init__(self, connector)
special
Default constructor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connector |
Union[Connect,] |
Connector object |
required |
Source code in tesla_ce_client/vle/course/client.py
def __init__(self, connector):
"""
Default constructor
:param connector: Connector object
:type connector: Connector
"""
# Connector object -> Connector
self._connector = connector
create(self, vle_course_id, code, description, start=None, end=None, vle_id=None)
Create a new course
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vle_course_id |
str |
Id of the course in the VLE |
required |
code |
str |
Code of the course |
required |
description |
str |
Description of the course |
required |
start |
datetime |
Start date of the course |
None |
end |
datetime |
End date of the course |
None |
vle_id |
int |
Identifier of the vle. If not provided take it from module configuration |
None |
Returns:
| Type | Description |
|---|---|
|
New created course |
Source code in tesla_ce_client/vle/course/client.py
def create(self, vle_course_id, code, description, start=None, end=None, vle_id=None):
"""
Create a new course
:param vle_course_id: Id of the course in the VLE
:type vle_course_id: str
:param code: Code of the course
:type code: str
:param description: Description of the course
:type description: str
:param start: Start date of the course
:type start: datetime
:param end: End date of the course
:type end: datetime
:param vle_id: Identifier of the vle. If not provided take it from module configuration
:type vle_id: int
:return: New created course
"""
if vle_id is None:
vle_id = self._connector.get_vle_id()
return self._connector.post('api/v2/vle/{}/course/'.format(vle_id), body={
"vle_course_id": vle_course_id,
"code": code,
"description": description,
"start": start,
"end": end
})
find_by_vle_id(self, vle_course_id, vle_id=None)
Get the learner from learner institution code
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vle_course_id |
str | int |
Identifier of the course in the vle |
required |
vle_id |
int |
Identifier of the vle. If not provided take it from module configuration |
None |
Returns:
| Type | Description |
|---|---|
dict |
Course object |
Source code in tesla_ce_client/vle/course/client.py
def find_by_vle_id(self, vle_course_id, vle_id=None):
"""
Get the learner from learner institution code
:param vle_course_id: Identifier of the course in the vle
:type vle_course_id: str | int
:param vle_id: Identifier of the vle. If not provided take it from module configuration
:type vle_id: int
:return: Course object
:rtype: dict
"""
if vle_id is None:
vle_id = self._connector.get_vle_id()
result = self._connector.get('api/v2/vle/{}/course/?vle_course_id={}'.format(vle_id, vle_course_id))
if result['count'] == 1:
return result['results'][0]
return None
list(self, vle_id=None)
Get the list of courses
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vle_id |
int |
Identifier of the vle. If not provided take it from module configuration |
None |
Returns:
| Type | Description |
|---|---|
list |
List of courses |
Source code in tesla_ce_client/vle/course/client.py
def list(self, vle_id=None):
"""
Get the list of courses
:param vle_id: Identifier of the vle. If not provided take it from module configuration
:type vle_id: int
:return: List of courses
:rtype: list
"""
if vle_id is None:
vle_id = self._connector.get_vle_id()
return self._connector.get('api/v2/vle/{}/course/'.format(vle_id))
learner
special
TeSLA CE VLE Course Activities cLient package
client
TeSLA CE VLE Course Learner client module
VleCourseLearnerClient
VLE Course Learner client class
__init__(self, connector)
special
Default constructor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connector |
Union[Connect,] |
Connector object |
required |
Source code in tesla_ce_client/vle/course/learner/client.py
def __init__(self, connector):
"""
Default constructor
:param connector: Connector object
:type connector: Connector
"""
# Connector object -> Connector
self._connector = connector
find_by_lerner_id(self, course_id, learner_id, vle_id=None)
Get a learner
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
course_id |
int |
Identifier of the course |
required |
learner_id |
str |
Learner learner_id UUID |
required |
vle_id |
int |
Identifier of the vle. If not provided take it from module configuration |
None |
Returns:
| Type | Description |
|---|---|
dict |
Learner data |
Source code in tesla_ce_client/vle/course/learner/client.py
def find_by_lerner_id(self, course_id, learner_id, vle_id=None):
"""
Get a learner
:param course_id: Identifier of the course
:type course_id: int
:param learner_id: Learner learner_id UUID
:type learner_id: str
:param vle_id: Identifier of the vle. If not provided take it from module configuration
:type vle_id: int
:return: Learner data
:rtype: dict
"""
if vle_id is None:
vle_id = self._connector.get_vle_id()
result = self._connector.get('api/v2/vle/{}/course/{}/learner/?lerner_id={}'.format(
vle_id, course_id, learner_id)
)
if result['count'] == 1:
return result['results'][0]
return None
find_by_mail(self, course_id, mail, vle_id=None)
Get a learner
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
course_id |
int |
Identifier of the course |
required |
mail |
str |
Mail of the learner |
required |
vle_id |
int |
Identifier of the vle. If not provided take it from module configuration |
None |
Returns:
| Type | Description |
|---|---|
dict |
Learner data |
Source code in tesla_ce_client/vle/course/learner/client.py
def find_by_mail(self, course_id, mail, vle_id=None):
"""
Get a learner
:param course_id: Identifier of the course
:type course_id: int
:param mail: Mail of the learner
:type mail: str
:param vle_id: Identifier of the vle. If not provided take it from module configuration
:type vle_id: int
:return: Learner data
:rtype: dict
"""
if vle_id is None:
vle_id = self._connector.get_vle_id()
result = self._connector.get('api/v2/vle/{}/course/{}/learner/?mail={}'.format(
vle_id, course_id, mail)
)
if result['count'] == 1:
return result['results'][0]
return None
find_by_uid(self, course_id, uid, vle_id=None)
Get a learner
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
course_id |
int |
Identifier of the course |
required |
uid |
str |
UID of the learner |
required |
vle_id |
int |
Identifier of the vle. If not provided take it from module configuration |
None |
Returns:
| Type | Description |
|---|---|
dict |
Learner data |
Source code in tesla_ce_client/vle/course/learner/client.py
def find_by_uid(self, course_id, uid, vle_id=None):
"""
Get a learner
:param course_id: Identifier of the course
:type course_id: int
:param uid: UID of the learner
:type uid: str
:param vle_id: Identifier of the vle. If not provided take it from module configuration
:type vle_id: int
:return: Learner data
:rtype: dict
"""
if vle_id is None:
vle_id = self._connector.get_vle_id()
result = self._connector.get('api/v2/vle/{}/course/{}/learner/?uid={}'.format(
vle_id, course_id, uid)
)
if result['count'] == 1:
return result['results'][0]
return None
get(self, course_id, learner_id, vle_id=None)
Get a learner
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
course_id |
int |
Identifier of the course |
required |
learner_id |
int |
Identifier of the learner |
required |
vle_id |
int |
Identifier of the vle. If not provided take it from module configuration |
None |
Returns:
| Type | Description |
|---|---|
list |
List of activities |
Source code in tesla_ce_client/vle/course/learner/client.py
def get(self, course_id, learner_id, vle_id=None):
"""
Get a learner
:param course_id: Identifier of the course
:type course_id: int
:param learner_id: Identifier of the learner
:type learner_id: int
:param vle_id: Identifier of the vle. If not provided take it from module configuration
:type vle_id: int
:return: List of activities
:rtype: list
"""
if vle_id is None:
vle_id = self._connector.get_vle_id()
return self._connector.get('api/v2/vle/{}/course/{}/activity/{}/'.format(vle_id, course_id, learner_id))
list(self, course_id, vle_id=None)
Get the list of learners
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
course_id |
str |
Identifier of the course. |
required |
vle_id |
int |
Identifier of the vle. If not provided take it from module configuration |
None |
Returns:
| Type | Description |
|---|---|
list |
List of learners |
Source code in tesla_ce_client/vle/course/learner/client.py
def list(self, course_id, vle_id=None):
"""
Get the list of learners
:param course_id: Identifier of the course.
:type course_id: str
:param vle_id: Identifier of the vle. If not provided take it from module configuration
:type vle_id: int
:return: List of learners
:rtype: list
"""
if vle_id is None:
vle_id = self._connector.get_vle_id()
return self._connector.get('api/v2/vle/{}/course/{}/learner/'.format(vle_id, course_id))