Models

class terminusgps_notifications.models.MessagePackage(id, price, count, max, customer)[source]

Public Data Attributes:

customer_id

customer

Associated customer.

Inherited from Model

pk

Public Methods:

__str__()

Returns 'MessagePackage #<pk>'.

price

Message package price.

count

Message package current execution count.

max

Message package maximum allowed executions.

id

A wrapper for a deferred-loading field.

objects

Inherited from Model

__init__(*args, **kwargs)

from_db(db, field_names, values)

__repr__()

Return repr(self).

__str__()

Return str(self).

__eq__(other)

Return self==value.

__hash__()

Return hash(self).

__reduce__()

Helper for pickle.

__getstate__()

Hook to allow choosing the attributes to pickle.

__setstate__(state)

get_deferred_fields()

Return a set containing names of deferred fields for this instance.

refresh_from_db([using, fields, from_queryset])

Reload field values from the database.

arefresh_from_db([using, fields, from_queryset])

serializable_value(field_name)

Return the value of the field name for this instance.

save(*[, force_insert, force_update, using, ...])

Save the current instance.

asave(*[, force_insert, force_update, ...])

save_base([raw, force_insert, force_update, ...])

Handle the parts of saving which should be done only once per save, yet need to be done in raw saves, too.

delete([using, keep_parents])

adelete([using, keep_parents])

prepare_database_save(field)

clean()

Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields.

validate_unique([exclude])

Check unique constraints on the model and raise ValidationError if any failed.

date_error_message(lookup_type, field_name, ...)

unique_error_message(model_class, unique_check)

get_constraints()

validate_constraints([exclude])

full_clean([exclude, validate_unique, ...])

Call clean_fields(), clean(), validate_unique(), and validate_constraints() on the model.

clean_fields([exclude])

Clean all fields and raise a ValidationError containing a dict of all validation errors if any occur.

check(**kwargs)

Inherited from AltersData

__init_subclass__(**kwargs)

This method is called when a class is subclassed.

Private Data Attributes:

_meta

Private Methods:

Inherited from Model

_get_pk_val([meta])

_set_pk_val(value)

_is_pk_set([meta])

_validate_force_insert(force_insert)

_save_parents(cls, using, update_fields, ...)

Save all the parents of cls using values from self.

_save_table([raw, cls, force_insert, ...])

Do the heavy-lifting involved in saving.

_do_update(base_qs, using, pk_val, values, ...)

Try to update the model.

_do_insert(manager, using, fields, ...)

Do an INSERT.

_assign_returned_values(returned_values, ...)

_prepare_related_fields_for_save(operation_name)

_get_FIELD_display(field)

_get_next_or_previous_by_FIELD(field, ...)

_get_next_or_previous_in_order(is_next)

_get_field_expression_map(meta[, exclude])

_get_unique_checks([exclude, ...])

Return a list of checks to perform.

_perform_unique_checks(unique_checks)

_perform_date_checks(date_checks)

_check_composite_pk()

_check_db_table_comment(databases)

_check_swappable()

Check if the swapped model exists.

_check_model()

_check_managers(**kwargs)

Perform all manager checks.

_check_fields(**kwargs)

Perform all field checks.

_check_m2m_through_same_relationship()

Check if no relationship model is used by more than one m2m field.

_check_id_field()

Check if id field is a primary key.

_check_field_name_clashes()

Forbid field shadowing in multi-table inheritance.

_check_column_name_clashes()

_check_model_name_db_lookup_clashes()

_check_property_name_related_field_accessor_clashes()

_check_single_primary_key()

_check_unique_together()

Check the value of "unique_together" option.

_check_indexes(databases)

_check_local_fields(fields, option)

_check_ordering()

Check "ordering" option -- is it a list of strings and do all fields exist?

_check_long_column_names(databases)

Check that any auto-generated column names are shorter than the limits for each database in which the model will be created.

_get_expr_references(expr)

_check_constraints(databases)


exception DoesNotExist
exception MultipleObjectsReturned
exception NotUpdated
count

Message package current execution count.

Type:

int

customer

Associated customer.

Type:

TerminusgpsNotificationsCustomer

max

Message package maximum allowed executions.

Type:

int

price

Message package price.

Type:

Decimal

class terminusgps_notifications.models.TerminusgpsNotificationsCustomer(*args, **kwargs)[source]

A Terminus GPS Notifications customer.

