Skip to content

Commit

Permalink
added and updated migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
DraKen0009 committed Dec 28, 2024
1 parent 228dbe6 commit a7a3279
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
2 changes: 1 addition & 1 deletion camera/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('facility', '0468_alter_asset_asset_class_alter_asset_meta'),
('facility', '0469_alter_asset_asset_class_alter_asset_meta'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

Expand Down
34 changes: 34 additions & 0 deletions camera/migrations/0004_assetbedboundary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 5.1.3 on 2024-12-28 18:51

import django.db.models.deletion
import uuid
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('camera', '0003_alter_positionpreset_created_date_and_more'),
('facility', '0469_alter_asset_asset_class_alter_asset_meta'),
]

operations = [
migrations.CreateModel(
name='AssetBedBoundary',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('external_id', models.UUIDField(db_index=True, default=uuid.uuid4, unique=True)),
('created_date', models.DateTimeField(auto_now_add=True, db_index=True, null=True)),
('modified_date', models.DateTimeField(auto_now=True, db_index=True, null=True)),
('deleted', models.BooleanField(db_index=True, default=False)),
('x0', models.IntegerField()),
('y0', models.IntegerField()),
('x1', models.IntegerField()),
('y1', models.IntegerField()),
('asset_bed', models.OneToOneField(on_delete=django.db.models.deletion.PROTECT, related_name='assetbed_camera_boundary', to='facility.assetbed')),
],
options={
'abstract': False,
},
),
]
1 change: 1 addition & 0 deletions camera/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from camera.models.asset_bed_boundary import AssetBedBoundary
15 changes: 13 additions & 2 deletions camera/models/asset_bed_boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class AssetBedBoundary(BaseModel):

def save(self, *args, **kwargs):
if self.asset_bed.asset.asset_class != "ONVIF":
raise ValidationError("AssetBedBoundary is only applicable for AssetBeds with ONVIF assets.")
error="AssetBedBoundary is only applicable for AssetBeds with ONVIF assets."
raise ValidationError(error)

data = {
"x0": self.x0,
Expand All @@ -32,6 +33,16 @@ def save(self, *args, **kwargs):
validate(instance=data, schema=ASSET_BED_BOUNDARY_SCHEMA)
except JSONSchemaValidationError as e:
error=f"Invalid data: {str(e)}"
raise ValidationError(error)
raise ValidationError(error) from e

super().save(*args, **kwargs)


def to_dict(self):
"""Serialize boundary data as a dictionary."""
return {
"x0": self.x0,
"y0": self.y0,
"x1": self.x1,
"y1": self.y1,
}
5 changes: 3 additions & 2 deletions camera/utils/onvif.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ def handle_action(self, **kwargs: ActionParams):
if not asset_bed:
raise ValidationError({"asset_bed_id": "Invalid Asset Bed ID"})

if asset_bed.boundary:
request_body.update({"boundary": asset_bed.boundary})
if hasattr(asset_bed, "assetbed_camera_boundary"):
boundary = asset_bed.assetbed_camera_boundary.to_dict()
request_body.update({"boundary": boundary})
return self.api_post(self.get_url("relativeMove"), request_body, timeout)

if action_type == self.OnvifActions.GET_STREAM_TOKEN.value:
Expand Down

0 comments on commit a7a3279

Please sign in to comment.