summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorQuentinAndre <quentin.andre@imt-atlantique.net>2021-08-19 09:43:52 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2021-11-16 17:04:41 +0100
commit645d1e0b8e1bf51757e360624a239c2ccd7828ea (patch)
tree8f588db5bbf3ef36ec3479aca10a3224677a04ab /ishtar_common
parent8bd44a470f51adafa5ae832e92a43da698bf0eb2 (diff)
downloadIshtar-645d1e0b8e1bf51757e360624a239c2ccd7828ea.tar.bz2
Ishtar-645d1e0b8e1bf51757e360624a239c2ccd7828ea.zip
test_geo_items works and manual tests work for ui
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/templates/ishtar/blocks/sheet_geo_items.html43
-rw-r--r--ishtar_common/templates/ishtar/blocks/sheet_simple_map.html31
-rw-r--r--ishtar_common/tests.py177
3 files changed, 174 insertions, 77 deletions
diff --git a/ishtar_common/templates/ishtar/blocks/sheet_geo_items.html b/ishtar_common/templates/ishtar/blocks/sheet_geo_items.html
index 3d76a5aa5..1c45b5d9f 100644
--- a/ishtar_common/templates/ishtar/blocks/sheet_geo_items.html
+++ b/ishtar_common/templates/ishtar/blocks/sheet_geo_items.html
@@ -1,60 +1,43 @@
{% load i18n window_field %}{% if PROFILE.mapping %}
{% if geo_item.point_2d or geo_item.multi_polygon %}
+{% load ids_display_geo_items %}
<dl class="col-12">
<dt>{% trans "Display geo items" %}</dt>
<dd>
<fieldset>
{% if geo_item.SLUG == "operation" %}
- <input type="checkbox" name="display-cr-for-ope" id="display-cr-for-ope">
- <label for="display-cr-for-ope">{% trans "Display context records" %}</label>
- <input type="checkbox" name="display-bf-for-ope" id="display-bf-for-ope">
- <label for="display-bf-for-ope">{% trans "Display base finds" %}</label>
- {% else %}
- <input type="checkbox" name="display-bf-for-cr" id="display-bf-for-cr">
- <label for="display-bf-for-cr">{% trans "Display base finds" %}</label>
+ <input type="checkbox" id="disp-cr-for-{{geo_item.SLUG}}-{{geo_item.pk}}">
+ <label for="disp-cr-for-{{geo_item.SLUG}}-{{geo_item.pk}}">{% trans "Display context records" %}</label>
{% endif %}
+ <input type="checkbox" id="disp-bf-for-{{geo_item.SLUG}}-{{geo_item.pk}}">
+ <label for="disp-bf-for-{{geo_item.SLUG}}-{{geo_item.pk}}">{% trans "Display base finds" %}</label>
</fieldset>
</dd>
<dd>
- {% if geo_item.SLUG == "operation" %}
- <label for="get-poly-ope" id="label-get-poly-ope">{% trans "Geometry: " %}</label>
- <select name="get-poly-ope" id="get-poly-ope">
+ <label for="get-poly-for-{{geo_item.SLUG}}-{{geo_item.pk}}" id="get-poly-label-for-{{geo_item.SLUG}}-{{geo_item.pk}}">{% trans "Geometry: " %}</label>
+ <select id="get-poly-for-{{geo_item.SLUG}}-{{geo_item.pk}}">
<option value="polygons" selected="selected">{% trans "Display polygons" %}</option>
<option value="points">{% trans "Display points" %}</option>
</select>
- {% else %}
- <label for="get-poly-cr" id="label-get-poly-cr">{% trans "Geometry: " %}</label>
- <select name="get-poly-cr" id="get-poly-cr">
- <option value="polygons" selected="selected">{% trans "Display polygons" %}</option>
- <option value="points">{% trans "Display points" %}</option>
- </select>
- {% endif %}
</dd>
</dl>
<script>
const hide_get_polygons = function() {
- {% if geo_item.SLUG == "operation" %}
- const disp_cr = $("#display-cr-for-ope");
- const disp_bf = $("#display-bf-for-ope");
- const get_poly = $("#get-poly-ope");
- const label = $("#label-get-poly-ope");
- {% else %}
- const disp_cr = null;
- const disp_bf = $("#display-bf-for-cr");
- const get_poly = $("#get-poly-cr");
- const label = $("#label-get-poly-cr");
- {% endif %}
+ const disp_cr = $("#disp-cr-for-{{geo_item.SLUG}}-{{geo_item.pk}}");
+ const disp_bf = $("#disp-bf-for-{{geo_item.SLUG}}-{{geo_item.pk}}");
+ const get_poly = $("#get-poly-for-{{geo_item.SLUG}}-{{geo_item.pk}}");
+ const label = $("#get-poly-label-for-{{geo_item.SLUG}}-{{geo_item.pk}}");
get_poly.hide();
label.hide();
const display_get_poly = function () {
- if (disp_bf.prop('checked') || ((disp_cr != null) && disp_cr.prop('checked'))) {
+ if (disp_bf.prop('checked') || ((disp_cr.length > 0) && disp_cr.prop('checked'))) {
get_poly.show();
label.show();
} else {
get_poly.hide();
label.hide();}
}
- if (disp_cr != null) {
+ if (disp_cr.length > 0) {
disp_cr.change( display_get_poly );
}
disp_bf.change( display_get_poly )
diff --git a/ishtar_common/templates/ishtar/blocks/sheet_simple_map.html b/ishtar_common/templates/ishtar/blocks/sheet_simple_map.html
index b44eb5724..a472c8b07 100644
--- a/ishtar_common/templates/ishtar/blocks/sheet_simple_map.html
+++ b/ishtar_common/templates/ishtar/blocks/sheet_simple_map.html
@@ -1,5 +1,6 @@
{% if PROFILE.mapping %}
{% if geo_item.point_2d or geo_item.multi_polygon %}
+{% load ids_display_geo_items %}
<div class="col-12 col-lg-6 flex-wrap">
<div class="window-map" id="map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}">
</div>
@@ -21,23 +22,25 @@ disp_map();
{% if geo_item.SLUG == "operation" or geo_item.SLUG == "contextrecord" %}
const disp_geo_items = function(disp_cr, disp_bf, get_polygons) {
- const get_poly = (get_polygons === "polygons");
- let url = null;
- if (get_poly) {
- url = "{% url 'api-get-geo-polygons' %}";
+ if (disp_cr || disp_bf) {
+ const get_poly = (get_polygons === "polygons");
+ let url = null;
+ if (get_poly) {
+ url = "{% url 'api-get-geo-polygons' %}";
+ }
+ else {
+ url = "{% url 'api-get-geo-points' %}";
+ }
+ display_geo_items("map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}", url, "{{geo_item.SLUG}}",
+ "{{geo_item.pk}}", disp_cr, disp_bf, get_poly);
}
- else {
- url = "{% url 'api-get-geo-points' %}";
- }
- display_geo_items("map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}", url, "{{geo_item.SLUG}}",
- "{{geo_item.pk}}", disp_cr, disp_bf, get_poly);
}
-
let geo_items_displayed_once = false;
+const disp_bf = $("#disp-bf-for-{{geo_item.SLUG}}-{{geo_item.pk}}");
+const get_polygons = $("#get-poly-for-{{geo_item.SLUG}}-{{geo_item.pk}}");
+
{% if geo_item.SLUG == "operation" %}
-const disp_cr = $("#display-cr-for-ope");
-const disp_bf = $("#display-bf-for-ope");
-const get_polygons = $("#get-poly-ope");
+const disp_cr = $("#disp-cr-for-{{geo_item.SLUG}}-{{geo_item.pk}}");
const event_func_disp_geo_items = function () {
if (geo_items_displayed_once) {
disp_map();
@@ -52,8 +55,6 @@ get_polygons.change( function () {
disp_geo_items(disp_cr.prop('checked'), disp_bf.prop('checked'), get_polygons.val());
})
{% else %}
-const disp_bf = $("#display-bf-for-cr");
-const get_polygons = $("#get-poly-cr");
const event_func_disp_geo_items = function () {
if (geo_items_displayed_once) {
disp_map();
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index c8bbf4342..348166069 100644
--- a/ishtar_common/tests.py
+++ b/ishtar_common/tests.py
@@ -2691,6 +2691,8 @@ class IshtarBasicTest(TestCase):
class GeomaticTest(TestCase):
+ fixtures = FIND_FIXTURES
+
def test_post_save_point(self):
class FakeGeomaticObject(object):
_meta = models.GeoItem._meta
@@ -2724,6 +2726,148 @@ class GeomaticTest(TestCase):
self.assertIsNotNone(obj.point_2d)
self.assertIsNotNone(obj.point)
+ @staticmethod
+ def create_cr_with_bfs(ope, geom_ope, geom_cr, list_geom_bf, label_cr):
+ from archaeological_operations.models import Operation
+ from archaeological_context_records.models import ContextRecord
+ from archaeological_finds.models import BaseFind, Find
+ from django.contrib.gis.geos import GEOSGeometry
+ from ishtar_common.models_common import SpatialReferenceSystem
+
+ wgs84 = SpatialReferenceSystem.objects.get(srid=4326)
+ poly_ope = ("MULTIPOLYGON(((1 1,5 1,5 5,1 5,1 1),(2 2,2 3,3 3,3 2,2 2)),"
+ "((6 3,9 2,9 4,6 3)))")
+ point_ope = GEOSGeometry("POINT({} {} {})".format(3.8, 3, 1), srid=4326)
+ point_2d_ope = GEOSGeometry("POINT({} {})".format(3.8, 3), srid=4326)
+ xy_ope = 3.8, 3
+ poly_cr = ("MULTIPOLYGON(((2 1,5 1,5 5,1 5,2 1),(2 2,2 3,3 3,3 2,2 2)),"
+ "((6 3,9 2,9 4,6 3)))")
+ point_cr = GEOSGeometry("POINT({} {} {})".format(3.9, 3, 1), srid=4326)
+ point_2d_cr = GEOSGeometry("POINT({} {})".format(3.9, 3), srid=4326)
+ xy_cr = 3.9, 3
+ poly_bf = ("MULTIPOLYGON(((2 1,4 1,4 4,1 4,2 1),(2 2,2 3,3 3,3 2,2 2)),"
+ "((6 3,9 2,9 4,6 3)))")
+ point_bf = GEOSGeometry("POINT({} {} {})".format(3.9, 2.9, 1), srid=4326)
+ point_2d_bf = GEOSGeometry("POINT({} {})".format(3.9, 2.9), srid=4326)
+ xy_bf = 3.9, 2.9
+
+ pks = {}
+
+ ope.multi_polygon = "SRID=4326;" + poly_ope
+ ope.multi_polygon_source = "P"
+ ope.multi_polygon_source_item = str(ope._meta.verbose_name)
+ ope.spatial_reference_system = wgs84
+ if geom_ope == "Point":
+ ope.point = point_ope
+ ope.point_source = "P"
+ ope.point_source_item = str(ope._meta.verbose_name)
+ ope.x, ope.y = xy_ope
+ ope.point_2d = point_2d_ope
+ ope.save() # needs 2 saves because point_2d is none for multi_polygon
+ ope = Operation.objects.get(pk=ope.pk)
+ ope.save()
+ ope = Operation.objects.get(pk=ope.pk)
+
+ default = {
+ "label": label_cr,
+ "operation": ope,
+ }
+ cr = ContextRecord.objects.create(**default)
+ cr = ContextRecord.objects.get(pk=cr.pk)
+ cr.multi_polygon = "SRID=4326;" + poly_cr
+ cr.multi_polygon_source = "P"
+ cr.multi_polygon_source_item = str(cr._meta.verbose_name)
+ cr.spatial_reference_system = wgs84
+ if geom_cr == "Point":
+ cr.point = point_cr
+ cr.point_source = "P"
+ cr.point_source_item = str(cr._meta.verbose_name)
+ cr.x, cr.y = xy_cr
+ cr.point_2d = point_2d_cr
+ cr.save()
+ cr = ContextRecord.objects.get(pk=cr.pk)
+ pks[label_cr] = cr.pk
+
+ bfs = []
+ for bf_geom in list_geom_bf:
+ default = {
+ "label": "Find " + bf_geom + " from " + label_cr,
+ "context_record": cr,
+ }
+ bf = BaseFind.objects.create(**default)
+ bf.multi_polygon = "SRID=4326;" + poly_bf
+ bf.multi_polygon_source = "P"
+ bf.multi_polygon_source_item = str(bf._meta.verbose_name)
+ bf.spatial_reference_system = wgs84
+ if bf_geom == "Point":
+ bf.point = point_bf
+ bf.point_source = "P"
+ bf.point_source_item = str(bf._meta.verbose_name)
+ bf.x, bf.y = xy_bf
+ bf.point_2d = point_2d_bf
+ bf.save()
+ bf = BaseFind.objects.get(pk=bf.pk)
+ bfs.append(bf)
+ pks[default['label']] = bf.pk
+
+ find = Find.objects.create()
+ find.base_finds.add(bf)
+ find.save()
+ return pks
+
+ @staticmethod
+ def setUpDefaultGeoItems(user):
+ from archaeological_operations.tests import create_operation
+
+ ope1 = create_operation(user)
+ ope2 = create_operation(user)
+ pks = {'Pt': ope1.pk, 'Poly': ope2.pk}
+
+ pks.update(GeomaticTest.create_cr_with_bfs(ope1, "Point", "Point", ["Polygon", "Point"], "CR Pt Pt"))
+ pks.update(GeomaticTest.create_cr_with_bfs(ope1, "Point", "Polygon", ["Polygon", "Point"], "CR Pt Poly"))
+ pks.update(GeomaticTest.create_cr_with_bfs(ope2, "Polygon", "Point", ["Polygon", "Point"], "CR Poly Pt"))
+ pks.update(GeomaticTest.create_cr_with_bfs(ope2, "Polygon", "Polygon", ["Polygon", "Point"], "CR Poly Poly"))
+
+ geom_ope = [
+ [[[[1, 1], [5, 1], [5, 5], [1, 5], [1, 1]], [[2, 2], [2, 3], [3, 3], [3, 2], [2, 2]]],
+ [[[6, 3], [9, 2], [9, 4], [6, 3]]]],
+ [3.86111, 3.02778],
+ [3.8, 3]
+ ]
+ geom_cr = [
+ [[[[2, 1], [5, 1], [5, 5], [1, 5], [2, 1]], [[2, 2], [2, 3], [3, 3], [3, 2], [2, 2]]],
+ [[[6, 3], [9, 2], [9, 4], [6, 3]]]],
+ [4.17708, 3.11458],
+ [3.9, 3]
+ ]
+ geom_bf = [
+ [[[[2, 1], [4, 1], [4, 4], [1, 4], [2, 1]], [[2, 2], [2, 3], [3, 3], [3, 2], [2, 2]]],
+ [[[6, 3], [9, 2], [9, 4], [6, 3]]]],
+ [4.42105, 2.73684],
+ [3.9, 2.9]
+ ]
+ return [geom_ope, geom_cr, geom_bf], pks
+
+ @staticmethod
+ def pt_coords_from_label(label, geoms):
+ if label[:2] == "Pt":
+ return geoms[0][2]
+ if label[:4] == "Poly":
+ return geoms[0][1]
+ if label[:2] == "CR":
+ if label[-2:] == "Pt":
+ return geoms[1][2]
+ if label[3:5] == "Pt":
+ return geoms[0][2]
+ return geoms[1][1]
+ if label[5:10] == "Point":
+ return geoms[2][2]
+ # label has shape Find Polygon from CR xxx xxx
+ if label[-2:] == "Pt":
+ return geoms[1][2]
+ if label[21:23] == "Pt":
+ return geoms[0][2]
+ return geoms[2][1]
class NewItems(TestCase):
fixtures = COMMON_FIXTURES
@@ -3171,38 +3315,7 @@ class SeleniumTests(StaticLiveServerTestCase):
self.selenium.find_element_by_xpath('//button[@type="submit"][@class="btn btn-primary"]').click()
def setUpDefaultGeoItems(self):
- from archaeological_operations.tests import create_operation
- from archaeological_finds.tests import GeomaticTest as GeomaticFindsTest
-
- ope1 = create_operation(self.user)
- ope2 = create_operation(self.user)
- pks = {'Pt': ope1.pk, 'Poly': ope2.pk}
-
- pks.update(GeomaticFindsTest.create_cr_with_bfs(ope1, "Point", "Point", ["Polygon", "Point"], "CR Pt Pt"))
- pks.update(GeomaticFindsTest.create_cr_with_bfs(ope1, "Point", "Polygon", ["Polygon", "Point"], "CR Pt Poly"))
- pks.update(GeomaticFindsTest.create_cr_with_bfs(ope2, "Polygon", "Point", ["Polygon", "Point"], "CR Poly Pt"))
- pks.update(GeomaticFindsTest.create_cr_with_bfs(ope2, "Polygon", "Polygon", ["Polygon", "Point"], "CR Poly Poly"))
-
- geom_ope = [
- [[[[1, 1], [5, 1], [5, 5], [1, 5], [1, 1]], [[2, 2], [2, 3], [3, 3], [3, 2], [2, 2]]],
- [[[6, 3], [9, 2], [9, 4], [6, 3]]]],
- [3.86111, 3.02778],
- [3.8, 3]
- ]
- geom_cr = [
- [[[[2, 1], [5, 1], [5, 5], [1, 5], [2, 1]], [[2, 2], [2, 3], [3, 3], [3, 2], [2, 2]]],
- [[[6, 3], [9, 2], [9, 4], [6, 3]]]],
- [4.17708, 3.11458],
- [3.9, 3]
- ]
- geom_bf = [
- [[[[2, 1], [4, 1], [4, 4], [1, 4], [2, 1]], [[2, 2], [2, 3], [3, 3], [3, 2], [2, 2]]],
- [[[6, 3], [9, 2], [9, 4], [6, 3]]]],
- [4.42105, 2.73684],
- [3.9, 2.9]
- ]
- return [geom_ope, geom_cr, geom_bf], pks
-
+ return GeomaticTest.setUpDefaultGeoItems(self.user)
def scroll(self, element):
self.selenium.execute_script(