Public Data Attributes:

user_id

user

Django user.

subscription_id

subscription

Associated subscription.

packages

Accessor to the related objects manager on the reverse side of a many-to-one relation.

token

Accessor to the related object on the reverse side of a one-to-one relation.

notifications

Accessor to the related objects manager on the reverse side of a many-to-one relation.

Inherited from Model

pk

Public Methods:

__str__()

Returns the customer user's username.

get_units_from_wialon(resource_id, session)

Returns a list of of customer Wialon unit dictionaries from the Wialon API.

get_resources_from_wialon(session[, force, ...])

Returns a list of of customer Wialon resource dictionaries from the Wialon API.

company

Company name.

date_format

Date format for notifications.

get_date_format_display(*[, field])

tax_rate

Subscription tax rate.

subtotal

Subscription current subtotal.

tax

Subscription tax total.

grand_total

Subscription grand total (subtotal + tax).

messages_max

Maximum number of notification executions in a single period.

messages_max_base

Maximum base number of notification executions in a single period.

messages_count

Current number of notification executions this period.

id

A wrapper for a deferred-loading field.

objects

Inherited from Model

__init__(*args, **kwargs)

from_db(db, field_names, values)

__repr__()

Return repr(self).

__str__()

Return str(self).

__eq__(other)

Return self==value.

__hash__()

Return hash(self).

__reduce__()

Helper for pickle.

__getstate__()

Hook to allow choosing the attributes to pickle.

__setstate__(state)

get_deferred_fields()

Return a set containing names of deferred fields for this instance.

refresh_from_db([using, fields, from_queryset])

Reload field values from the database.

arefresh_from_db([using, fields, from_queryset])

serializable_value(field_name)

Return the value of the field name for this instance.

save(*[, force_insert, force_update, using, ...])

Save the current instance.

asave(*[, force_insert, force_update, ...])

save_base([raw, force_insert, force_update, ...])

Handle the parts of saving which should be done only once per save, yet need to be done in raw saves, too.

delete([using, keep_parents])

adelete([using, keep_parents])

prepare_database_save(field)

clean()

Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields.

validate_unique([exclude])

Check unique constraints on the model and raise ValidationError if any failed.

date_error_message(lookup_type, field_name, ...)

unique_error_message(model_class, unique_check)

get_constraints()

validate_constraints([exclude])

full_clean([exclude, validate_unique, ...])

Call clean_fields(), clean(), validate_unique(), and validate_constraints() on the model.

clean_fields([exclude])

Clean all fields and raise a ValidationError containing a dict of all validation errors if any occur.

check(**kwargs)

Inherited from AltersData

__init_subclass__(**kwargs)

This method is called when a class is subclassed.

Private Data Attributes:

_meta

Private Methods:

Inherited from Model

_get_pk_val([meta])

_set_pk_val(value)

_is_pk_set([meta])

_validate_force_insert(force_insert)

_save_parents(cls, using, update_fields, ...)

Save all the parents of cls using values from self.

_save_table([raw, cls, force_insert, ...])

Do the heavy-lifting involved in saving.

_do_update(base_qs, using, pk_val, values, ...)

Try to update the model.

_do_insert(manager, using, fields, ...)

Do an INSERT.

_assign_returned_values(returned_values, ...)

_prepare_related_fields_for_save(operation_name)

_get_FIELD_display(field)

_get_next_or_previous_by_FIELD(field, ...)

_get_next_or_previous_in_order(is_next)

_get_field_expression_map(meta[, exclude])

_get_unique_checks([exclude, ...])

Return a list of checks to perform.

_perform_unique_checks(unique_checks)

_perform_date_checks(date_checks)

_check_composite_pk()

_check_db_table_comment(databases)

_check_swappable()

Check if the swapped model exists.

_check_model()

_check_managers(**kwargs)

Perform all manager checks.

_check_fields(**kwargs)

Perform all field checks.

_check_m2m_through_same_relationship()

Check if no relationship model is used by more than one m2m field.

_check_id_field()

Check if id field is a primary key.

_check_field_name_clashes()

Forbid field shadowing in multi-table inheritance.

_check_column_name_clashes()

_check_model_name_db_lookup_clashes()

_check_property_name_related_field_accessor_clashes()

_check_single_primary_key()

_check_unique_together()

Check the value of "unique_together" option.

_check_indexes(databases)

_check_local_fields(fields, option)

