# ---------------------- # Public Lighting Models # ---------------------- from django.contrib.gis.db import models from django.urls import reverse from django.utils.translation import gettext_lazy as _ from assets.models import AbstractLocation, AbstractAsset, AbstractGeoAsset, AbstractAssetModel from common.models import Municipality, Document from common.storages import PrivateMediaStorage from assets.models.trafficlights import TrafficLightPole private_storage = PrivateMediaStorage() # Public Lighting Street class PublicLightingStreet(AbstractLocation): geom = models.MultiPolygonField(srid=3812, null=True,blank=True) municipality = models.ForeignKey(Municipality, on_delete=models.SET_NULL, null=True, blank=True, related_name="publiclighting_streets") def get_active_assets(self): # Retrieve associated poles poles = self.poles.filter(status='active') light_fixtures = self.light_fixtures.filter(status='active') return { "poles": poles, "light_fixtures": light_fixtures, } def get_all_assets(self): # Retrieve associated poles poles = self.poles.all() light_fixtures = self.light_fixtures.all() return { "poles": poles, "light_fixtures": light_fixtures, } def get_direct_child_assets(self): # Retrieve associated poles poles = self.poles.all() light_fixtures = self.light_fixtures.all() return { "poles": poles, "light_fixtures": light_fixtures, } def get_absolute_url(self): return reverse("assets:publiclighting_streets_detail", kwargs={"street_id": self.id}) TL_DOCUMENT_TYPE_CHOICES = ( ('as_built', 'As Built'), ('other', 'Autre'), ) class PublicLightingStreetDocument(Document): street = models.ForeignKey(PublicLightingStreet, on_delete=models.CASCADE, related_name="documents", verbose_name="Associated Street") file = models.FileField(upload_to="assets_documents/publiclighting/", storage=private_storage, verbose_name="Fichier", max_length=255) thumbnail = models.ImageField(upload_to="assets_documents/publiclighting/", storage=private_storage, null=True, blank=True, max_length=255) document_type = models.CharField(max_length=50, choices=TL_DOCUMENT_TYPE_CHOICES, default='other', verbose_name="Type de document") # Public Lighting Pole Model class PublicLightingPoleModel(AbstractAssetModel): color = models.CharField(max_length=200, null=True,blank=True) ral = models.CharField(max_length=200, null=True,blank=True) height = models.FloatField(null=True,blank=True) # Public Lighting Pole class PublicLightingPole(AbstractGeoAsset): model = models.ForeignKey(PublicLightingPoleModel, on_delete=models.PROTECT) street = models.ForeignKey(PublicLightingStreet, related_name="poles", on_delete=models.PROTECT) class Meta: indexes = [ models.Index(fields=["code"]), ] verbose_name = _("Public lighting pole") verbose_name_plural = _("Public lighting poles") def save(self, *args, **kwargs): super().save(*args, **kwargs) for radar in self.radars.all(): radar.save() def get_absolute_url(self): return reverse('assets:publiclighting_assets_detail', kwargs={'asset_model': 'publiclightingpole', 'asset_id':self.id}) # Public Lighting Light Fixture Model (Luminaire) class PublicLightingLightFixtureModel(AbstractAssetModel): color = models.CharField(max_length=200, null=True,blank=True) # Public Lighting Fixture (Luminaire) class PublicLightingLightFixture(AbstractGeoAsset): model = models.ForeignKey(PublicLightingLightFixtureModel, on_delete=models.PROTECT, null=True, blank=True) pole = models.ForeignKey(PublicLightingPole, related_name="light_fixtures", on_delete=models.SET_NULL, null=True, blank=True) traffic_light_pole = models.ForeignKey(TrafficLightPole, related_name="light_fixtures", on_delete=models.SET_NULL, null=True, blank=True) street = models.ForeignKey(PublicLightingStreet, related_name="light_fixtures", on_delete=models.PROTECT) class Meta: indexes = [ models.Index(fields=["code"]), ] verbose_name = _("Luminaire") verbose_name_plural = _("Luminaires") def get_absolute_url(self): return reverse('assets:publiclighting_assets_detail', kwargs={'asset_model': 'publiclightinglightfixture', 'asset_id':self.id}) # Public Lighting Electrical Cabinet Model class PublicLightingElectricalCabinetModel(AbstractAssetModel): width = models.FloatField(null=True, blank=True, verbose_name="Largeur (cm)") height = models.FloatField(null=True, blank=True, verbose_name="Hauteur (cm)") depth = models.FloatField(null=True, blank=True, verbose_name="Profondeur (cm)") ip_rating = models.CharField(max_length=10, null=True, blank=True, verbose_name="Indice de protection IP") # Public Lighting Electrical Cabinet class PublicLightingElectricalCabinet(AbstractGeoAsset): model = models.ForeignKey(PublicLightingElectricalCabinetModel, on_delete=models.PROTECT) street = models.ForeignKey(PublicLightingStreet, related_name="electrical_cabinets", on_delete=models.PROTECT) ean_code = models.CharField(max_length=50, null=True, blank=True, verbose_name="Code EAN") power_supply = models.CharField(max_length=100, null=True, blank=True, verbose_name="Alimentation électrique") meter_number = models.CharField(max_length=100, null=True, blank=True, verbose_name="Numéro de compteur") number_of_circuits = models.IntegerField(null=True, blank=True, verbose_name="Nombre de circuits") class Meta: indexes = [ models.Index(fields=["code"]), ] def get_absolute_url(self): return reverse('assets:publiclighting_assets_detail', kwargs={'asset_model': 'publiclightingelectricalcabinet', 'asset_id':self.id})