Skip to content

Commit

Permalink
Revert "Save centroid of geometry when the geometry is not a point (k…
Browse files Browse the repository at this point in the history
…artoza#3422)"

This reverts commit 918ed19.
  • Loading branch information
dimasciput committed Jul 30, 2023
1 parent b736e08 commit 7c604df
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
17 changes: 5 additions & 12 deletions bims/models/location_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,7 @@ def data_name(self):
def get_centroid(self):
""" Getting centroid of location site """

if (
self.geometry_point and
self.location_type.allowed_geometry == 'POINT'
):
if self.geometry_point:
return self.geometry_point
else:
if self.get_geometry():
Expand All @@ -201,11 +198,10 @@ def get_geometry(self):
geometry = None
validation_error = ValidationError('Only one geometry allowed.')

if (
self.geometry_point and
self.location_type.allowed_geometry == 'POINT'
):
return self.geometry_point
if self.geometry_point:
if geometry:
raise validation_error
geometry = self.geometry_point

if self.geometry_polygon:
if geometry:
Expand Down Expand Up @@ -407,9 +403,6 @@ def save(self, *args, **kwargs):
if not lon_lat_changed:
self.geometry_point.x = self.longitude
self.geometry_point.y = self.latitude
if self.location_type.allowed_geometry != 'POINT':
self.geometry_point = self.get_centroid()

super(LocationSite, self).save(*args, **kwargs)
self.__original_centroid = self.get_centroid()
else:
Expand Down
11 changes: 6 additions & 5 deletions bims/static/js/forms/location-site-admin-form.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
(function ($) {
$(document).ready(function () {
var $geometryInput = $('[class*="geometry_"]').not(".geometry_point");
var $geometryInput = $('[class*="geometry_"]');
var init = true;
$geometryInput.hide();
function resetAllGeometries() {
geodjango_geometry_point.clearFeatures();
geodjango_geometry_line.clearFeatures();
geodjango_geometry_polygon.clearFeatures();
geodjango_geometry_multipolygon.clearFeatures();
Expand All @@ -17,14 +18,14 @@
if ($(this).val()) {
$.get("/api/location-type/" + $(this).val() + '/allowed-geometry/', function (data) {
var className = 'geometry_' + data.toLowerCase();
$geometryInput.not('.' + className).not(".geometry_point").hide();
$geometryInput.not('.' + className).hide();
if (!$('.' + className).is(":visible")) {
$('.' + className).show();
}
})
.fail(function () {
console.log('fail');
})
.fail(function () {
console.log('fail');
})
} else {
$geometryInput.hide();
}
Expand Down

0 comments on commit 7c604df

Please sign in to comment.