Skip to content

models

sensor.models ¤

Classes¤

PermissionsBase ¤

Bases: Model

Base model for models that require permissions.

Functions¤
set_model_permissions() classmethod ¤

Set model-level add permissions.

Source code in management/models.py
76
77
78
79
@classmethod
def set_model_permissions(cls):
    """Set model-level add permissions."""
    apply_add_permissions_to_standard_group(cls)
set_object_permissions() ¤

Set object-level delete, change and view permissions.

Source code in management/models.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
def set_object_permissions(self):
    """Set object-level delete, change and view permissions."""
    delete, change, view, add = _get_perm_codenames(self.__class__)
    standard_group = Group.objects.get(name="Standard")
    anonymous_user = get_anonymous_user()

    # View permissions based on permissions level
    if self.visibility in ["public", "internal"]:
        assign_perm(view, standard_group, self)
        assign_perm(view, anonymous_user, self)
        if self.owner:
            remove_perm(view, self.owner, self)
    elif self.visibility == "private" and self.owner:
        remove_perm(view, standard_group, self)
        remove_perm(view, anonymous_user, self)
        if self.owner:
            assign_perm(view, self.owner, self)

    # Assign change and delete permissions for owner
    for perm in [change, delete]:
        remove_perm(perm, standard_group, self)
        remove_perm(perm, anonymous_user, self)
        if self.owner:
            assign_perm(perm, self.owner, self)

Sensor ¤

Bases: PermissionsBase

Specific sensor details.

Attributes:

Name Type Description
sensor_id int

Primary key, sensor id.

code

(str) sensor code.

sensor_type SensorType

sensor type.

sensor_brand SensorBrand

sensor brand.

model str

specific model of the sensor.

serial str

serial number of the sensor.

status bool

sensor status.

Functions¤
__str__() ¤

Return the sensor code.

Source code in sensor/models.py
112
113
114
def __str__(self) -> str:
    """Return the sensor code."""
    return str(self.code)
get_absolute_url() ¤

Return the absolute url of the sensor.

Source code in sensor/models.py
116
117
118
def get_absolute_url(self) -> str:
    """Return the absolute url of the sensor."""
    return reverse("sensor:sensor_detail", kwargs={"pk": self.pk})

SensorBrand ¤

Bases: PermissionsBase

Brand of the sensor, eg. Davis, Texas Electronics, etc.

Attributes:

Name Type Description
brand_id

int, primary key, sensor brand id.

name

str, sensor brand name.

Functions¤
__str__() ¤

Return the brand name.

Source code in sensor/models.py
52
53
54
def __str__(self) -> str:
    """Return the brand name."""
    return str(self.name)
get_absolute_url() ¤

Return the absolute url of the sensor brand.

Source code in sensor/models.py
56
57
58
def get_absolute_url(self) -> str:
    """Return the absolute url of the sensor brand."""
    return reverse("sensor:brand_detail", kwargs={"pk": self.pk})

SensorType ¤

Bases: PermissionsBase

Type of sensor, eg. pluviometric, wind sensor, etc.

Attributes:

Name Type Description
sensor_type_id

int, primary key, sensor type id.

name

str, sensor type name.

Functions¤
__str__() ¤

Return the sensor type name.

Source code in sensor/models.py
32
33
34
def __str__(self) -> str:
    """Return the sensor type name."""
    return str(self.name)
get_absolute_url() ¤

Return the absolute url of the sensor type.

Source code in sensor/models.py
36
37
38
def get_absolute_url(self) -> str:
    """Return the absolute url of the sensor type."""
    return reverse("sensor:type_detail", kwargs={"pk": self.pk})