master #341
@ -26,7 +26,7 @@ from konova.settings import DEFAULT_GROUP, ZB_GROUP, ETS_GROUP
|
||||
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
||||
from konova.utils.message_templates import COMPENSATION_REMOVED_TEMPLATE, DATA_CHECKED_PREVIOUSLY_TEMPLATE, \
|
||||
RECORDED_BLOCKS_EDIT, CHECKED_RECORDED_RESET, FORM_INVALID, PARAMS_INVALID, IDENTIFIER_REPLACED, \
|
||||
COMPENSATION_ADDED_TEMPLATE, DO_NOT_FORGET_TO_SHARE
|
||||
COMPENSATION_ADDED_TEMPLATE, DO_NOT_FORGET_TO_SHARE, GEOMETRY_SIMPLIFIED
|
||||
from konova.utils.user_checks import in_group
|
||||
|
||||
|
||||
@ -103,6 +103,11 @@ def new_view(request: HttpRequest, intervention_id: str = None):
|
||||
)
|
||||
)
|
||||
messages.success(request, COMPENSATION_ADDED_TEMPLATE.format(comp.identifier))
|
||||
if geom_form.geometry_simplified:
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRY_SIMPLIFIED
|
||||
)
|
||||
return redirect("compensation:detail", id=comp.id)
|
||||
else:
|
||||
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
||||
@ -175,6 +180,11 @@ def edit_view(request: HttpRequest, id: str):
|
||||
if intervention_recorded or intervention_checked:
|
||||
messages.info(request, CHECKED_RECORDED_RESET)
|
||||
messages.success(request, _("Compensation {} edited").format(comp.identifier))
|
||||
if geom_form.geometry_simplified:
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRY_SIMPLIFIED
|
||||
)
|
||||
return redirect("compensation:detail", id=comp.id)
|
||||
else:
|
||||
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
||||
@ -218,6 +228,8 @@ def detail_view(request: HttpRequest, id: str):
|
||||
_user = request.user
|
||||
is_data_shared = comp.intervention.is_shared_with(_user)
|
||||
|
||||
|
||||
|
||||
# Order states according to surface
|
||||
before_states = comp.before_states.all().prefetch_related("biotope_type").order_by("-surface")
|
||||
after_states = comp.after_states.all().prefetch_related("biotope_type").order_by("-surface")
|
||||
|
@ -22,7 +22,7 @@ from konova.forms import SimpleGeomForm
|
||||
from konova.settings import ETS_GROUP, DEFAULT_GROUP, ZB_GROUP
|
||||
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
||||
from konova.utils.message_templates import CANCEL_ACC_RECORDED_OR_DEDUCTED, RECORDED_BLOCKS_EDIT, FORM_INVALID, \
|
||||
IDENTIFIER_REPLACED, DO_NOT_FORGET_TO_SHARE
|
||||
IDENTIFIER_REPLACED, DO_NOT_FORGET_TO_SHARE, GEOMETRY_SIMPLIFIED
|
||||
from konova.utils.user_checks import in_group
|
||||
|
||||
|
||||
@ -84,6 +84,11 @@ def new_view(request: HttpRequest):
|
||||
)
|
||||
)
|
||||
messages.success(request, _("Eco-Account {} added").format(acc.identifier))
|
||||
if geom_form.geometry_simplified:
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRY_SIMPLIFIED
|
||||
)
|
||||
return redirect("compensation:acc:detail", id=acc.id)
|
||||
else:
|
||||
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
||||
@ -149,6 +154,11 @@ def edit_view(request: HttpRequest, id: str):
|
||||
# The data form takes the geom form for processing, as well as the performing user
|
||||
acc = data_form.save(request.user, geom_form)
|
||||
messages.success(request, _("Eco-Account {} edited").format(acc.identifier))
|
||||
if geom_form.geometry_simplified:
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRY_SIMPLIFIED
|
||||
)
|
||||
return redirect("compensation:acc:detail", id=acc.id)
|
||||
else:
|
||||
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
||||
|
@ -23,7 +23,7 @@ from konova.forms.modals import RemoveModalForm
|
||||
from konova.settings import DEFAULT_GROUP, ZB_GROUP, ETS_GROUP
|
||||
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
||||
from konova.utils.message_templates import RECORDED_BLOCKS_EDIT, IDENTIFIER_REPLACED, FORM_INVALID, \
|
||||
DO_NOT_FORGET_TO_SHARE
|
||||
DO_NOT_FORGET_TO_SHARE, GEOMETRY_SIMPLIFIED
|
||||
from konova.utils.user_checks import in_group
|
||||
|
||||
|
||||
@ -84,6 +84,12 @@ def new_view(request: HttpRequest):
|
||||
)
|
||||
)
|
||||
messages.success(request, _("EMA {} added").format(ema.identifier))
|
||||
if geom_form.geometry_simplified:
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRY_SIMPLIFIED
|
||||
)
|
||||
|
||||
return redirect("ema:detail", id=ema.id)
|
||||
else:
|
||||
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
||||
@ -208,6 +214,11 @@ def edit_view(request: HttpRequest, id: str):
|
||||
# The data form takes the geom form for processing, as well as the performing user
|
||||
ema = data_form.save(request.user, geom_form)
|
||||
messages.success(request, _("EMA {} edited").format(ema.identifier))
|
||||
if geom_form.geometry_simplified:
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRY_SIMPLIFIED
|
||||
)
|
||||
return redirect("ema:detail", id=ema.id)
|
||||
else:
|
||||
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
||||
|
@ -22,7 +22,7 @@ from konova.forms.modals import RemoveModalForm
|
||||
from konova.settings import DEFAULT_GROUP, ZB_GROUP, ETS_GROUP
|
||||
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
||||
from konova.utils.message_templates import DATA_CHECKED_PREVIOUSLY_TEMPLATE, RECORDED_BLOCKS_EDIT, \
|
||||
CHECKED_RECORDED_RESET, FORM_INVALID, IDENTIFIER_REPLACED, DO_NOT_FORGET_TO_SHARE
|
||||
CHECKED_RECORDED_RESET, FORM_INVALID, IDENTIFIER_REPLACED, DO_NOT_FORGET_TO_SHARE, GEOMETRY_SIMPLIFIED
|
||||
from konova.utils.user_checks import in_group
|
||||
|
||||
|
||||
@ -88,6 +88,11 @@ def new_view(request: HttpRequest):
|
||||
)
|
||||
)
|
||||
messages.success(request, _("Intervention {} added").format(intervention.identifier))
|
||||
if geom_form.geometry_simplified:
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRY_SIMPLIFIED
|
||||
)
|
||||
return redirect("intervention:detail", id=intervention.id)
|
||||
else:
|
||||
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
||||
@ -231,6 +236,11 @@ def edit_view(request: HttpRequest, id: str):
|
||||
messages.success(request, _("Intervention {} edited").format(intervention.identifier))
|
||||
if i_check or i_rec:
|
||||
messages.info(request, CHECKED_RECORDED_RESET)
|
||||
if geom_form.geometry_simplified:
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRY_SIMPLIFIED
|
||||
)
|
||||
return redirect("intervention:detail", id=intervention.id)
|
||||
else:
|
||||
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
||||
|
@ -15,6 +15,7 @@ from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from konova.forms.base_form import BaseForm
|
||||
from konova.models import Geometry
|
||||
from konova.settings import GEOM_MAX_VERTICES
|
||||
from konova.tasks import celery_update_parcels, celery_check_for_geometry_conflicts
|
||||
from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP
|
||||
from user.models import UserActionLogEntry
|
||||
@ -25,6 +26,7 @@ class SimpleGeomForm(BaseForm):
|
||||
|
||||
"""
|
||||
read_only = True
|
||||
geometry_simplified = False
|
||||
geom = MultiPolygonField(
|
||||
srid=DEFAULT_SRID_RLP,
|
||||
label=_("Geometry"),
|
||||
@ -124,6 +126,38 @@ class SimpleGeomForm(BaseForm):
|
||||
|
||||
return is_valid
|
||||
|
||||
def __is_vertices_num_valid(self):
|
||||
""" Checks whether the number of vertices in the geometry is not too high
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
geom = self.cleaned_data.get("geom")
|
||||
g = gdal.OGRGeometry(geom, srs=DEFAULT_SRID_RLP)
|
||||
num_vertices = g.num_coords
|
||||
|
||||
return num_vertices <= GEOM_MAX_VERTICES
|
||||
|
||||
def __simplify_geometry(self, geom, max_vert: int):
|
||||
""" Simplifies a geometry
|
||||
|
||||
Geometry will be simplified until a threshold of max vertices has been reached.
|
||||
|
||||
Args:
|
||||
geom (MultiPolygon): The geometry
|
||||
max_vert (int): Threshold of maximum vertices in geometry
|
||||
|
||||
Returns:
|
||||
geom (MultiPolygon): The simplified geometry
|
||||
"""
|
||||
tolerance = 0.1
|
||||
n = geom.num_coords
|
||||
while(n > max_vert):
|
||||
geom = geom.simplify(tolerance)
|
||||
n = geom.num_coords
|
||||
tolerance += 0.1
|
||||
return geom
|
||||
|
||||
def save(self, action: UserActionLogEntry):
|
||||
""" Saves the form's geometry
|
||||
|
||||
@ -149,6 +183,13 @@ class SimpleGeomForm(BaseForm):
|
||||
geom=self.cleaned_data.get("geom", MultiPolygon(srid=DEFAULT_SRID_RLP)),
|
||||
created=action,
|
||||
)
|
||||
|
||||
is_vertices_num_valid = self.__is_vertices_num_valid()
|
||||
if not is_vertices_num_valid:
|
||||
geometry.geom = self.__simplify_geometry(geometry.geom, max_vert=GEOM_MAX_VERTICES)
|
||||
geometry.save()
|
||||
self.geometry_simplified = True
|
||||
|
||||
# Start parcel update and geometry conflict checking procedure in a background process
|
||||
celery_update_parcels.delay(geometry.id)
|
||||
celery_check_for_geometry_conflicts.delay(geometry.id)
|
||||
|
@ -44,3 +44,5 @@ STRF_DATE_TIME = "%d.%m.%Y %H:%M:%S"
|
||||
DEFAULT_GROUP = "Default"
|
||||
ZB_GROUP = "Registration office"
|
||||
ETS_GROUP = "Conservation office"
|
||||
|
||||
GEOM_MAX_VERTICES = 10000
|
||||
|
@ -7,6 +7,8 @@ Created on: 02.08.21
|
||||
"""
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from konova.settings import GEOM_MAX_VERTICES
|
||||
|
||||
NO_DETAILS = _("no further details")
|
||||
UNKNOWN = _("Unknown")
|
||||
UNGROUPED = _("Ungrouped")
|
||||
@ -79,8 +81,9 @@ DOCUMENT_EDITED = _("Document edited")
|
||||
EDITED_GENERAL_DATA = _("Edited general data")
|
||||
ADDED_DEADLINE = _("Added deadline")
|
||||
|
||||
# Geometry conflicts
|
||||
# Geometry
|
||||
GEOMETRY_CONFLICT_WITH_TEMPLATE = _("Geometry conflict detected with {}")
|
||||
GEOMETRY_SIMPLIFIED = _("The geometry contained more than {} vertices. It had to be simplified to match the allowed limit of {} vertices.").format(GEOM_MAX_VERTICES, GEOM_MAX_VERTICES)
|
||||
|
||||
# INTERVENTION
|
||||
INTERVENTION_HAS_REVOCATIONS_TEMPLATE = _("This intervention has {} revocations")
|
||||
|
@ -6,6 +6,7 @@ Created on: 19.08.22
|
||||
|
||||
"""
|
||||
import json
|
||||
from json import JSONDecodeError
|
||||
|
||||
import requests
|
||||
from django.contrib.auth.decorators import login_required
|
||||
@ -13,6 +14,8 @@ from django.http import JsonResponse, HttpRequest
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.utils.http import urlencode
|
||||
from django.views import View
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from requests.auth import HTTPDigestAuth
|
||||
|
||||
from konova.sub_settings.proxy_settings import PROXIES, CLIENT_PROXY_AUTH_USER, CLIENT_PROXY_AUTH_PASSWORD
|
||||
@ -57,7 +60,18 @@ class ClientProxyParcelSearch(BaseClientProxyView):
|
||||
def get(self, request: HttpRequest):
|
||||
url = request.META.get("QUERY_STRING")
|
||||
content, response_code = self.perform_url_call(url)
|
||||
body = json.loads(content)
|
||||
try:
|
||||
body = json.loads(content)
|
||||
except JSONDecodeError as e:
|
||||
body = {
|
||||
"totalResultsCount": -1,
|
||||
"geonames": [
|
||||
{
|
||||
"title": _("The external service is currently unavailable.<br>Please try again in a few moments...")
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
if response_code != 200:
|
||||
return JsonResponse({
|
||||
"status_code": response_code,
|
||||
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user