|
8 | 8 | from django.conf import settings |
9 | 9 | from django.contrib.gis.geos import GEOSGeometry |
10 | 10 | from django.core.files.base import ContentFile |
11 | | -from pydantic import BaseModel, ValidationInfo, model_validator |
| 11 | +from pydantic import BaseModel |
12 | 12 | from pyfirebase_mapswipe import extended_models as firebase_ext_models |
13 | 13 | from pyfirebase_mapswipe import models as firebase_models |
14 | 14 | from ulid import ULID |
@@ -39,29 +39,6 @@ class TileMapServiceProjectProperty(base_project.BaseProjectProperty): |
39 | 39 | tile_server_property: RasterTileServerConfig |
40 | 40 | aoi_geometry: custom_fields.PydanticId |
41 | 41 |
|
42 | | - @model_validator(mode="after") |
43 | | - def check_aoi_geometry_exists(self, info: ValidationInfo) -> typing.Self: |
44 | | - if not isinstance(info.context, dict): |
45 | | - # Skipping validation in case context is not defined |
46 | | - return self |
47 | | - |
48 | | - project_id = info.context.get("project_id") |
49 | | - asset_exists = ( |
50 | | - ProjectAsset.usable_objects() |
51 | | - .filter( |
52 | | - id=self.aoi_geometry, |
53 | | - type=AssetTypeEnum.INPUT, |
54 | | - input_type=ProjectAssetInputTypeEnum.AOI_GEOMETRY, |
55 | | - project_id=project_id, |
56 | | - ) |
57 | | - .exists() |
58 | | - ) |
59 | | - |
60 | | - # FIXME(tnagorra): Handle error |
61 | | - if not asset_exists: |
62 | | - raise ValueError(f"ProjectAsset with id {self.aoi_geometry} is invalid or does not exist.") |
63 | | - return self |
64 | | - |
65 | 42 |
|
66 | 43 | class TileMapServiceProjectTaskGroupProperty(base_project.BaseProjectTaskGroupProperty): |
67 | 44 | x_max: int |
@@ -92,6 +69,15 @@ class TileMapServiceBaseProject[ |
92 | 69 | def __init__(self, project: Project): |
93 | 70 | super().__init__(project) |
94 | 71 |
|
| 72 | + @typing.override |
| 73 | + def get_aoi_geometry_asset(self) -> ProjectAsset | None: |
| 74 | + return ProjectAsset.usable_objects().get( |
| 75 | + id=int(self.project_type_specifics.aoi_geometry), |
| 76 | + type=ProjectAsset.Type.INPUT, |
| 77 | + input_type=ProjectAssetInputTypeEnum.AOI_GEOMETRY, |
| 78 | + project_id=self.project.pk, |
| 79 | + ) |
| 80 | + |
95 | 81 | @typing.override |
96 | 82 | def post_create_groups(self): |
97 | 83 | # NOTE: Create a geojson from the tasks (useful for tutorial creation) |
@@ -142,8 +128,8 @@ def get_feature(task: ProjectTask): |
142 | 128 | created_by=self.project.modified_by, |
143 | 129 | modified_by=self.project.modified_by, |
144 | 130 | ) |
145 | | - self.project.project_type_specific_output = asset |
146 | | - self.project.save(update_fields=("project_type_specific_output",)) |
| 131 | + self.project.project_type_specific_output_asset = asset |
| 132 | + self.project.save(update_fields=("project_type_specific_output_asset",)) |
147 | 133 |
|
148 | 134 | # TODO(thenav56): Calculate centroid, bounding box, etc. |
149 | 135 | # TODO(thenav56): Calculate: total_area, time_spent_max_allowed |
@@ -222,13 +208,9 @@ def validate(self): |
222 | 208 | """Validate project before creating groups.""" |
223 | 209 | self.project.update_processing_status(Project.ProcessingStatus.VALIDATING_GEOMETRY, True) |
224 | 210 |
|
225 | | - aoi_asset = ProjectAsset.usable_objects().get( |
226 | | - id=self.project_type_specifics.aoi_geometry, |
227 | | - type=AssetTypeEnum.INPUT, |
228 | | - input_type=ProjectAssetInputTypeEnum.AOI_GEOMETRY, |
229 | | - mimetype=AssetMimetypeEnum.GEOJSON, |
230 | | - project_id=self.project.pk, |
231 | | - ) |
| 211 | + aoi_asset = self.project.aoi_geometry_input_asset |
| 212 | + if not aoi_asset: |
| 213 | + raise Exception("Could not find AOI geometry asset") |
232 | 214 |
|
233 | 215 | extension = Path(aoi_asset.file.name).suffix |
234 | 216 | with tempfile.NamedTemporaryFile(suffix=extension, dir=settings.TEMP_DIR) as temp_file: |
|
0 commit comments