summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2022-09-08 17:49:05 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2022-12-12 12:23:18 +0100
commite1dbb7d2d80c494c30e49f7d800b6cf941d72359 (patch)
tree95fc53fcdc8959da12250e0a4f49b35e0af902d3
parent543343147c3db01117a4d8d252edc11ff767a860 (diff)
downloadIshtar-e1dbb7d2d80c494c30e49f7d800b6cf941d72359.tar.bz2
Ishtar-e1dbb7d2d80c494c30e49f7d800b6cf941d72359.zip
Geo display: clean old code - manage bad data
-rw-r--r--archaeological_context_records/tests.py123
-rw-r--r--archaeological_finds/tests.py83
-rw-r--r--archaeological_operations/models.py135
-rw-r--r--archaeological_operations/tests.py163
-rw-r--r--ishtar_common/static/js/ishtar-map.js173
-rw-r--r--ishtar_common/tests.py181
-rw-r--r--ishtar_common/views_item.py2
7 files changed, 79 insertions, 781 deletions
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py
index acebda49b..21d3550c5 100644
--- a/archaeological_context_records/tests.py
+++ b/archaeological_context_records/tests.py
@@ -65,15 +65,11 @@ from ishtar_common.tests import (
COMMON_FIXTURES,
WAREHOUSE_FIXTURES,
SearchText,
- SeleniumTests,
)
from archaeological_operations.serializers import operation_serialization
from archaeological_context_records import views, serializers
-if settings.SELENIUM_TEST:
- from selenium.webdriver.support.wait import WebDriverWait
-
class ImportContextRecordTest(ImportTest, TestCase):
fixtures = CONTEXT_RECORD_TOWNS_FIXTURES
@@ -1513,122 +1509,3 @@ class GraphGenerationTest(ContextRecordInit, TestCase):
self.assertNotIn('"CR 2D"', content)
-@tag("ui")
-class SeleniumTestsContextRecords(SeleniumTests):
- fixtures = CONTEXT_RECORD_FIXTURES
-
- def _test_cr(self, xpath, slug_pk, geojsons):
- self.wait_and_click(xpath)
- label = self.label_from_internal_id(slug_pk)
-
- base = copy.deepcopy(geojsons[label]["get_polys"])
-
- get_poly_id = "get-poly-for-" + slug_pk
- get_poly_label_id = "get-poly-label-for-" + slug_pk
- disp_bf_id = "disp-bf-for-" + slug_pk
-
- cr_polys = geojsons[label]["get_polys"]
- bf_labels_polys = cr_polys["properties"].pop("base-finds")
- bf_polys = {
- "type": "FeatureCollection",
- "features": [
- geojsons[bf_label]["get_polys"] for bf_label in bf_labels_polys
- ],
- }
-
- cr_pts = geojsons[label]["get_pts"]
- bf_labels_pts = cr_pts["properties"].pop("base-finds")
- bf_pts = {
- "type": "FeatureCollection",
- "features": [geojsons[bf_label]["get_pts"] for bf_label in bf_labels_pts],
- }
-
- WebDriverWait(self.selenium, self.waiting_time).until(
- lambda driver: driver.find_element_by_xpath(
- '//dl[@class="col-12"]/dt[text()="Display geo items" or text()="Afficher les éléments"]'
- )
- )
- dd = '//dl[@class="col-12"]/dd'
- self.selenium.find_element_by_xpath(
- dd + '/fieldset/label[@for="' + disp_bf_id + '"]'
- )
- disp_bf = self.selenium.find_element_by_xpath(
- dd + '/fieldset/input[@id="' + disp_bf_id + '"]'
- )
- self.assertFalse(disp_bf.is_selected())
- select_get_poly = dd + '/select[@id="' + get_poly_id + '"]'
- get_poly_label = dd + '/label[@id="' + get_poly_label_id + '"]'
- self.assertNotInDOM(select_get_poly)
- self.assertNotInDOM(get_poly_label)
- self.assertMap(base, slug_pk)
-
- # context record specific
-
- # click on "Base finds"
- self.selenium.execute_script(
- "return initialize_test_map(arguments[0])", slug_pk
- )
- self.scroll(disp_bf)
- disp_bf.click()
- select_get_poly = dd + '/select[@id="' + get_poly_id + '"]'
- get_poly = self.selenium.find_element_by_xpath(select_get_poly)
- get_poly.click()
- self.selenium.find_element_by_xpath(
- select_get_poly + '/option[@value="polygons"]'
- ).click()
-
- bf_geoms = [bf_polys, {"type": "FeatureCollection", "features": []}]
- self.assertTrue(disp_bf.is_selected())
- self.selenium.find_element_by_xpath(get_poly_label)
- self.assertMap(base, slug_pk, bf_geoms)
-
- get_poly = self.selenium.find_element_by_xpath(select_get_poly)
- get_poly.click()
- self.selenium.find_element_by_xpath(
- select_get_poly + '/option[@value="points"]'
- ).click()
- bf_geoms = [bf_pts, {"type": "FeatureCollection", "features": []}]
- self.assertTrue(disp_bf.is_selected())
- self.selenium.find_element_by_xpath(get_poly_label)
- self.assertMap(base, slug_pk, bf_geoms)
-
- # Click on "None"
- self.selenium.execute_script(
- "return initialize_test_map(arguments[0])", slug_pk
- )
- disp_bf.click()
- self.assertFalse(disp_bf.is_selected())
- self.assertNotInDOM(select_get_poly)
- self.assertNotInDOM(get_poly_label)
- self.assertMap(base, slug_pk)
-
- def test_geo_items(self):
- if not settings.SELENIUM_TEST:
- return
- geojsons = self.default_geojson()
- # from operation
- self.access_from_dropdown("operation")
- for ope_pk, ope_xpath in self.pks_and_details_from_table("operation"):
- self.access_from_dropdown("operation")
- self.wait_and_click(ope_xpath)
- self.selenium.find_element_by_xpath(
- '//ul[@role="tablist"]/li/a[contains(@id, "cr-tab")][contains(@id, "operation-'
- + str(ope_pk)
- + '")]'
- ).click()
- for pk, xpath in self.pks_and_details_from_table(
- "contextrecord", "operation"
- ):
- slug_pk = "contextrecord-" + str(pk)
- self._test_cr(xpath, slug_pk, copy.deepcopy(geojsons))
- # from search bar
- self.access_from_dropdown("record")
- from_table = self.pks_and_details_from_table("contextrecord")
- for pk, xpath in from_table:
- self.access_from_dropdown("record")
- slug_pk = "contextrecord-" + str(pk)
- self._test_cr(xpath, slug_pk, copy.deepcopy(geojsons))
- # from bottom table, multiple displays
- for pk, xpath in from_table:
- slug_pk = "contextrecord-" + str(pk)
- self._test_cr(xpath, slug_pk, copy.deepcopy(geojsons))
diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py
index 3fd7d56e2..16e4b3304 100644
--- a/archaeological_finds/tests.py
+++ b/archaeological_finds/tests.py
@@ -95,7 +95,6 @@ from ishtar_common.tests import (
COMMON_FIXTURES,
GenericSerializationTest,
SearchText,
- SeleniumTests,
)
from archaeological_operations.tests import ImportTest, create_operation
from archaeological_context_records.tests import ContextRecordInit
@@ -2904,85 +2903,3 @@ class TemplateTest(FindInit, TestCase):
os.remove(tpl)
-@tag("ui")
-class SeleniumTestsBaseFinds(SeleniumTests):
- fixtures = FIND_FIXTURES
-
- def _test_bf(self, xpath, slug_pk, geojsons):
- self.wait_and_click(xpath)
- label = self.label_from_internal_id(slug_pk)
-
- bf_base = geojsons[label]["get_polys"]
- self.assertMap(bf_base, slug_pk)
-
- title = '//dl[@class="col-12"]/dt[text()="Display geo items" or text()="Afficher les éléments"]'
- dd = '//dl[@class="col-12"]/dd'
- disp = dd + '/input[@name="checkbox-geo-items"]'
- get_poly = dd + '/select[@name="get-poly-geo-items"]'
- self.assertNotInDOM(title)
- self.assertNotInDOM(disp)
- self.assertNotInDOM(get_poly)
-
- def test_geo_items(self):
- if not settings.SELENIUM_TEST:
- return
- geojsons = self.default_geojson()
- # from operation
- self.access_from_dropdown("operation")
- for ope_pk, ope_xpath in self.pks_and_details_from_table("operation"):
- self.access_from_dropdown("operation")
- self.wait_and_click(ope_xpath)
- self.selenium.find_element_by_xpath(
- '//ul[@role="tablist"]/li/a[contains(@id, "finds-tab")][contains(@id, "operation-'
- + str(ope_pk)
- + '")]'
- ).click()
- for pk, xpath in self.pks_and_details_from_table("find", "operation"):
- slug_pk = "find-" + str(pk)
- self._test_bf(xpath, slug_pk, copy.deepcopy(geojsons))
- # from context record
- self.access_from_dropdown("record")
- for cr_pk, cr_xpath in self.pks_and_details_from_table("record"):
- self.access_from_dropdown("record")
- self.wait_and_click(cr_xpath)
- self.selenium.find_element_by_xpath(
- '//ul[@role="tablist"]/li/a[contains(@id, "finds-tab")][contains(@id, "contextrecord-'
- + str(cr_pk)
- + '")]'
- ).click()
- for pk, xpath in self.pks_and_details_from_table("find", "record"):
- slug_pk = "find-" + str(pk)
- self._test_bf(xpath, slug_pk, copy.deepcopy(geojsons))
- # from context record from operation
- self.access_from_dropdown("operation")
- for ope_pk, ope_xpath in self.pks_and_details_from_table("operation"):
- self.access_from_dropdown("operation")
- self.wait_and_click(ope_xpath)
- self.selenium.find_element_by_xpath(
- '//ul[@role="tablist"]/li/a[contains(@id, "cr-tab")][contains(@id, "operation-'
- + str(ope_pk)
- + '")]'
- ).click()
- for cr_pk, cr_xpath in self.pks_and_details_from_table(
- "record", "operation"
- ):
- self.wait_and_click(cr_xpath)
- self.selenium.find_element_by_xpath(
- '//ul[@role="tablist"]/li/a[contains(@id, "finds-tab")][contains(@id, "contextrecord-'
- + str(cr_pk)
- + '")]'
- ).click()
- for pk, xpath in self.pks_and_details_from_table("find", "record"):
- slug_pk = "find-" + str(pk)
- self._test_bf(xpath, slug_pk, copy.deepcopy(geojsons))
- # from search bar
- self.access_from_dropdown("find")
- from_table = self.pks_and_details_from_table("find")
- for pk, xpath in from_table:
- self.access_from_dropdown("find")
- slug_pk = "find-" + str(pk)
- self._test_bf(xpath, slug_pk, copy.deepcopy(geojsons))
- # from bottom table, multiple displays
- for pk, xpath in from_table:
- slug_pk = "find-" + str(pk)
- self._test_bf(xpath, slug_pk, copy.deepcopy(geojsons))
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 69f8d4fdc..69b24fecd 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -30,6 +30,7 @@ from django.contrib.gis.db import models
from django.contrib.gis.db.models.aggregates import Union
from django.contrib.gis.db.models.functions import Centroid
from django.contrib.postgres.indexes import GinIndex
+from django.contrib.sites.models import Site
from django.db import IntegrityError, transaction
from django.db.models import Q, Count, Sum, Max, Avg
from django.db.models.signals import post_save, m2m_changed, post_delete
@@ -1729,92 +1730,88 @@ class Operation(
q = self.towns.filter(limit__isnull=False).annotate(poly=Union("limit")).all()
if not q.count():
return None
- return q.all()[0].poly, self._meta.verbose_namea
-
- """
- def _get_child_geodata(self, query, cr_list, collection_context_records_id,
- current_geodata):
- childs = []
- for cr in query.exclude(id__in=cr_list).values(
- "main_geodata", "id").distinct().all():
- childs.append(cr["id"])
- geodata_id = cr["main_geodata"]
- if geodata_id not in collection_context_records_id \
- and geodata_id not in current_geodata:
- collection_context_records_id.append(geodata_id)
- cr_list += childs
- return childs
- """
-
- def get_geo_items(self, rounded=True):
- dct = super(Operation, self).get_geo_items(rounded=rounded)
- ContextRecord = apps.get_model(
- "archaeological_context_records", "ContextRecord"
- )
-
- q = self.context_record.filter(main_geodata__isnull=False)
-
- """
- included = q.filter(
- right_relations__relation_type__txt_idx='is_included')
- q_upper = q.exclude(id__in=set(included.values_list("id", flat=True)))
- cr_list = []
-
- childs = self._get_child_geodata(
- q_upper, cr_list, collection_context_records_id,
- current_geodata)
- while childs:
- new_childs = []
- for child_id in childs:
- q_lower = q.filter(
- right_relations__relation_type__txt_idx='is_included',
- right_relations__right_record_id=child_id
- )
- new_childs += self._get_child_geodata(
- q_lower, cr_list, collection_context_records_id,
- current_geodata)
- childs = new_childs
-
+ return q.all()[0].poly, self._meta.verbose_name
-
- """
- collection_context_records_id = []
- current_geodata = self.geodata.values_list("id", flat=True)
+ def _get_geo_item_list(self, q, current_geodata, url, precision, rounded):
+ collection_id = []
+ items_id = []
q = q.values("main_geodata", "id")
- for cr in q.distinct().all():
- geodata_id = cr["main_geodata"]
- if geodata_id not in collection_context_records_id \
- and geodata_id not in current_geodata:
- collection_context_records_id.append(geodata_id)
-
- collection_context_records = []
- for cr_id in collection_context_records_id:
- geo = json.loads(GeoVectorData.objects.get(pk=cr_id).geojson)
+ for item in q.distinct().all():
+ geodata_id = item["main_geodata"]
+ if geodata_id not in current_geodata:
+ collection_id.append(geodata_id)
+ items_id.append(item["id"])
+ current_geodata.append(geodata_id)
+
+ collection = []
+ for idx in range(len(collection_id)):
+ geo = json.loads(GeoVectorData.objects.get(pk=collection_id[idx]).geojson)
geo_type = geo.get("type", None)
+ url_geo = url.format(items_id[idx])
if geo_type == "FeatureCollection":
- collection_context_records += geo["features"]
+ for feat in geo["features"]:
+ if "properties" in feat:
+ feat["properties"]["url"] = url_geo
+ collection += geo["features"]
elif geo_type:
- collection_context_records.append(geo)
+ if "properties" in geo:
+ geo["properties"]["url"] = url_geo
+ collection.append(geo)
- profile = get_current_profile()
- precision = profile.point_precision
if not precision and rounded:
- precision = 5
- if precision is not None:
- r = re.compile(r"(\d+)\.(\d{6})(\d*)")
- for feat in collection_context_records:
- geom_type = feat["geometry"].get("type", None)
- if geom_type == "Point":
+ precision = 6
+ r = re.compile(r"(\d+)\.(\d{6})(\d*)")
+ new_collection = []
+ for feat in collection:
+ geom_type = feat["geometry"].get("type", None)
+ if geom_type == "Point":
+ if precision is not None:
feat["geometry"]["coordinates"] = [
round(feat["geometry"]["coordinates"][0], precision),
round(feat["geometry"]["coordinates"][1], precision),
]
+ if not (-90 <= feat["geometry"]["coordinates"][1] <= 90) or not (
+ -180 <= feat["geometry"]["coordinates"][0] <= 180):
+ # probably a bad projection
+ continue
+ new_collection.append(feat)
+ return new_collection
+
+
+ def get_geo_items(self, rounded=True):
+ dct = super(Operation, self).get_geo_items(rounded=rounded)
+ site = Site.objects.get_current()
+ scheme = "https" if settings.ISHTAR_SECURE else "http"
+ base_url = scheme + "://" + site.domain
+
+ profile = get_current_profile()
+ precision = profile.point_precision
+
+ current_geodata = list(self.geodata.values_list("id", flat=True))
+
+ q = self.context_record.filter(main_geodata__isnull=False)
+ url = base_url + "/show-contextrecord/{}/"
+ collection_context_records = self._get_geo_item_list(
+ q, current_geodata, url, precision, rounded
+ )
+
+ BaseFind = apps.get_model("archaeological_finds", "BaseFind")
+ q = BaseFind.objects.filter(context_record__operation_id=self.pk,
+ main_geodata__isnull=False)
+ url = base_url + "/show-basefind/{}/"
+ collection_finds = self._get_geo_item_list(
+ q, current_geodata, url, precision, rounded
+ )
dct["context-records"] = {
"type": "FeatureCollection",
"features": collection_context_records,
}
+ dct["finds"] = {
+ "type": "FeatureCollection",
+ "features": collection_finds,
+ }
return dct
def context_record_relations_q(self):
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index 2521651ae..bfe8e3b11 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -109,13 +109,9 @@ from ishtar_common.tests import (
GenericSerializationTest,
WAREHOUSE_FIXTURES,
SearchText,
- SeleniumTests,
)
from ishtar_common.serializers import restore_serialized
-if settings.SELENIUM_TEST:
- from selenium.webdriver.support.wait import WebDriverWait
-
class FileInit(object):
def login_as_superuser(self):
@@ -4483,165 +4479,6 @@ class DocumentQATest(OperationInitTest, TestCase):
)
-@tag("ui")
-class SeleniumTestsOperations(SeleniumTests):
- fixtures = OPERATION_FIXTURES
-
- def _test_operation(self, xpath, slug_pk, geojsons):
- self.wait_and_click(xpath)
- label = self.label_from_internal_id(slug_pk)
-
- get_poly_id = "get-poly-for-" + slug_pk
- get_poly_label_id = "get-poly-label-for-" + slug_pk
- disp_cr_id = "disp-cr-for-" + slug_pk
- disp_bf_id = "disp-bf-for-" + slug_pk
-
- ope_polys = geojsons[label]["get_polys"]
- cr_labels_polys = ope_polys["properties"].pop("context-records")
- bf_labels_polys = ope_polys["properties"].pop("base-finds")
- cr_polys = {"type": "FeatureCollection", "features": []}
- for cr_label in cr_labels_polys:
- geojsons[cr_label]["get_polys"]["properties"] = None
- cr_polys["features"].append(geojsons[cr_label]["get_polys"])
- bf_polys = {
- "type": "FeatureCollection",
- "features": [
- geojsons[bf_label]["get_polys"] for bf_label in bf_labels_polys
- ],
- }
-
- ope_pts = geojsons[label]["get_pts"]
- cr_labels_pts = ope_pts["properties"].pop("context-records")
- cr_pts = {"type": "FeatureCollection", "features": []}
- for cr_label in cr_labels_pts:
- geojsons[cr_label]["get_pts"]["properties"] = None
- cr_pts["features"].append(geojsons[cr_label]["get_pts"])
- bf_labels_pts = ope_pts["properties"].pop("base-finds")
- bf_pts = {
- "type": "FeatureCollection",
- "features": [geojsons[bf_label]["get_pts"] for bf_label in bf_labels_pts],
- }
-
- ope_base = geojsons[label]["get_polys"]
-
- WebDriverWait(self.selenium, self.waiting_time).until(
- lambda driver: driver.find_element_by_xpath(
- '//dl[@class="col-12"]/dt[@id="display-geo-items-for-' + slug_pk + '"]'
- )
- )
- dd = '//dl[@class="col-12"]/dd'
- self.selenium.find_element_by_xpath(
- dd + '/fieldset/label[@for="' + disp_cr_id + '"]'
- )
- disp_cr = self.selenium.find_element_by_xpath(
- dd + '/fieldset/input[@id="' + disp_cr_id + '"]'
- )
- self.selenium.find_element_by_xpath(
- dd + '/fieldset/label[@for="' + disp_bf_id + '"]'
- )
- disp_bf = self.selenium.find_element_by_xpath(
- dd + '/fieldset/input[@id="' + disp_bf_id + '"]'
- )
- self.assertFalse(disp_cr.is_selected())
- self.assertFalse(disp_bf.is_selected())
- select_get_poly = dd + '/select[@id="' + get_poly_id + '"]'
- get_poly_label = dd + '/label[@id="' + get_poly_label_id + '"]'
- self.assertNotInDOM(select_get_poly)
- self.assertNotInDOM(get_poly_label)
- self.assertMap(ope_base, slug_pk)
-
- # click on "Context records"
- self.selenium.execute_script("initialize_test_map(arguments[0])", slug_pk)
- self.scroll(disp_cr)
- disp_cr.click()
-
- cr_geoms = [{"type": "FeatureCollection", "features": []}, cr_polys]
- self.assertTrue(disp_cr.is_selected())
- self.assertFalse(disp_bf.is_selected())
- self.selenium.find_element_by_xpath(get_poly_label)
- self.assertMap(ope_base, slug_pk, cr_geoms)
-
- get_poly = self.selenium.find_element_by_xpath(select_get_poly)
- get_poly.click()
- self.selenium.find_element_by_xpath(
- select_get_poly + '/option[@value="points"]'
- ).click()
- cr_geoms = [{"type": "FeatureCollection", "features": []}, cr_pts]
- self.assertTrue(disp_cr.is_selected())
- self.assertFalse(disp_bf.is_selected())
- self.selenium.find_element_by_xpath(get_poly_label)
- self.assertMap(ope_base, slug_pk, cr_geoms)
-
- # Click on everything
- self.selenium.execute_script("initialize_test_map(arguments[0])", slug_pk)
- disp_bf.click()
- every_geoms = [bf_pts, cr_pts]
- self.assertTrue(disp_cr.is_selected())
- self.assertTrue(disp_bf.is_selected())
- self.selenium.find_element_by_xpath(get_poly_label)
- self.assertMap(ope_base, slug_pk, every_geoms)
-
- self.selenium.execute_script("initialize_test_map(arguments[0])", slug_pk)
- get_poly.click()
- self.selenium.find_element_by_xpath(
- select_get_poly + '/option[@value="polygons"]'
- ).click()
- every_geoms = [bf_polys, cr_polys]
- self.assertTrue(disp_cr.is_selected())
- self.assertTrue(disp_bf.is_selected())
- self.selenium.find_element_by_xpath(get_poly_label)
- self.assertMap(ope_base, slug_pk, every_geoms)
-
- # click on "Base finds"
- self.selenium.execute_script("initialize_test_map(arguments[0])", slug_pk)
- self.scroll(disp_cr)
- disp_cr.click()
-
- bf_geoms = [bf_polys, {"type": "FeatureCollection", "features": []}]
- self.assertFalse(disp_cr.is_selected())
- self.assertTrue(disp_bf.is_selected())
- self.selenium.find_element_by_xpath(get_poly_label)
- self.assertMap(ope_base, slug_pk, bf_geoms)
-
- select_get_poly = dd + '/select[@id="' + get_poly_id + '"]'
- get_poly = self.selenium.find_element_by_xpath(select_get_poly)
- get_poly.click()
- self.selenium.find_element_by_xpath(
- select_get_poly + '/option[@value="points"]'
- ).click()
- bf_geoms = [bf_pts, {"type": "FeatureCollection", "features": []}]
- self.assertFalse(disp_cr.is_selected())
- self.assertTrue(disp_bf.is_selected())
- self.selenium.find_element_by_xpath(get_poly_label)
- self.assertMap(ope_base, slug_pk, bf_geoms)
-
- # Click on "None"
- self.selenium.execute_script("initialize_test_map(arguments[0])", slug_pk)
- disp_bf.click()
- self.assertFalse(disp_cr.is_selected())
- self.assertFalse(disp_bf.is_selected())
- self.assertNotInDOM(select_get_poly)
- self.assertNotInDOM(get_poly_label)
- self.assertMap(ope_base, slug_pk)
-
- def test_geo_items(self):
- if not settings.SELENIUM_TEST:
- return
- geojsons = self.default_geojson()
- slug = "operation"
- self.access_from_dropdown(slug)
- from_table = self.pks_and_details_from_table(slug)
- for pk, xpath in from_table:
- self.access_from_dropdown(slug)
- slug_pk = slug + "-" + str(pk)
- self._test_operation(xpath, slug_pk, copy.deepcopy(geojsons))
- # display both at the same time
- self.access_from_dropdown(slug)
- for pk, xpath in from_table:
- slug_pk = slug + "-" + str(pk)
- self._test_operation(xpath, slug_pk, copy.deepcopy(geojsons))
-
-
class ApiTest(OperationInitTest, APITestCase):
fixtures = FILE_FIXTURES
diff --git a/ishtar_common/static/js/ishtar-map.js b/ishtar_common/static/js/ishtar-map.js
index ae591db08..8ffe399d6 100644
--- a/ishtar_common/static/js/ishtar-map.js
+++ b/ishtar_common/static/js/ishtar-map.js
@@ -529,6 +529,9 @@ var open_map_window = function(map_id){
var complete_list_label = "complete list...";
+var map_display_base_url_start = "<a class='display_details' href='#' onclick='load_window(\"";
+var map_display_base_url_end = "\")'><i class='fa fa-info-circle' aria-hidden='true'></i></a>";
+
var _display_items = function(map_id, features, offset_x, offset_y){
// console.log("display_items");
var feature = features[0];
@@ -549,7 +552,10 @@ var _display_items = function(map_id, features, offset_x, offset_y){
if (link_template[map_id]){
link = link_template[map_id].replace("<pk>", properties["id"]);
}
- var txt = "<li>" + link + " " + properties['name'] + "</li>";
+ if ("url" in properties){
+ link = map_display_base_url_start + properties["url"] + map_display_base_url_end;
+ }
+ var txt = "<li>" + link + " " + properties["name"] + "</li>";
window_content += txt;
if (idx_feat < 5){
popup_content += txt;
@@ -728,8 +734,7 @@ var display_points = function(map_id, points, first_init){
if (!cluster_source[map_id]){
enable_clustering(map_id);
} else {
- cluster_source[map_id].getSource().clear();
- cluster_source[map_id].getSource().refresh();
+ reinit_clustering(map_id);
}
cluster_source[map_id].getSource().addFeatures(point_features[map_id]);
if (first_init && points.features && points.features.length){
@@ -761,160 +766,6 @@ var display_lines_and_polys = function(map_id, lines_and_polys, first_init){
}
};
-var display_geo_items = function(map_id, base_url, slug, pk,
- disp_cr, disp_bf, get_poly) {
- let url = base_url;
- if (slug === "operation") {
- url += "?operation_pk=";
- }
- else {
- url += "?context_record_pk=";
- }
- url += pk;
-
- httpRequest = new XMLHttpRequest();
- if (!httpRequest) { return; }
- httpRequest.onreadystatechange = function() {
- if (httpRequest.readyState === XMLHttpRequest.DONE) {
- if (httpRequest.status === 200) {
- const geo_items = to_geo_items(JSON.parse(httpRequest.responseText), slug, disp_cr, disp_bf)
- if (current_test) {
- geo_items_features[map_id] = [];
- }
- let bfs = null;
- let crs = null;
- if (get_poly) {
- bfs = display_associated_polys(map_id, geo_items['base-finds'], 'basefind');
- crs = display_associated_polys(map_id, geo_items['context-records'], 'contextrecord');
- } else {
- bfs = display_associated_points(map_id, geo_items['base-finds'], 'basefind');
- crs = display_associated_points(map_id, geo_items['context-records'], 'contextrecord');
- }
- if (current_test) {
- geo_items_features[map_id].push(bfs)
- geo_items_features[map_id].push(crs)
- $("#http-geo-items-ready-"+slug+"-"+pk).show();
- }
- } else { return; }
- }
- };
- httpRequest.open('GET', url, true);
- httpRequest.send();
-};
-
-var to_geo_items = function (obj, slug, disp_cr, disp_bf) {
- const objects = {'context-records': {'features': [], 'type': 'FeatureCollection'},
- 'base-finds': {'features': [], 'type': 'FeatureCollection'}};
- if (slug === "operation") {
- const crs = obj['properties']['context-records'];
- for (const cr of crs['features']) {
- if (disp_bf) {
- for (const bf of cr['properties']['base-finds']['features']) {
- objects['base-finds']['features'].push(bf)
- }
- }
- delete cr['properties'];
- if (disp_cr) {
- objects['context-records']['features'].push(cr)
- }
- }
- }
- else {
- for (const bf of obj['properties']['base-finds']['features']) {
- objects['base-finds']['features'].push(bf)
- }
- }
- return objects;
-}
-
-var display_associated_polys = function (map_id, polys, slug) {
- const _vector_features = geojson_format.readFeatures(polys);
- const _vector_source = new ol.source.Vector();
- _vector_source.addFeatures(_vector_features);
- let style = get_associated_base_find_style;
- if (slug === 'contextrecord') {
- style = get_associated_context_record_style;
- }
- const _vector_layer = new ol.layer.Vector({
- source: _vector_source,
- style: style
- });
- map[map_id].addLayer(_vector_layer);
- return _vector_features
-}
-
-var get_associated_base_find_style = function (feature) {
- return new ol.style.Style({
- stroke: new ol.style.Stroke({
- color: 'rgba(0, 0, 0, 1)',
- width: 2
- }),
- fill: new ol.style.Fill({
- color: 'rgba(O, O, O, 0.2)'
- })
- });
-};
-
-var get_associated_context_record_style = function (feature) {
- return new ol.style.Style({
- stroke: new ol.style.Stroke({
- color: 'rgba(255, 255, 255, 1)',
- width: 2
- }),
- fill: new ol.style.Fill({
- color: 'rgba(255, 255, 255, 0.2)'
- }),
- radius: 10
- });
-};
-
-var display_associated_points = function (map_id, points, slug) {
- const _point_features = geojson_format.readFeatures(points);
- const _cluster_source = new ol.source.Cluster({
- distance: 40,
- source: new ol.source.Vector()
- });
- _cluster_source.getSource().addFeatures(_point_features);
- // TODO: create own style
- const style = cluster_get_style;
- const _cluster_layer = new ol.layer.Vector({
- name: 'Cluster',
- source: _cluster_source,
- style: style
- });
- map[map_id].addLayer(_cluster_layer);
- return _point_features;
-}
-
-var get_features_by_id = function (id) {
- let base_features = null
- if (vector_features[id] == null) {
- base_features = geojson_format.writeFeaturesObject(point_features[id], {decimals: 5});
- } else {
- base_features = geojson_format.writeFeaturesObject(vector_features[id], {decimals: 5});
- }
- const geo_items_feats = [];
- if (geo_items_features && id in geo_items_features) {
- for (const features of geo_items_features[id]) {
- geo_items_feats.push(geojson_format.writeFeaturesObject(features, {decimals: 5}));
- }
- }
- return [base_features, geo_items_feats];
-}
-
-var base_features_type = function (id) {
- if (vector_features[id] == null) {
- if (point_features[id] == null) {
- return 'both null';
- }
- else { return 'Point'; }
- }
- if (point_features[id] == null) {
- return 'MultiPolygon';
- }
- else { return 'Point and MultiPolygon' }
-}
-
var _geo_points = new Array();
var _geo_other = new Array();
@@ -948,10 +799,10 @@ const _refresh_map_finds = function(idx) {
}
}
-const refresh_map_finds_crs = function(url, attrs, idx, crs_check, find_check) {
+const refresh_map_finds_crs = function(url, attrs, idx, crs_check, finds_check) {
if (idx in _point_list_finds){
if (crs_check) _refresh_map_crs(idx);
- if (find_check) _refresh_map_finds(idx);
+ if (finds_check) _refresh_map_finds(idx);
return;
}
_point_list_crs[idx] = new Array();
@@ -1011,9 +862,9 @@ const refresh_map = function(idx, geodata_list, url, attrs) {
}
}
if (url && attrs){
- let find_check = $("#map-ol-" + idx + "-finds").prop('checked');
+ let finds_check = $("#map-ol-" + idx + "-finds").prop('checked');
let crs_check = $("#map-ol-" + idx + "-crs").prop('checked');
- refresh_map_finds_crs(url, attrs, idx, crs_check, find_check);
+ refresh_map_finds_crs(url, attrs, idx, crs_check, finds_check);
}
}
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index 25d4d8e85..a7cc8361c 100644
--- a/ishtar_common/tests.py
+++ b/ishtar_common/tests.py
@@ -90,12 +90,6 @@ from ishtar_common import utils_secretary
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
-if settings.SELENIUM_TEST:
- from selenium.webdriver.firefox.webdriver import WebDriver
- from selenium.webdriver.support.wait import WebDriverWait
- from selenium.webdriver.common.by import By
- from selenium.webdriver.support import expected_conditions as EC
-
COMMON_FIXTURES = [
settings.ROOT_PATH + "../fixtures/initial_data-auth-fr.json",
@@ -3369,178 +3363,3 @@ class TemplateGenerationTest(TestCase):
filtr = doc.get_filter(template, filter_re)
for key in expected_keys:
self.assertIn(key, filtr)
-
-
-@tag("ui")
-class SeleniumTests(StaticLiveServerTestCase):
- @classmethod
- def setUpClass(cls):
- if not settings.SELENIUM_TEST:
- sys.stdout.write("UI test not activated. Set SELENIUM_TEST to True.")
- return
- super().setUpClass()
- cls.waiting_time = 20
- cls.selenium = WebDriver()
- cls.selenium.implicitly_wait(cls.waiting_time)
-
- @classmethod
- def tearDownClass(cls):
- if not settings.SELENIUM_TEST:
- return
- cls.selenium.quit()
- super().tearDownClass()
-
- def setUp(self):
- if not settings.SELENIUM_TEST:
- return
-
- # profile
- profile = models.get_current_profile()
- profile.mapping = True
- profile.files = True
- profile.context_record = True
- profile.find = True
- profile.warehouse = True
- profile.experimental_feature = True
- profile.save()
-
- # login
- self.username, self.password, self.user = create_superuser()
- self.selenium.get("%s%s" % (self.live_server_url, "/accounts/login/"))
- WebDriverWait(self.selenium, self.waiting_time).until(
- lambda driver: driver.find_element_by_name("username")
- )
- username_input = self.selenium.find_element_by_name("username")
- username_input.send_keys(self.username)
- password_input = self.selenium.find_element_by_name("password")
- password_input.send_keys(self.password)
- self.selenium.find_element_by_xpath(
- '//button[@type="submit"][@class="btn btn-primary"]'
- ).click()
-
- def setUpDefaultGeoItems(self):
- if not settings.SELENIUM_TEST:
- return
- return GeomaticTest.setUpDefaultGeoItems(self.user)
-
- def default_geojson(self):
- geoms, pks = self.setUpDefaultGeoItems()
- return GeomaticTest.geojson_geo_items(geoms, pks)
-
- def scroll(self, element):
- self.selenium.execute_script(
- "var viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);"
- + "var elementTop = arguments[0].getBoundingClientRect().top;"
- + "window.scrollBy(0, elementTop-(viewPortHeight/2));",
- element,
- )
-
- def wait_and_click(self, xpath):
- WebDriverWait(self.selenium, self.waiting_time).until(
- EC.visibility_of_element_located((By.XPATH, xpath))
- )
- el = self.selenium.find_element_by_xpath(xpath)
- self.scroll(el)
- el.click()
-
- def access_from_dropdown(self, slug):
- if slug == "contextrecord":
- slug = "record"
- if slug == "basefind":
- slug = "find"
- self.wait_and_click(
- '//a[@class="nav-link dropdown-toggle"][@id="dropdown-menu-main"]'
- )
- self.selenium.find_element_by_xpath(
- '//div[@class="dropdown-menu show"]/a[@href="/' + slug + '_search/"]'
- ).click()
-
- def pks_and_details_from_table(self, slug, source=None):
- res = []
- xpath = "//table"
- keywords = ["find", "record", "operation"]
- for key in keywords:
- if key in slug or (source and key in source):
- xpath += '[contains(@id, "' + key + '")]'
- else:
- xpath += '[not(contains(@id, "' + key + '"))]'
- xpath += (
- '/tbody/tr/td/a[@class="display_details"][@href="#"][contains(@onclick, "'
- + slug
- + '")]'
- )
- for el in self.selenium.find_elements_by_xpath(xpath):
- pk = int(re.findall(r"\d+", el.get_attribute("onclick"))[-1])
- res.append([pk, xpath + '[contains(@onclick, "' + str(pk) + '")]'])
- return res
-
- def label_from_internal_id(self, slug_pk):
- xpath = '//div[contains(@id, "'
- if slug_pk[:3] == "ope":
- xpath += slug_pk + '")]' + "/div" * 5
- elif slug_pk[:7] == "context":
- xpath += slug_pk + '")]' + "/div" * 3
- else:
- xpath += slug_pk[4:] + '")]'
- xpath += '/p/small[@title="ID interne" or @title="Internal ID"]'
- WebDriverWait(self.selenium, self.waiting_time).until(
- EC.visibility_of_element_located((By.XPATH, xpath))
- )
- label = self.selenium.find_element_by_xpath(xpath).text
- if slug_pk[:3] == "ope":
- if label == "2":
- label = "Poly"
- else:
- label = "Pt"
- elif slug_pk[:7] == "context":
- label = label[1:]
- else:
- label = label.split("-")
- label = label[2]
- return label
-
- def assertNotInDOM(self, xpath):
- self.selenium.implicitly_wait(self.waiting_time / 10)
- try:
- WebDriverWait(self.selenium, self.waiting_time / 10).until(
- EC.visibility_of_element_located((By.XPATH, xpath))
- )
- found = True
- except:
- found = False
- self.selenium.implicitly_wait(self.waiting_time)
- self.assertFalse(found)
-
- def assertMap(self, dic_base, slug_pk, features_collecs=None):
- dic_base = {"type": "FeatureCollection", "features": [dic_base]}
- mapid = None
- t = time()
- while not mapid and time() - t < self.waiting_time:
- mapdivs = self.selenium.find_elements_by_class_name("window-map")
- for mapdiv in mapdivs:
- if slug_pk in mapdiv.get_attribute("id"):
- mapid = mapdiv.get_attribute("id")
- break
- self.assertIsNotNone(mapid, "Timeout, no mapid found")
- id = int(re.search(r"\d+$", mapid).group())
- # TODO: use the map and not the map_features in the js function
- if features_collecs:
- WebDriverWait(self.selenium, self.waiting_time).until(
- EC.visibility_of_element_located(
- (By.ID, "http-geo-items-ready-" + slug_pk)
- )
- )
- base_features, geo_items_feats = self.selenium.execute_script(
- "return get_features_by_id(arguments[0])", mapid
- )
- base_features["features"][0]["properties"].pop("name")
- base_features_type = self.selenium.execute_script(
- "return base_features_type(arguments[0])", mapid
- )
- dic_base["features"][0]["properties"] = {"id": id}
- self.assertEqual(
- base_features_type, dic_base["features"][0]["geometry"]["type"]
- )
- self.assertEqual(base_features, dic_base)
- if features_collecs:
- self.assertEqual(geo_items_feats, features_collecs)
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py
index b1a7e397d..d06613b19 100644
--- a/ishtar_common/views_item.py
+++ b/ishtar_common/views_item.py
@@ -360,7 +360,7 @@ def show_item(model, name, extra_dct=None, model_for_perms=None):
date = dct.pop("date")
dct["sheet_id"] = f"{name}-{pk}"
dct["window_id"] = f"{name}-{pk}-{datetime.datetime.now().strftime('%M%s')}"
- if pk.startswith("source-"):
+ if str(pk).startswith("source-"):
return show_source_item(request, pk, model, name, dct, extra_dct)
try:
item = q.get(pk=pk)