Files
cetana-backend/apps/live_monitoring/models.py
T

50 lines
2.0 KiB
Python

from django.db import models
from apps.core.models import TimeStampedModel, UUIDModel
from apps.live_monitoring.protocols import DEFAULT_PROTOCOL, PROTOCOL_CHOICES
class Camera(UUIDModel, TimeStampedModel):
name = models.CharField(max_length=200)
facility = models.CharField(max_length=200, blank=True)
processing_line = models.CharField(max_length=200, blank=True)
# Blank = inherit camera.default_protocol from Live Monitoring settings.
protocol = models.CharField(
max_length=32,
choices=PROTOCOL_CHOICES,
blank=True,
default="",
help_text="Streaming standard. Leave blank to use the system default protocol.",
)
# CharField (not URLField) so RTSP/RTMP/SRT URLs are accepted.
stream_url = models.CharField(max_length=1000)
# Never expose credentials to the frontend; keep auth config server-side.
# Expected keys: username, password, token, auth_method, host, port, path, transport…
auth_config = models.JSONField(default=dict, blank=True)
active = models.BooleanField(default=True)
def __str__(self) -> str:
return self.name
def resolved_protocol(self) -> str:
if self.protocol:
return self.protocol
from apps.core.settings_service import SettingsService
value = SettingsService().get("camera.default_protocol", DEFAULT_PROTOCOL)
return value if value in dict(PROTOCOL_CHOICES) else DEFAULT_PROTOCOL
class LiveStream(UUIDModel, TimeStampedModel):
camera = models.ForeignKey(Camera, on_delete=models.CASCADE, related_name="streams")
name = models.CharField(max_length=200, blank=True)
active = models.BooleanField(default=True)
def __str__(self) -> str:
return self.name or self.camera.name
class WorkflowStepCamera(UUIDModel):
step = models.ForeignKey("workflows.WorkflowStep", on_delete=models.CASCADE, related_name="cameras")
camera = models.ForeignKey(Camera, on_delete=models.CASCADE, related_name="workflow_steps")