api package

Contents

api package#

Submodules#

api.admin module#

class api.admin.ApiLogAdmin(model, admin_site)[source]#

Bases: ModelAdmin

autocomplete_fields = ['admin']#
property media#

api.apis module#

These are the supported APIs for Cobalt.

Authentication is handled in the urls.py module, so by the time you get here you are dealing with an authenticated user. Functions in here are still responsible for rbac calls to handle access.

Code here should be as short as possible, if anything more complex is required you should call a function in the ‘home’ module for the thing you are doing.

APIs should all be versioned with /vx.y at the end of the URI. This is automatically logged every time an API is called.

APIs should all return JSON with at least one parameter e.g.

{‘status’: ‘Success’}

or

{‘status: ‘Failure’}

or

{‘status: ‘Access Denied’}

class api.apis.APIStatus[source]#

Bases: object

Status messages from the API

ACCESS_DENIED = 'Access Denied'#
FAILURE = 'Failure'#
SUCCESS = 'Success'#
class api.apis.MobileClientFCMRequestV1(*, fcm_token: str)[source]#

Bases: Schema

fcm_token: str#
class api.apis.MobileClientRegisterRequestV1(*, username: str = '', password: str = '', fcm_token: str = '')[source]#

Bases: Schema

Request format from mobile_client_register_v1

fcm_token: str#
password: str#
username: str#
class api.apis.MobileClientRegisterRequestV11(*, username: str = '', password: str = '', fcm_token: str = '', OS: str = '', name: str = '')[source]#

Bases: Schema

Request format from mobile_client_register_v1.1

OS: str#
fcm_token: str#
name: str#
password: str#
username: str#
class api.apis.MobileClientSingleMessageRequestV1(*, fcm_token: str, message_id: int)[source]#

Bases: Schema

Structure for requests that access a single message by id

fcm_token: str#
message_id: int#
class api.apis.MobileClientUnreadMessagesResponseV1(*, status: str, un_read_messages: List[UnreadMessageV1])[source]#

Bases: Schema

status: str#
un_read_messages: List[UnreadMessageV1]#
class api.apis.MobileClientUpdateRequestV1(*, old_fcm_token: str = '', new_fcm_token: str = '')[source]#

Bases: Schema

Request format from mobile_client_update_v1

new_fcm_token: str#
old_fcm_token: str#
class api.apis.NotificationFileUploadV1(*, sender_identification: str = None)[source]#

Bases: Schema

sender_identification: str#
class api.apis.StatusResponseV1(*, status: str, message: str)[source]#

Bases: Schema

Standard error/response format when no data is returned

message: str#
status: str#
class api.apis.UnauthorizedV1(*, detail: str)[source]#

Bases: Schema

Standard error format

detail: str#
class api.apis.UnreadMessageV1(*, id: int, message: str, created_datetime: str)[source]#

Bases: Schema

created_datetime: str#
id: int#
message: str#
class api.apis.UserDataResponseV1(*, status: str, user: UserResponseV1)[source]#

Bases: Schema

Response format from mobile_client_register_v1

class UserResponseV1(*, first_name: str, last_name: str, system_number: int)[source]#

Bases: Schema

first_name: str#
last_name: str#
system_number: int#
status: str#
user: UserResponseV1#
class api.apis.UserDataResponseV11(*, status: str, user: UserResponseV1)[source]#

Bases: Schema

Response format from mobile_client_register_v1.1

class UserResponseV1(*, first_name: str, last_name: str, system_number: int, session_id: str)[source]#

Bases: Schema

first_name: str#
last_name: str#
session_id: str#
system_number: int#
status: str#
user: UserResponseV1#
api.apis.api_notifications_delete_all_messages_for_user_v1(request, data: MobileClientFCMRequestV1)[source]#

Delete all message

api.apis.api_notifications_delete_message_for_user_v1(request, data: MobileClientSingleMessageRequestV1)[source]#

Delete a single message

