Source code for festivalgrid.models

import importlib

from django.db import models


[docs]class APIUser(models.Model): username = models.CharField(max_length=40) password = models.CharField(max_length=40) token = models.CharField(max_length=40, null=True, blank=True) class Meta: verbose_name_plural = "API Users" def __str__(self): return self.username
[docs]class Node(models.Model): name = models.CharField(max_length=100, blank=True) device = models.ForeignKey("Device", on_delete=models.SET_NULL, null=True, blank=True, related_name="nodes") warning_level = models.IntegerField(null=True, blank=True, default=2500) shutdown_level = models.IntegerField(null=True, blank=True, default=3000) cut_power = models.BooleanField(default=False) latitude = models.DecimalField(max_digits=20, decimal_places=16, null=True, blank=True) longitude = models.DecimalField(max_digits=20, decimal_places=16, null=True, blank=True)
[docs] def __init__(self, *args, **kwargs): super(Node, self).__init__(*args, **kwargs) self.__original_cut_power = self.cut_power
[docs] def save(self, force_insert=False, force_update=False, *args, **kwargs): if self.cut_power != self.__original_cut_power: self.device.get_template().set_cut_power(self.cut_power) self.__original_cut_power = self.cut_power super(Node, self).save(force_insert, force_update, *args, **kwargs)
def __str__(self): return self.name if self.name else "Node #" + str(self.pk)
[docs]class Device(models.Model): name = models.CharField(max_length=100) template = models.CharField(max_length=100) mqtt_topic = models.CharField(max_length=100, null=True, blank=True) ip = models.GenericIPAddressField(null=True, blank=True) hostname = models.CharField(max_length=100, null=True, blank=True) mac = models.CharField(max_length=100, null=True, blank=True)
[docs] def get_template(self): try: return self._template except AttributeError: self._template = importlib.import_module( "festivalgrid.device_templates." + str(self.template)).TEMPLATE_CLASS(self) return self._template
def __str__(self): return "%s (%s)" % (self.name, self.template)
[docs]class Timer(models.Model): ACTION_CHOICES = ( ("ON", "On"), ("OFF", "Off"), ("TOGGLE", "Toggle"), ) name = models.CharField(max_length=100, null=True, blank=True) node = models.ForeignKey(Node, on_delete=models.CASCADE, related_name="timers") time = models.TimeField() # date = models.DateField(null=True, blank=True) action = models.CharField(max_length=6, choices=ACTION_CHOICES) enabled = models.BooleanField(default=False) def __str__(self): return self.name if self.name else self.node + " " + self.pk
[docs]class Connection(models.Model): plug = models.ForeignKey(Node, on_delete=models.SET_NULL, null=True, blank=True, related_name="plugs") socket = models.ForeignKey(Node, on_delete=models.SET_NULL, null=True, blank=True, related_name="sockets") geojson = models.TextField(null=True, blank=True)
[docs]class ImageLayer(models.Model): image = models.FileField(null=True, blank=True) latitude1 = models.DecimalField(max_digits=20, decimal_places=16, null=True, blank=True) longitude1 = models.DecimalField(max_digits=20, decimal_places=16, null=True, blank=True) latitude2 = models.DecimalField(max_digits=20, decimal_places=16, null=True, blank=True) longitude2 = models.DecimalField(max_digits=20, decimal_places=16, null=True, blank=True) latitude3 = models.DecimalField(max_digits=20, decimal_places=16, null=True, blank=True) longitude3 = models.DecimalField(max_digits=20, decimal_places=16, null=True, blank=True) def __str__(self): return "%s" % str(self.image)
from . import signals