_check_ordering()

Check "ordering" option -- is it a list of strings and do all fields exist?

_check_long_column_names(databases)

Check that any auto-generated column names are shorter than the limits for each database in which the model will be created.

_get_expr_references(expr)

_check_constraints(databases)


exception DoesNotExist
exception MultipleObjectsReturned
exception NotUpdated
get_resources_from_wialon(session: ~terminusgps.wialon.session.WialonSession, force: bool = False, flags: int = <DataFlag.RESOURCE_BASE: 1>, start: int = 0, end: int = 0) list[dict[str, Any]][source]

Returns a list of of customer Wialon resource dictionaries from the Wialon API.

Default Wialon resource dictionary format (flags=1):

key

type

desc

"mu"

int

Measurement system

"nm"

str

Resource name

"cls"

int

Superclass ID: ‘avl_resource’

"id"

int

Resource ID

"uacl"

int

User’s access rights

Parameters:
  • force (bool) – Whether to force a Wialon API call instead of using a cached response. Default is False (use cache).

  • flags (int) – Response flags. Default is 1.

  • start (int) – Start index. Default is 0.

  • end (int) – End index. Default is 0 (no limit).

Returns:

A list of Wialon resource dictionaries.

Return type:

list[dict[str, Any]]

get_units_from_wialon(resource_id: str | int, session: ~terminusgps.wialon.session.WialonSession, items_type: str = 'avl_unit', force: bool = False, flags: int = <DataFlag.RESOURCE_BASE: 1>, start: int = 0, end: int = 0) list[dict[str, Any]][source]

Returns a list of of customer Wialon unit dictionaries from the Wialon API.

Default Wialon unit dictionary format (flags=1):

key

type

desc

"mu"

int

Measurement system

"nm"

str

Unit name

"cls"

int

Superclass ID: ‘avl_unit’

"id"

int

Unit ID

"uacl"

int

User’s access rights

Parameters:
  • force (bool) – Whether to force a Wialon API call instead of using a cached response. Default is False (use cache).

  • flags (int) – Response flags. Default is 1.

  • start (int) – Start index. Default is 0.

  • end (int) – End index. Default is 0 (no limit).

Raises:

ValueError – If resource_id was a string and contained non-digit characters.

Returns:

A list of Wialon unit dictionaries.

Return type:

list[dict[str, Any]]

company

Company name. Optional.

Type:

str | None

date_format

Date format for notifications. Default is "%Y-%m-%d %H:%M:%S".

Type:

str

grand_total

Subscription grand total (subtotal + tax). Automatically generated.

Type:

Decimal

messages_count

Current number of notification executions this period. Default is 0.

Type:

int

messages_max

Maximum number of notification executions in a single period. Default is 500.

Type:

int

messages_max_base

Maximum base number of notification executions in a single period. Default is 500.

Type:

int

subscription

Associated subscription. Optional.

Type:

terminusgps_payments.models.Subscription | None

subtotal

Subscription current subtotal. Default is 60.00 ($60.00).

Type:

Decimal

tax

Subscription tax total. Automatically generated.

Type:

Decimal

tax_rate

Subscription tax rate. Default is 0.0825 (8.25%).

Type:

Decimal

user

Django user.

Type:

AbstractBaseUser

class terminusgps_notifications.models.WialonToken(*args, **kwargs)[source]

Wialon API token.

Public Data Attributes:

customer_id

customer

Associated customer.

Inherited from Model

pk

Public Methods:

__str__()

Returns '<customer email>'s WialonToken'.

name

Encrypted Wialon API token name.

flags

Wialon token flags.

id

A wrapper for a deferred-loading field.

objects

Inherited from Model

__init__(*args, **kwargs)

from_db(db, field_names, values)

__repr__()

Return repr(self).

__str__()

Return str(self).

__eq__(other)

Return self==value.

__hash__()

Return hash(self).

__reduce__()

Helper for pickle.

__getstate__()

Hook to allow choosing the attributes to pickle.

__setstate__(state)

get_deferred_fields()

Return a set containing names of deferred fields for this instance.

refresh_from_db([using, fields, from_queryset])

Reload field values from the database.

arefresh_from_db([using, fields, from_queryset])

serializable_value(field_name)

Return the value of the field name for this instance.

save(*[, force_insert, force_update, using, ...])

Save the current instance.

asave(*[, force_insert, force_update, ...])