api.apis.api_notifications_latest_messages_for_user_v1(request, data: MobileClientFCMRequestV1)[source]#

Return last 50 messages for this user

api.apis.api_notifications_unread_messages_for_user_v1(request, data: MobileClientFCMRequestV1)[source]#

Return any unread messages for this user

api.apis.key_check_v1(request)[source]#

Allow a developer to check that their key is valid

api.apis.mobile_client_register_v1(request, data: MobileClientRegisterRequestV1)[source]#

Called by the Flutter front end to register a new FCM Token for a user. User is NOT authenticated, but username and password are passed in.

Parameters:
  • user (password - as provided by)

  • No (can be ABF)

  • username (email or actual)

  • login (same as)

  • user

  • user/device (fcm_token - client device's Google Firebase Cloud Messaging token. Used to send messages to this)

api.apis.mobile_client_register_v11(request, data: MobileClientRegisterRequestV11)[source]#

Called by the Flutter front end to register a new FCM Token for a user. User is NOT authenticated, but username and password are passed in.

Parameters:
  • user (password - as provided by)

  • No (can be ABF)

  • username (email or actual)

  • login (same as)

  • user

  • user/device (fcm_token - client device's Google Firebase Cloud Messaging token. Used to send messages to this)

  • device (name - name of mobile)

  • device

api.apis.mobile_client_update_v1(request, data: MobileClientUpdateRequestV1)[source]#

Called to update the FCM token

api.apis.notification_file_upload_v1(request, data: NotificationFileUploadV1 = Form(default=Ellipsis, extra={}), file: UploadedFile = File(default=Ellipsis, extra={}))[source]#

Allow scorers to upload a file with ABF numbers and messages to send to members.

File format is abf_number[tab character (t)]message

The filename is used as the description.

If the message contains <NL> then we change this to a newline (n).

Messages are sent through Google Firebase Messaging to a mobile app.

api.apis.sms_file_upload_v1(request, file: UploadedFile = File(default=Ellipsis, extra={}))[source]#

Allow scorers to upload a file with ABF numbers and messages to send to members.

File format is abf_number[tab character (t)]message

The filename is used as the description.

If the message contains <NL> then we change this to a newline (n).

Messages over 140 characters will be sent as multiple SMSs.

api.apis.system_number_lookup_v1(request, system_number: int)[source]#

api.apps module#

class api.apps.ApiConfig(app_name, app_module)[source]#

Bases: AppConfig

default_auto_field = 'django.db.models.BigAutoField'#
name = 'api'#

api.core module#

api.core.api_rbac(request, role)[source]#

Check if API user has RBAC role

api.models module#

class api.models.ApiLog(*args, **kwargs)[source]#

Bases: Model

Logging of API usage. All API calls should create a record here

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

admin#

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.

admin_id#
api#

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

created_date#

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

get_next_by_created_date(*, field=<django.db.models.fields.DateTimeField: created_date>, is_next=True, **kwargs)#
get_previous_by_created_date(*, field=<django.db.models.fields.DateTimeField: created_date>, is_next=False, **kwargs)#
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>#
version#

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

api.urls module#

This is the main entry point for the cobalt API. The API is a separate Django app as this makes things cleaner and easier to manage than having the (relatively small) API code spread across lots of modules.

class api.urls.AuthCheck[source]#

Bases: object

This is the core authentication method. Other classes inherit from this and provide different ways to obtain the same key from the client.

authenticate(request, key)[source]#

Returns the user associated with this key or None (invalid)

class api.urls.BearerKey[source]#

Bases: AuthCheck, HttpBearer

Get the key from the HttpBearer

class api.urls.HeaderKey[source]#

Bases: AuthCheck, APIKeyHeader

Get the key from the header

class api.urls.QueryKey[source]#

Bases: AuthCheck, APIKeyQuery

Get the key from the query

api.urls.custom_validation_errors(request, exc)[source]#
api.urls.log_api_call(request, user=None)[source]#

Log a call to the API. For anonymous calls the user will be empty

Module contents#