-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added boundary model and validations #5
Open
DraKen0009
wants to merge
3
commits into
main
Choose a base branch
from
adding-boundary-model-and-validations-for-onvif-asset
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from camera.models.asset_bed_boundary import AssetBedBoundary | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. importing it, so that migrations can be created |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from django.db import models | ||
from django.core.exceptions import ValidationError | ||
from jsonschema import validate | ||
from jsonschema.exceptions import ValidationError as JSONSchemaValidationError | ||
from camera.models.json_schema.boundary import ASSET_BED_BOUNDARY_SCHEMA | ||
from care.facility.models import AssetBed | ||
from care.utils.models.base import BaseModel | ||
|
||
|
||
|
||
class AssetBedBoundary(BaseModel): | ||
asset_bed = models.OneToOneField( | ||
AssetBed, on_delete=models.PROTECT, related_name="assetbed_camera_boundary" | ||
) | ||
x0 = models.IntegerField() | ||
y0 = models.IntegerField() | ||
x1 = models.IntegerField() | ||
y1 = models.IntegerField() | ||
|
||
def save(self, *args, **kwargs): | ||
if self.asset_bed.asset.asset_class != "ONVIF": | ||
error="AssetBedBoundary is only applicable for AssetBeds with ONVIF assets." | ||
raise ValidationError(error) | ||
|
||
data = { | ||
"x0": self.x0, | ||
"y0": self.y0, | ||
"x1": self.x1, | ||
"y1": self.y1, | ||
} | ||
|
||
try: | ||
validate(instance=data, schema=ASSET_BED_BOUNDARY_SCHEMA) | ||
except JSONSchemaValidationError as e: | ||
error=f"Invalid data: {str(e)}" | ||
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
ASSET_BED_BOUNDARY_SCHEMA = { | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"properties": { | ||
"x0": {"type": "number"}, | ||
"y0": {"type": "number"}, | ||
"x1": {"type": "number"}, | ||
"y1": {"type": "number"}, | ||
}, | ||
"required": ["x0", "y0", "x1", "y1"], | ||
"additionalProperties": False, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated the branch name according to the respective branch on core app.
This will be fixed once we have merged the plugin PR in core care