diff options
| -rw-r--r-- | archaeological_finds/tests.py | 50 | ||||
| -rw-r--r-- | archaeological_finds/urls.py | 13 | ||||
| -rw-r--r-- | archaeological_finds/views.py | 116 | ||||
| -rw-r--r-- | ishtar_common/models_common.py | 25 | 
4 files changed, 109 insertions, 95 deletions
| diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py index 2a98ef381..73e3f6f45 100644 --- a/archaeological_finds/tests.py +++ b/archaeological_finds/tests.py @@ -877,10 +877,7 @@ class ImportFindTest(ImportTest, FindInit, TestCase):              _("The division {} {} do not exist for the location {}.")          ).format("Area", "43", "Warehouse test")          for error in impt.errors: -            self.assertEqual( -                error["error"], -                error_msg -            ) +            self.assertEqual(error["error"], error_msg)      def tearDown(self):          self.tmpdir.cleanup() @@ -1106,8 +1103,9 @@ class FindBasketTest(FindInit, TestCase):          self.create_finds(force=True)          self.username = "myuser"          self.password = "mypassword" -        u = User.objects.create_superuser(self.username, "myemail@test.com", -                                          self.password) +        u = User.objects.create_superuser( +            self.username, "myemail@test.com", self.password +        )          self.client = Client()          b = models.FindBasket.objects.create(label="test basket", user_id=u.pk)          b.items.add(self.finds[0]) @@ -1131,7 +1129,7 @@ class FindBasketTest(FindInit, TestCase):          content = response.content.decode()          res = json.loads(content)          self.assertEqual(res["recordsTotal"], 2) -        search = {"search_vector" : 'other'} +        search = {"search_vector": "other"}          response = c.get(reverse("get-findbasket"), search)          content = response.content.decode()          res = json.loads(content) @@ -2544,21 +2542,18 @@ class GeomaticTest(FindInit, TestCase):          base_find = models.BaseFind.objects.get(pk=base_find.pk)          dic = {              "type": "Feature", -            "geometry": { -                "type": "Point", -                "coordinates": [2.0, 43.0] -            } +            "geometry": {"type": "Point", "coordinates": [2.0, 43.0]},          }          res = base_find.get_geo_items(get_polygons=True)          self.assertEqual(dic, res)          res = base_find.get_geo_items(get_polygons=False)          self.assertEqual(dic, res) -            # test API +        # test API          find = base_find.find.all()[0]          response = self.client.get(reverse("api-get-geo-items", kwargs={"pk": find.pk}))          self.assertEqual(response.status_code, 200) -        self.assertIn(json.dumps(dic).encode('utf-8'), response.content) +        self.assertIn(json.dumps(dic).encode("utf-8"), response.content)          # with multi-polygon          base_find = models.BaseFind.objects.get(pk=base_find.pk) @@ -2582,31 +2577,34 @@ class GeomaticTest(FindInit, TestCase):                          [[1.0, 1.0], [5.0, 1.0], [5.0, 5.0], [1.0, 5.0], [1.0, 1.0]],                          [[2.0, 2.0], [2.0, 3.0], [3.0, 3.0], [3.0, 2.0], [2.0, 2.0]],                      ], -                    [ -                        [[6.0, 3.0], [9.0, 2.0], [9.0, 4.0], [6.0, 3.0]] -                    ] -                ] +                    [[[6.0, 3.0], [9.0, 2.0], [9.0, 4.0], [6.0, 3.0]]], +                ],              },          }          res_poly = base_find.get_geo_items(get_polygons=True)          self.assertEqual(dict_poly, res_poly)          dict_centroid = {              "type": "Feature", -            "geometry": { -                "type": "Point", -                "coordinates": [3.86111, 3.02778] -            } +            "geometry": {"type": "Point", "coordinates": [3.86111, 3.02778]},          }          res_centroid = base_find.get_geo_items(get_polygons=False)          self.assertEqual(dict_centroid, res_centroid) -            # test API -        response = self.client.get(reverse("api-get-geo-items", kwargs={"pk": base_find.pk, "get_polygons": True})) +        # test API +        response = self.client.get( +            reverse( +                "api-get-geo-items", kwargs={"pk": base_find.pk, "get_polygons": True} +            ) +        )          self.assertEqual(response.status_code, 200) -        self.assertIn(json.dumps(dict_poly).encode('utf-8'), response.content) -        response = self.client.get(reverse("api-get-geo-items", kwargs={"pk": base_find.pk, "get_polygons": False})) +        self.assertIn(json.dumps(dict_poly).encode("utf-8"), response.content) +        response = self.client.get( +            reverse( +                "api-get-geo-items", kwargs={"pk": base_find.pk, "get_polygons": False} +            ) +        )          self.assertEqual(response.status_code, 200) -        self.assertIn(json.dumps(dict_centroid).encode('utf-8'), response.content) +        self.assertIn(json.dumps(dict_centroid).encode("utf-8"), response.content) diff --git a/archaeological_finds/urls.py b/archaeological_finds/urls.py index 73fa1d4a7..699337b8f 100644 --- a/archaeological_finds/urls.py +++ b/archaeological_finds/urls.py @@ -572,11 +572,20 @@ urlpatterns = [          name="autocomplete-findbasket-write",      ),      url(r"api/public/find/$", views.PublicFindAPI.as_view(), name="api-public-find"), -    url(r"api/ishtar/finds/geo/(?P<pk>.+)/(?P<get_polygons>.+)?$", +    url( +        r"api/ishtar/base-finds/geo/polygons/(?P<pk>[0-9]+)/(?P<get_polygons>(True|False)/)?$",          check_rights(["view_find", "view_own_find"])(              views.get_geo_items,          ), -        name="api-get-geo-items"), +        name="api-get-geo-items", +    ), +    url( +        r"api/ishtar/base-finds/geo/point/(?P<pk>[0-9]+)/$", +        check_rights(["view_find", "view_own_find"])( +            views.get_geo_items, +        ), +        name="api-get-geo-items", +    ),  ]  urlpatterns += get_urls_for_model(models.Find, views, own=True, autocomplete=True) diff --git a/archaeological_finds/views.py b/archaeological_finds/views.py index 3e1ffc574..8169f447b 100644 --- a/archaeological_finds/views.py +++ b/archaeological_finds/views.py @@ -155,13 +155,13 @@ get_administrativeacttreatmentfile = get_item(  def autocomplete_treatmentfile(request):      if ( -            not request.user.has_perm("ishtar_common.view_treatment", models.Treatment) -            and not request.user.has_perm( -        "ishtar_common.view_own_treatment", models.Treatment -    ) -            and not request.user.ishtaruser.has_right( -        "treatmentfile_search", session=request.session -    ) +        not request.user.has_perm("ishtar_common.view_treatment", models.Treatment) +        and not request.user.has_perm( +            "ishtar_common.view_own_treatment", models.Treatment +        ) +        and not request.user.ishtaruser.has_right( +            "treatmentfile_search", session=request.session +        )      ):          return HttpResponse(content_type="text/plain")      if not request.GET.get("term"): @@ -171,9 +171,9 @@ def autocomplete_treatmentfile(request):      for q1 in q.split(" "):          for q in q1.split(" "):              extra = ( -                    Q(internal_reference__icontains=q) -                    | Q(external_id__icontains=q) -                    | Q(name__icontains=q) +                Q(internal_reference__icontains=q) +                | Q(external_id__icontains=q) +                | Q(name__icontains=q)              )              try:                  int(q) @@ -201,10 +201,10 @@ def show_find_extra(request, find):      user = request.user.ishtaruser      q = (          models.FindBasket.objects.filter(items__pk=find.pk) -            .filter( +        .filter(              Q(user=user) | Q(shared_with__pk=user.pk) | Q(shared_write_with__pk=user.pk)          ) -            .distinct() +        .distinct()      )      return {"baskets": [(basket.pk, basket.full_label) for basket in q.all()]} @@ -489,8 +489,8 @@ class OwnBasket(object):                  models.FindBasket.objects.filter(                      Q(user=user) | Q(shared_with=user) | Q(shared_write_with=user)                  ) -                    .distinct() -                    .get(pk=pk) +                .distinct() +                .get(pk=pk)              )          except models.FindBasket.DoesNotExist:              raise PermissionDenied @@ -587,9 +587,9 @@ class FindBasketDeleteItemView(          basket = self.get_basket(user=ishtaruser, pk=self.kwargs["basket"])          if ( -                not user.is_superuser -                and not ishtaruser.has_right("view_find") -                and not (ishtaruser.has_right("view_own_find") and find.is_own(user)) +            not user.is_superuser +            and not ishtaruser.has_right("view_find") +            and not (ishtaruser.has_right("view_own_find") and find.is_own(user))          ):              raise PermissionDenied          basket.items.remove(find) @@ -665,7 +665,7 @@ treatment_modification_wizard = wizards.TreatmentModificationWizard.as_view(  def treatment_modify(request, pk):      if not wizard_is_available( -            treatment_modification_wizard, request, models.Treatment, pk +        treatment_modification_wizard, request, models.Treatment, pk      ):          return HttpResponseRedirect("/")      wizards.TreatmentModificationWizard.session_set_value( @@ -833,7 +833,7 @@ treatment_deletion_wizard = wizards.TreatmentDeletionWizard.as_view(  def treatment_delete(request, pk):      if not wizard_is_available( -            treatment_deletion_wizard, request, models.Treatment, pk +        treatment_deletion_wizard, request, models.Treatment, pk      ):          return HttpResponseRedirect("/")      wizards.TreatmentDeletionWizard.session_set_value( @@ -889,7 +889,7 @@ treatment_administrativeact_modification_wizard = (  def treatment_administrativeacttreatment_modify(request, pk):      if not wizard_is_available( -            treatment_administrativeact_modification_wizard, request, AdministrativeAct, pk +        treatment_administrativeact_modification_wizard, request, AdministrativeAct, pk      ):          return HttpResponseRedirect("/")      wizards.TreatmentEditAdministrativeActWizard.session_set_value( @@ -918,7 +918,7 @@ treatment_admacttreatment_deletion_wizard = AdministrativeActDeletionWizard.as_v  def treatment_administrativeacttreatment_delete(request, pk):      if not wizard_is_available( -            treatment_admacttreatment_deletion_wizard, request, AdministrativeAct, pk +        treatment_admacttreatment_deletion_wizard, request, AdministrativeAct, pk      ):          return HttpResponseRedirect("/")      wizard_url = "treatment_admacttreatment_deletion" @@ -978,7 +978,7 @@ treatmentfile_modification_wizard = wizards.TreatmentFileModificationWizard.as_v  def treatmentfile_modify(request, pk):      if not wizard_is_available( -            treatmentfile_modification_wizard, request, models.TreatmentFile, pk +        treatmentfile_modification_wizard, request, models.TreatmentFile, pk      ):          return HttpResponseRedirect("/")      wizards.TreatmentFileModificationWizard.session_set_value( @@ -1021,7 +1021,7 @@ treatmentfile_deletion_wizard = wizards.TreatmentFileDeletionWizard.as_view(  def treatmentfile_delete(request, pk):      if not wizard_is_available( -            treatmentfile_deletion_wizard, request, models.TreatmentFile, pk +        treatmentfile_deletion_wizard, request, models.TreatmentFile, pk      ):          return HttpResponseRedirect("/")      wizard_url = "treatmentfile_deletion" @@ -1078,10 +1078,10 @@ treatmentfile_admacttreatmentfile_modification_wizard = (  def treatmentfile_administrativeacttreatmentfile_modify(request, pk):      if not wizard_is_available( -            treatmentfile_admacttreatmentfile_modification_wizard, -            request, -            AdministrativeAct, -            pk, +        treatmentfile_admacttreatmentfile_modification_wizard, +        request, +        AdministrativeAct, +        pk,      ):          return HttpResponseRedirect("/")      wizards.TreatmentFileEditAdministrativeActWizard.session_set_value( @@ -1137,10 +1137,10 @@ treatmentfile_admacttreatmentfile_deletion_wizard = (  def treatmentfile_administrativeacttreatmentfile_delete(request, pk):      if not wizard_is_available( -            treatmentfile_admacttreatmentfile_deletion_wizard, -            request, -            AdministrativeAct, -            pk, +        treatmentfile_admacttreatmentfile_deletion_wizard, +        request, +        AdministrativeAct, +        pk,      ):          return HttpResponseRedirect("/")      wizard_url = "treatmentfle_admacttreatmentfle_deletion" @@ -1152,30 +1152,30 @@ def treatmentfile_administrativeacttreatmentfile_delete(request, pk):  def reset_wizards(request):      for wizard_class, url_name in ( -            (wizards.FindWizard, "find_creation"), -            (wizards.FindModificationWizard, "find_modification"), -            (wizards.FindDeletionWizard, "find_deletion"), -            (wizards.TreatmentWizard, "treatement_creation"), -            (wizards.TreatmentModificationWizard, "treatment_modification"), -            (wizards.TreatmentDeletionWizard, "treatment_deletion"), -            (wizards.TreatmentAdministrativeActWizard, "treatment_admacttreatment"), -            ( -                    wizards.TreatmentEditAdministrativeActWizard, -                    "treatment_admacttreatment_modification", -            ), -            (wizards.TreatmentDeletionWizard, "treatment_admacttreatment_deletion"), -            (wizards.TreatmentFileWizard, "treatmentfile_creation"), -            (wizards.TreatmentFileModificationWizard, "treatmentfile_modification"), -            (wizards.TreatmentFileDeletionWizard, "treatmentfile_deletion"), -            ( -                    wizards.TreatmentFileAdministrativeActWizard, -                    "treatmentfle_admacttreatmentfle", -            ), -            ( -                    wizards.TreatmentFileEditAdministrativeActWizard, -                    "treatmentfle_admacttreatmentfle_modification", -            ), -            (AdministrativeActDeletionWizard, "treatmentfle_admacttreatmentfle_deletion"), +        (wizards.FindWizard, "find_creation"), +        (wizards.FindModificationWizard, "find_modification"), +        (wizards.FindDeletionWizard, "find_deletion"), +        (wizards.TreatmentWizard, "treatement_creation"), +        (wizards.TreatmentModificationWizard, "treatment_modification"), +        (wizards.TreatmentDeletionWizard, "treatment_deletion"), +        (wizards.TreatmentAdministrativeActWizard, "treatment_admacttreatment"), +        ( +            wizards.TreatmentEditAdministrativeActWizard, +            "treatment_admacttreatment_modification", +        ), +        (wizards.TreatmentDeletionWizard, "treatment_admacttreatment_deletion"), +        (wizards.TreatmentFileWizard, "treatmentfile_creation"), +        (wizards.TreatmentFileModificationWizard, "treatmentfile_modification"), +        (wizards.TreatmentFileDeletionWizard, "treatmentfile_deletion"), +        ( +            wizards.TreatmentFileAdministrativeActWizard, +            "treatmentfle_admacttreatmentfle", +        ), +        ( +            wizards.TreatmentFileEditAdministrativeActWizard, +            "treatmentfle_admacttreatmentfle_modification", +        ), +        (AdministrativeActDeletionWizard, "treatmentfle_admacttreatmentfle_deletion"),      ):          wizard_class.session_reset(request, url_name) @@ -1300,8 +1300,8 @@ class PublicFindAPI(APIView):              return empty          q = (              models.FindBasket.items.through.objects.filter(findbasket_id=basket.id) -                .values("find_id") -                .order_by("id") +            .values("find_id") +            .order_by("id")          )          id_list = [bi["find_id"] for bi in q]          clauses = " ".join( @@ -1323,4 +1323,4 @@ def get_geo_items(request, pk, get_polygons, current_right=None):      if not base_find:          return Http404()      dic = base_find.get_geo_items(get_polygons=(get_polygons == "True")) -    return HttpResponse(json.dumps(dic).encode('utf-8')) +    return HttpResponse(json.dumps(dic).encode("utf-8")) diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index 3d8b4f8f6..982e02bf7 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -2860,28 +2860,35 @@ class GeoItem(models.Model):                      for linear_ring in range(len(polygon)):                          list_coords[-1].append([])                          for coords in polygon[linear_ring]: -                            point_2d = Point(coords[0], coords[1], srid=self.multi_polygon.srid) -                            list_coords[-1][linear_ring].append(self.convert_coordinates(point_2d, rounded)) +                            point_2d = Point( +                                coords[0], coords[1], srid=self.multi_polygon.srid +                            ) +                            list_coords[-1][linear_ring].append( +                                self.convert_coordinates(point_2d, rounded) +                            )                  dict["geometry"]["type"] = "MultiPolygon"                  dict["geometry"]["coordinates"] = list_coords              else:                  dict["geometry"]["type"] = "Point" -                dict["geometry"]["coordinates"] = self.convert_coordinates(self.multi_polygon.centroid, rounded) +                dict["geometry"]["coordinates"] = self.convert_coordinates( +                    self.multi_polygon.centroid, rounded +                )          else:              dict["geometry"]["type"] = "Point" -            x,y = self.display_coordinates -            dict["geometry"]["coordinates"] = [x,y] +            x, y = self.display_coordinates +            dict["geometry"]["coordinates"] = [x, y]          return dict      def convert_coordinates(self, point_2d, rounded):          profile = get_current_profile()          if ( -                not profile.display_srs -                or not profile.display_srs.srid -                or ( +            not profile.display_srs +            or not profile.display_srs.srid +            or (                  profile.display_srs == self.spatial_reference_system                  and point_2d.x -                and point_2d.y) +                and point_2d.y +            )          ):              x, y = point_2d.x, point_2d.y          else: | 