save_base([raw, force_insert, force_update, ...])

Handle the parts of saving which should be done only once per save, yet need to be done in raw saves, too.

delete([using, keep_parents])

adelete([using, keep_parents])

prepare_database_save(field)

clean()

Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields.

validate_unique([exclude])

Check unique constraints on the model and raise ValidationError if any failed.

date_error_message(lookup_type, field_name, ...)

unique_error_message(model_class, unique_check)

get_constraints()

validate_constraints([exclude])

full_clean([exclude, validate_unique, ...])

Call clean_fields(), clean(), validate_unique(), and validate_constraints() on the model.

clean_fields([exclude])

Clean all fields and raise a ValidationError containing a dict of all validation errors if any occur.

check(**kwargs)

Inherited from AltersData

__init_subclass__(**kwargs)

This method is called when a class is subclassed.

Private Data Attributes:

_meta

Private Methods:

Inherited from Model

_get_pk_val([meta])

_set_pk_val(value)

_is_pk_set([meta])

_validate_force_insert(force_insert)

_save_parents(cls, using, update_fields, ...)

Save all the parents of cls using values from self.

_save_table([raw, cls, force_insert, ...])

Do the heavy-lifting involved in saving.

_do_update(base_qs, using, pk_val, values, ...)

Try to update the model.

_do_insert(manager, using, fields, ...)

Do an INSERT.

_assign_returned_values(returned_values, ...)

_prepare_related_fields_for_save(operation_name)

_get_FIELD_display(field)

_get_next_or_previous_by_FIELD(field, ...)

_get_next_or_previous_in_order(is_next)

_get_field_expression_map(meta[, exclude])

_get_unique_checks([exclude, ...])

Return a list of checks to perform.

_perform_unique_checks(unique_checks)

_perform_date_checks(date_checks)

_check_composite_pk()

_check_db_table_comment(databases)

_check_swappable()

Check if the swapped model exists.

_check_model()

_check_managers(**kwargs)

Perform all manager checks.

_check_fields(**kwargs)

Perform all field checks.

_check_m2m_through_same_relationship()

Check if no relationship model is used by more than one m2m field.

_check_id_field()

Check if id field is a primary key.

_check_field_name_clashes()

Forbid field shadowing in multi-table inheritance.

_check_column_name_clashes()

_check_model_name_db_lookup_clashes()

_check_property_name_related_field_accessor_clashes()

_check_single_primary_key()

_check_unique_together()

Check the value of "unique_together" option.

_check_indexes(databases)

_check_local_fields(fields, option)

_check_ordering()

Check "ordering" option -- is it a list of strings and do all fields exist?

_check_long_column_names(databases)

Check that any auto-generated column names are shorter than the limits for each database in which the model will be created.

_get_expr_references(expr)

_check_constraints(databases)


exception DoesNotExist
exception MultipleObjectsReturned
exception NotUpdated
customer

Associated customer.

Type:

TerminusgpsNotificationsCustomer

flags

Wialon token flags.

Type:

int

name

Encrypted Wialon API token name.

Type:

str

class terminusgps_notifications.models.WialonNotification(*args, **kwargs)[source]

Wialon notification.

exception DoesNotExist
exception MultipleObjectsReturned
exception NotUpdated
class WialonNotificationMethod(*values)[source]

Wialon notification method.

get_absolute_url() str[source]

Returns a URL pointing to the notification’s detail view.

get_actions() list[dict[str, Any]][source]

Returns a list of notification actions (act).

get_data_from_wialon(session: WialonSession) dict[str, Any][source]

Returns the notification data from Wialon using the Wialon API.

Notification data format:

key

type

desc

"id"

int

Notification ID

"n"

str

Notification name

"txt"

int

Notification text

"ta"

int

Activation time (UNIX timestamp)

"td"

int

Deactivation time (UNIX timestamp)

"ma"

int

Maximum number of alarms (0 = unlimited)

"mmtd"

int

Maximum time interval between messages (sec)

"cdt"

int

Alarm timeout (sec)

"mast"

int

Minimum duration of the alarm state (sec)

"mpst"

int

Minimum duration of previous state (sec)

"cp"

int

Control period relative to current time (sec)

"fl"

int

Notification flags

"tz"

int

Notification timezone

"la"

str

Notification language code

"ac"

int

Alarms count

"d"

str

Notification description

"sch"

dict

