Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 625c591122 | |||
| f551763798 |
+15
-10
@@ -113,7 +113,7 @@ class Geometry(BaseResource):
|
|||||||
objs (list): The list of objects
|
objs (list): The list of objects
|
||||||
"""
|
"""
|
||||||
objs = []
|
objs = []
|
||||||
|
stop_searching = False
|
||||||
# Some related data sets can be processed rather easily
|
# Some related data sets can be processed rather easily
|
||||||
regular_sets = [
|
regular_sets = [
|
||||||
self.intervention_set,
|
self.intervention_set,
|
||||||
@@ -129,15 +129,20 @@ class Geometry(BaseResource):
|
|||||||
else:
|
else:
|
||||||
objs += set_objs
|
objs += set_objs
|
||||||
|
|
||||||
# ... but we need a special treatment for compensations, since they can be deleted directly OR inherit their
|
stop_searching = len(objs) > 0
|
||||||
# de-facto-deleted status from their deleted parent intervention
|
if stop_searching:
|
||||||
comp_objs = self.compensation_set.filter(
|
break
|
||||||
Q(deleted=None) & Q(intervention__deleted=None)
|
|
||||||
)
|
if not stop_searching:
|
||||||
if limit_to_attrs:
|
# ... but we need a special treatment for compensations, since they can be deleted directly OR inherit their
|
||||||
objs += comp_objs.values(*limit_to_attrs)
|
# de-facto-deleted status from their deleted parent intervention
|
||||||
else:
|
comp_objs = self.compensation_set.filter(
|
||||||
objs += comp_objs
|
Q(deleted=None) | Q(intervention__deleted=None)
|
||||||
|
)
|
||||||
|
if limit_to_attrs:
|
||||||
|
objs += comp_objs.values(*limit_to_attrs)
|
||||||
|
else:
|
||||||
|
objs += comp_objs
|
||||||
return objs
|
return objs
|
||||||
|
|
||||||
def get_data_object(self, limit_to_attrs: list = None):
|
def get_data_object(self, limit_to_attrs: list = None):
|
||||||
|
|||||||
@@ -85,12 +85,6 @@ class GeometryTestCase(BaseTestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_get_data_objects(self):
|
def test_get_data_objects(self):
|
||||||
num_objs_with_geom = 0
|
|
||||||
self.assertEqual(
|
|
||||||
len(self.geom_1.get_data_objects()),
|
|
||||||
num_objs_with_geom
|
|
||||||
)
|
|
||||||
|
|
||||||
objs = [
|
objs = [
|
||||||
self.intervention,
|
self.intervention,
|
||||||
self.compensation,
|
self.compensation,
|
||||||
@@ -98,16 +92,13 @@ class GeometryTestCase(BaseTestCase):
|
|||||||
self.ema,
|
self.ema,
|
||||||
]
|
]
|
||||||
for obj in objs:
|
for obj in objs:
|
||||||
obj.geometry = self.geom_1
|
if not obj.geometry:
|
||||||
obj.save()
|
obj.geometry = Geometry.objects.create(geom=self.create_dummy_geometry())
|
||||||
|
obj.save()
|
||||||
|
|
||||||
num_objs_with_geom += 1
|
data_objs = obj.geometry.get_data_objects()
|
||||||
geom_objs = self.geom_1.get_data_objects()
|
self.assertEqual(len(data_objs), 1)
|
||||||
self.assertEqual(
|
self.assertIn(obj, data_objs)
|
||||||
len(geom_objs),
|
|
||||||
num_objs_with_geom
|
|
||||||
)
|
|
||||||
self.assertIn(obj, geom_objs)
|
|
||||||
|
|
||||||
def test_as_feature_collection(self):
|
def test_as_feature_collection(self):
|
||||||
geometry = self.geom_1.geom
|
geometry = self.geom_1.geom
|
||||||
|
|||||||
Reference in New Issue
Block a user