Notification schedule (see below)

"ctrl_sch"

dict

Notification control schedule (see below)

"un"

list

List of unit/unit group IDs

"act"

list

List of notification actions (see below)

"trg"

dict

Notification trigger (see below)

"ct"

int

Creation time (UNIX timestamp)

"mt"

int

Last modification time (UNIX timestamp)

Notification schedule/control schedule format:

key

type

desc

"f1"

int

Beginning of interval 1 (minutes from midnight)

"f2"

int

Beginning of interval 2 (minutes from midnight)

"t1"

int

End of interval 1 (minutes from midnight)

"t2"

int

End of interval 2 (minutes from midnight)

"m"

int

Mask of the days of the month (1: 20, 31: 230)

"y"

int

Mask of months (Jan: 20, Dec: 211)

"w"

int

Mask of days of the week (Mon: 20, Sun: 26)

"f"

int

Schedule flags

Notification action format (each item in the act list):

key

type

desc

"t"

str

Action type

"p"

dict

Action parameters

Notification trigger format:

key

type

desc

"t"

str

Trigger type

"p"

dict

Trigger parameters

Parameters:

session (WialonSession) – A valid Wialon API session.

Raises:

WialonAPIError – If something went wrong calling the Wialon API.

Returns:

The notification data from Wialon.

Return type:

dict[str, Any]

get_resource_name(session: WialonSession) str[source]

Returns the Wialon resource name.

Parameters:

session (WialonSession) – A valid Wialon API session.

Returns:

The Wialon resource name.

Return type:

str

get_text() str[source]

Returns the notification text (txt).

get_wialon_parameters(call_mode: str) dict[str, Any][source]

Returns parameters for Wialon notification API calls.

Parameters:

call_mode (str) – A Wialon API update notification call mode.

Returns:

A dictionary of Wialon API update notification parameters.

Return type:

dict[str, Any]

save(**kwargs) None[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.

update_in_wialon(call_mode: WialonNotificationUpdateCallModeType, session: WialonSession) dict[str, Any][source]

Updates the notification in Wialon.

Parameters:
  • call_mode (WialonNotificationUpdateCallMode) – Call mode to use when calling resource/update_notification.

  • session (WialonSession) – A valid Wialon API session.

Raises:

WialonAPIError – If something went wrong calling the Wialon API.

Returns:

A dictionary of notification data.

Return type:

dict[str, Any]

actions

Actions.

activation_time

Activation date/time. Optional.

Type:

datetime | None

activations

Activation count.

alarm_timeout

Alarm timeout in seconds. Default is 0. Max is 1800 (30 minutes in seconds).

Type:

int

control_period

Control period relative to current time in seconds. Default is 3600.

Options are:

value

desc

0

Any time

60

Last minute

600

Last 10 minutes

3600

Last hour

86400

Last day

control_schedule

Control schedule.

customer

Associated customer.

date_created

Date created.

deactivation_time

Deactivation date/time. Optional.

Type:

datetime | None

enabled

Whether the notification is enabled in Wialon.

flags

Flags. Default is 0.

Options are:

value

desc

0

Trigger on first message

1

Trigger on every message

2

Disabled

language

2-letter language code. Default is "en".

Options are:

value

desc

"en"

English

Type:

str

max_alarms

Maximum number of alarms (0 = unlimited). Default is 0.

Type:

int

max_message_interval

Max time interval between messages. Default is 3600.

Options are:

value

desc

0

Any time

60

1 minute

600

10 minutes

1800

30 minutes

3600

1 hour

21600

6 hours

43200

12 hours

86400

1 day

864000

10 days

Type:

int

message

Notification message. 1024 characters max.

Type:

str

method

Notification method. Default is "sms".

Options are:

value

desc

"sms"

Deliver via SMS

"voice"

Deliver via TTS voice

Type:

str

min_duration_alarm

Minimum duration of alarm state in seconds. Default is 0. Max is 86400 (1 day).

min_duration_prev

Minimum duration of previous state in seconds. Default is 0. Max is 86400 (1 day).

Type:

int

name

Notification name. 4 characters min. 64 characters max.

Type:

str

resource_id

Resource id.

resource_name

Resource name.

schedule

Schedule.

text

Text.

timezone

Timezone.

trigger_parameters

Trigger parameters.

trigger_type

Trigger type.

unit_list

List of Wialon units.

wialon_id

Wialon id.