Compare commits
13 Commits
55cc8eb1f3
...
1.13
| Author | SHA1 | Date | |
|---|---|---|---|
| e5db7f6b13 | |||
| 442f3ceb37 | |||
| cd2949fc03 | |||
| 7bcd32fd7a | |||
| 97f1882698 | |||
| d6cabd5f6c | |||
| 63a824f9d9 | |||
| a12c2fb57e | |||
| 23bc79ee3b | |||
| 07bac26a58 | |||
| d01816cf71 | |||
| f543dfc1cb | |||
| 62fc019127 |
@@ -12,7 +12,7 @@ from django.contrib.gis import geos
|
||||
from django.urls import reverse
|
||||
|
||||
from api.tests.v1.share.test_api_sharing import BaseAPIV1TestCase
|
||||
from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP
|
||||
from konova.models import Geometry
|
||||
|
||||
|
||||
class APIV1UpdateTestCase(BaseAPIV1TestCase):
|
||||
@@ -64,7 +64,7 @@ class APIV1UpdateTestCase(BaseAPIV1TestCase):
|
||||
|
||||
put_props = put_body["properties"]
|
||||
put_geom = geos.fromstr(json.dumps(put_body))
|
||||
put_geom.transform(DEFAULT_SRID_RLP)
|
||||
put_geom = Geometry.cast_to_rlp_srid(put_geom)
|
||||
self.assertEqual(put_geom, self.intervention.geometry.geom)
|
||||
self.assertEqual(put_props["title"], self.intervention.title)
|
||||
self.assertNotEqual(modified_on, self.intervention.modified)
|
||||
@@ -94,7 +94,7 @@ class APIV1UpdateTestCase(BaseAPIV1TestCase):
|
||||
|
||||
put_props = put_body["properties"]
|
||||
put_geom = geos.fromstr(json.dumps(put_body))
|
||||
put_geom.transform(DEFAULT_SRID_RLP)
|
||||
put_geom = Geometry.cast_to_rlp_srid(put_geom)
|
||||
self.assertEqual(put_geom, self.compensation.geometry.geom)
|
||||
self.assertEqual(put_props["title"], self.compensation.title)
|
||||
self.assertNotEqual(modified_on, self.compensation.modified)
|
||||
@@ -124,7 +124,7 @@ class APIV1UpdateTestCase(BaseAPIV1TestCase):
|
||||
|
||||
put_props = put_body["properties"]
|
||||
put_geom = geos.fromstr(json.dumps(put_body))
|
||||
put_geom.transform(DEFAULT_SRID_RLP)
|
||||
put_geom = Geometry.cast_to_rlp_srid(put_geom)
|
||||
self.assertEqual(put_geom, self.eco_account.geometry.geom)
|
||||
self.assertEqual(put_props["title"], self.eco_account.title)
|
||||
self.assertNotEqual(modified_on, self.eco_account.modified)
|
||||
@@ -156,7 +156,7 @@ class APIV1UpdateTestCase(BaseAPIV1TestCase):
|
||||
|
||||
put_props = put_body["properties"]
|
||||
put_geom = geos.fromstr(json.dumps(put_body))
|
||||
put_geom.transform(DEFAULT_SRID_RLP)
|
||||
put_geom = Geometry.cast_to_rlp_srid(put_geom)
|
||||
self.assertEqual(put_geom, self.ema.geometry.geom)
|
||||
self.assertEqual(put_props["title"], self.ema.title)
|
||||
self.assertNotEqual(modified_on, self.ema.modified)
|
||||
|
||||
@@ -13,7 +13,7 @@ from django.contrib.gis.geos import GEOSGeometry
|
||||
from django.core.paginator import Paginator
|
||||
from django.db.models import Q
|
||||
|
||||
from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP
|
||||
from konova.models import Geometry
|
||||
from konova.utils.message_templates import DATA_UNSHARED
|
||||
|
||||
|
||||
@@ -145,8 +145,8 @@ class AbstractModelAPISerializer:
|
||||
if isinstance(geojson, dict):
|
||||
geojson = json.dumps(geojson)
|
||||
geometry = geos.fromstr(geojson)
|
||||
if geometry.srid != DEFAULT_SRID_RLP:
|
||||
geometry.transform(DEFAULT_SRID_RLP)
|
||||
geometry = Geometry.cast_to_rlp_srid(geometry)
|
||||
geometry = Geometry.cast_to_multipolygon(geometry)
|
||||
return geometry
|
||||
|
||||
def _get_obj_from_db(self, id, user):
|
||||
|
||||
@@ -54,7 +54,7 @@ class CompensationWorkflowTestCase(BaseWorkflowTestCase):
|
||||
post_data = {
|
||||
"identifier": test_id,
|
||||
"title": test_title,
|
||||
"geom": geom_json,
|
||||
"output": geom_json,
|
||||
"intervention": self.intervention.id,
|
||||
}
|
||||
pre_creation_intervention_log_count = self.intervention.log.count()
|
||||
@@ -94,7 +94,7 @@ class CompensationWorkflowTestCase(BaseWorkflowTestCase):
|
||||
post_data = {
|
||||
"identifier": test_id,
|
||||
"title": test_title,
|
||||
"geom": geom_json,
|
||||
"output": geom_json,
|
||||
}
|
||||
pre_creation_intervention_log_count = self.intervention.log.count()
|
||||
|
||||
@@ -150,7 +150,7 @@ class CompensationWorkflowTestCase(BaseWorkflowTestCase):
|
||||
"title": new_title,
|
||||
"intervention": self.intervention.id, # just keep the intervention as it is
|
||||
"comment": new_comment,
|
||||
"geom": geojson,
|
||||
"output": geojson,
|
||||
}
|
||||
self.client_user.post(url, post_data)
|
||||
self.compensation.refresh_from_db()
|
||||
|
||||
@@ -46,7 +46,7 @@ class EcoAccountWorkflowTestCase(BaseWorkflowTestCase):
|
||||
post_data = {
|
||||
"identifier": test_id,
|
||||
"title": test_title,
|
||||
"geom": geom_json,
|
||||
"output": geom_json,
|
||||
"surface": test_deductable_surface,
|
||||
"conservation_office": test_conservation_office.id
|
||||
}
|
||||
@@ -86,7 +86,7 @@ class EcoAccountWorkflowTestCase(BaseWorkflowTestCase):
|
||||
new_title = self.create_dummy_string()
|
||||
new_identifier = self.create_dummy_string()
|
||||
new_comment = self.create_dummy_string()
|
||||
new_geometry = MultiPolygon(srid=4326) # Create an empty geometry
|
||||
new_geometry = self.create_dummy_geometry()
|
||||
test_conservation_office = self.get_conservation_office_code()
|
||||
test_deductable_surface = self.eco_account.deductable_surface + 100
|
||||
|
||||
@@ -103,7 +103,7 @@ class EcoAccountWorkflowTestCase(BaseWorkflowTestCase):
|
||||
"identifier": new_identifier,
|
||||
"title": new_title,
|
||||
"comment": new_comment,
|
||||
"geom": new_geometry.geojson,
|
||||
"output": self.create_geojson(new_geometry),
|
||||
"surface": test_deductable_surface,
|
||||
"conservation_office": test_conservation_office.id
|
||||
}
|
||||
|
||||
@@ -27,7 +27,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, CHECK_STATE_RESET, FORM_INVALID, PARAMS_INVALID, IDENTIFIER_REPLACED, \
|
||||
COMPENSATION_ADDED_TEMPLATE, DO_NOT_FORGET_TO_SHARE, GEOMETRY_SIMPLIFIED
|
||||
COMPENSATION_ADDED_TEMPLATE, DO_NOT_FORGET_TO_SHARE, GEOMETRY_SIMPLIFIED, GEOMETRIES_IGNORED_TEMPLATE
|
||||
|
||||
|
||||
@login_required
|
||||
@@ -103,11 +103,19 @@ def new_view(request: HttpRequest, intervention_id: str = None):
|
||||
)
|
||||
)
|
||||
messages.success(request, COMPENSATION_ADDED_TEMPLATE.format(comp.identifier))
|
||||
if geom_form.geometry_simplified:
|
||||
if geom_form.has_geometry_simplified():
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRY_SIMPLIFIED
|
||||
)
|
||||
|
||||
num_ignored_geometries = geom_form.get_num_geometries_ignored()
|
||||
if num_ignored_geometries > 0:
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRIES_IGNORED_TEMPLATE.format(num_ignored_geometries)
|
||||
)
|
||||
|
||||
return redirect("compensation:detail", id=comp.id)
|
||||
else:
|
||||
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
||||
@@ -179,11 +187,19 @@ def edit_view(request: HttpRequest, id: str):
|
||||
if intervention_is_checked:
|
||||
messages.info(request, CHECK_STATE_RESET)
|
||||
messages.success(request, _("Compensation {} edited").format(comp.identifier))
|
||||
if geom_form.geometry_simplified:
|
||||
if geom_form.has_geometry_simplified():
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRY_SIMPLIFIED
|
||||
)
|
||||
|
||||
num_ignored_geometries = geom_form.get_num_geometries_ignored()
|
||||
if num_ignored_geometries > 0:
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRIES_IGNORED_TEMPLATE.format(num_ignored_geometries)
|
||||
)
|
||||
|
||||
return redirect("compensation:detail", id=comp.id)
|
||||
else:
|
||||
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
||||
|
||||
@@ -12,11 +12,12 @@ from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from compensation.models import Compensation
|
||||
from konova.contexts import BaseContext
|
||||
from konova.decorators import uuid_required
|
||||
from konova.forms import SimpleGeomForm
|
||||
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
||||
from konova.utils.generators import generate_qr_code
|
||||
|
||||
|
||||
@uuid_required
|
||||
def report_view(request: HttpRequest, id: str):
|
||||
""" Renders the public report view
|
||||
|
||||
|
||||
@@ -23,7 +23,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, GEOMETRY_SIMPLIFIED
|
||||
IDENTIFIER_REPLACED, DO_NOT_FORGET_TO_SHARE, GEOMETRY_SIMPLIFIED, GEOMETRIES_IGNORED_TEMPLATE
|
||||
|
||||
|
||||
@login_required
|
||||
@@ -84,11 +84,19 @@ def new_view(request: HttpRequest):
|
||||
)
|
||||
)
|
||||
messages.success(request, _("Eco-Account {} added").format(acc.identifier))
|
||||
if geom_form.geometry_simplified:
|
||||
if geom_form.has_geometry_simplified():
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRY_SIMPLIFIED
|
||||
)
|
||||
|
||||
num_ignored_geometries = geom_form.get_num_geometries_ignored()
|
||||
if num_ignored_geometries > 0:
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRIES_IGNORED_TEMPLATE.format(num_ignored_geometries)
|
||||
)
|
||||
|
||||
return redirect("compensation:acc:detail", id=acc.id)
|
||||
else:
|
||||
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
||||
@@ -156,11 +164,19 @@ 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:
|
||||
if geom_form.has_geometry_simplified():
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRY_SIMPLIFIED
|
||||
)
|
||||
|
||||
num_ignored_geometries = geom_form.get_num_geometries_ignored()
|
||||
if num_ignored_geometries > 0:
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRIES_IGNORED_TEMPLATE.format(num_ignored_geometries)
|
||||
)
|
||||
|
||||
return redirect("compensation:acc:detail", id=acc.id)
|
||||
else:
|
||||
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
||||
|
||||
@@ -12,11 +12,13 @@ from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from compensation.models import EcoAccount
|
||||
from konova.contexts import BaseContext
|
||||
from konova.decorators import uuid_required
|
||||
from konova.forms import SimpleGeomForm
|
||||
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
||||
from konova.utils.generators import generate_qr_code
|
||||
|
||||
|
||||
@uuid_required
|
||||
def report_view(request: HttpRequest, id: str):
|
||||
""" Renders the public report view
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ class EmaWorkflowTestCase(BaseWorkflowTestCase):
|
||||
post_data = {
|
||||
"identifier": test_id,
|
||||
"title": test_title,
|
||||
"geom": geom_json,
|
||||
"output": geom_json,
|
||||
"conservation_office": test_conservation_office.id
|
||||
}
|
||||
self.client_user.post(new_url, post_data)
|
||||
@@ -84,7 +84,7 @@ class EmaWorkflowTestCase(BaseWorkflowTestCase):
|
||||
new_title = self.create_dummy_string()
|
||||
new_identifier = self.create_dummy_string()
|
||||
new_comment = self.create_dummy_string()
|
||||
new_geometry = MultiPolygon(srid=4326) # Create an empty geometry
|
||||
new_geometry = self.create_dummy_geometry() # Create an empty geometry
|
||||
test_conservation_office = self.get_conservation_office_code()
|
||||
|
||||
check_on_elements = {
|
||||
@@ -99,7 +99,7 @@ class EmaWorkflowTestCase(BaseWorkflowTestCase):
|
||||
"identifier": new_identifier,
|
||||
"title": new_title,
|
||||
"comment": new_comment,
|
||||
"geom": new_geometry.geojson,
|
||||
"output": self.create_geojson(new_geometry),
|
||||
"conservation_office": test_conservation_office.id
|
||||
}
|
||||
self.client_user.post(url, post_data)
|
||||
|
||||
@@ -48,7 +48,7 @@ class NewEmaFormTestCase(BaseTestCase):
|
||||
)
|
||||
geom_form_data = json.loads(geom_form_data)
|
||||
geom_form_data = {
|
||||
"geom": json.dumps(geom_form_data)
|
||||
"output": json.dumps(geom_form_data)
|
||||
}
|
||||
|
||||
geom_form = SimpleGeomForm(geom_form_data)
|
||||
@@ -116,7 +116,7 @@ class EditEmaFormTestCase(BaseTestCase):
|
||||
)
|
||||
geom_form_data = json.loads(geom_form_data)
|
||||
geom_form_data = {
|
||||
"geom": json.dumps(geom_form_data)
|
||||
"output": json.dumps(geom_form_data)
|
||||
}
|
||||
|
||||
geom_form = SimpleGeomForm(geom_form_data)
|
||||
|
||||
@@ -24,7 +24,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, GEOMETRY_SIMPLIFIED
|
||||
DO_NOT_FORGET_TO_SHARE, GEOMETRY_SIMPLIFIED, GEOMETRIES_IGNORED_TEMPLATE
|
||||
|
||||
|
||||
@login_required
|
||||
@@ -84,11 +84,17 @@ def new_view(request: HttpRequest):
|
||||
)
|
||||
)
|
||||
messages.success(request, _("EMA {} added").format(ema.identifier))
|
||||
if geom_form.geometry_simplified:
|
||||
if geom_form.has_geometry_simplified():
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRY_SIMPLIFIED
|
||||
)
|
||||
num_ignored_geometries = geom_form.get_num_geometries_ignored()
|
||||
if num_ignored_geometries > 0:
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRIES_IGNORED_TEMPLATE.format(num_ignored_geometries)
|
||||
)
|
||||
|
||||
return redirect("ema:detail", id=ema.id)
|
||||
else:
|
||||
@@ -215,11 +221,19 @@ 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:
|
||||
if geom_form.has_geometry_simplified():
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRY_SIMPLIFIED
|
||||
)
|
||||
|
||||
num_ignored_geometries = geom_form.get_num_geometries_ignored()
|
||||
if num_ignored_geometries > 0:
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRIES_IGNORED_TEMPLATE.format(num_ignored_geometries)
|
||||
)
|
||||
|
||||
return redirect("ema:detail", id=ema.id)
|
||||
else:
|
||||
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
||||
|
||||
@@ -12,11 +12,12 @@ from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from ema.models import Ema
|
||||
from konova.contexts import BaseContext
|
||||
from konova.decorators import uuid_required
|
||||
from konova.forms import SimpleGeomForm
|
||||
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
||||
from konova.utils.generators import generate_qr_code
|
||||
|
||||
|
||||
@uuid_required
|
||||
def report_view(request:HttpRequest, id: str):
|
||||
""" Renders the public report view
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ class InterventionWorkflowTestCase(BaseWorkflowTestCase):
|
||||
post_data = {
|
||||
"identifier": test_id,
|
||||
"title": test_title,
|
||||
"geom": geom_json,
|
||||
"output": geom_json,
|
||||
}
|
||||
response = self.client_user.post(
|
||||
new_url,
|
||||
|
||||
@@ -62,7 +62,7 @@ class NewInterventionFormTestCase(BaseTestCase):
|
||||
)
|
||||
geom_form_data = json.loads(geom_form_data)
|
||||
geom_form_data = {
|
||||
"geom": json.dumps(geom_form_data)
|
||||
"output": json.dumps(geom_form_data)
|
||||
}
|
||||
geom_form = SimpleGeomForm(geom_form_data)
|
||||
|
||||
@@ -104,7 +104,7 @@ class EditInterventionFormTestCase(NewInterventionFormTestCase):
|
||||
)
|
||||
geom_form_data = json.loads(geom_form_data)
|
||||
geom_form_data = {
|
||||
"geom": json.dumps(geom_form_data)
|
||||
"output": json.dumps(geom_form_data)
|
||||
}
|
||||
|
||||
geom_form = SimpleGeomForm(geom_form_data)
|
||||
@@ -124,7 +124,7 @@ class EditInterventionFormTestCase(NewInterventionFormTestCase):
|
||||
self.assertIsNotNone(obj.responsible.handler)
|
||||
self.assertEqual(obj.title, data["title"])
|
||||
self.assertEqual(obj.comment, data["comment"])
|
||||
self.assertTrue(test_geom.equals_exact(obj.geometry.geom, 0.000001))
|
||||
self.assert_equal_geometries(test_geom, obj.geometry.geom)
|
||||
|
||||
self.assertEqual(obj.legal.binding_date, today)
|
||||
self.assertEqual(obj.legal.registration_date, today)
|
||||
|
||||
@@ -23,7 +23,8 @@ 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, \
|
||||
CHECK_STATE_RESET, FORM_INVALID, IDENTIFIER_REPLACED, DO_NOT_FORGET_TO_SHARE, GEOMETRY_SIMPLIFIED
|
||||
CHECK_STATE_RESET, FORM_INVALID, IDENTIFIER_REPLACED, DO_NOT_FORGET_TO_SHARE, GEOMETRY_SIMPLIFIED, \
|
||||
GEOMETRIES_IGNORED_TEMPLATE
|
||||
|
||||
|
||||
@login_required
|
||||
@@ -88,11 +89,19 @@ def new_view(request: HttpRequest):
|
||||
)
|
||||
)
|
||||
messages.success(request, _("Intervention {} added").format(intervention.identifier))
|
||||
if geom_form.geometry_simplified:
|
||||
if geom_form.has_geometry_simplified():
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRY_SIMPLIFIED
|
||||
)
|
||||
|
||||
num_ignored_geometries = geom_form.get_num_geometries_ignored()
|
||||
if num_ignored_geometries > 0:
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRIES_IGNORED_TEMPLATE.format(num_ignored_geometries)
|
||||
)
|
||||
|
||||
return redirect("intervention:detail", id=intervention.id)
|
||||
else:
|
||||
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
||||
@@ -236,11 +245,19 @@ def edit_view(request: HttpRequest, id: str):
|
||||
messages.success(request, _("Intervention {} edited").format(intervention.identifier))
|
||||
if intervention_is_checked:
|
||||
messages.info(request, CHECK_STATE_RESET)
|
||||
if geom_form.geometry_simplified:
|
||||
if geom_form.has_geometry_simplified():
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRY_SIMPLIFIED
|
||||
)
|
||||
|
||||
num_ignored_geometries = geom_form.get_num_geometries_ignored()
|
||||
if num_ignored_geometries > 0:
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRIES_IGNORED_TEMPLATE.format(num_ignored_geometries)
|
||||
)
|
||||
|
||||
return redirect("intervention:detail", id=intervention.id)
|
||||
else:
|
||||
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
||||
|
||||
@@ -11,7 +11,7 @@ from uuid import UUID
|
||||
|
||||
from bootstrap_modal_forms.mixins import is_ajax
|
||||
from django.contrib import messages
|
||||
from django.http import Http404
|
||||
from django.core.exceptions import BadRequest
|
||||
from django.shortcuts import redirect, get_object_or_404, render
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
@@ -185,7 +185,7 @@ def uuid_required(function):
|
||||
try:
|
||||
uuid = UUID(uuid)
|
||||
except ValueError:
|
||||
raise Http404(
|
||||
raise BadRequest(
|
||||
"Invalid UUID"
|
||||
)
|
||||
return function(request, *args, **kwargs)
|
||||
|
||||
@@ -25,8 +25,8 @@ class SimpleGeomForm(BaseForm):
|
||||
""" A geometry form for rendering geometry read-only using a widget
|
||||
|
||||
"""
|
||||
read_only = True
|
||||
geometry_simplified = False
|
||||
read_only: bool = True
|
||||
_geometry_simplified: bool = False
|
||||
output = JSONField(
|
||||
label=_("Geometry"),
|
||||
help_text=_(""),
|
||||
@@ -34,6 +34,7 @@ class SimpleGeomForm(BaseForm):
|
||||
required=False,
|
||||
disabled=False,
|
||||
)
|
||||
_num_geometries_ignored: int = 0
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.read_only = kwargs.pop("read_only", True)
|
||||
@@ -48,7 +49,7 @@ class SimpleGeomForm(BaseForm):
|
||||
raise AttributeError
|
||||
|
||||
geojson = self.instance.geometry.as_feature_collection(srid=DEFAULT_SRID_RLP)
|
||||
geojson = self._set_properties(geojson, self.instance.identifier)
|
||||
self._set_geojson_properties(geojson, title=self.instance.identifier or None)
|
||||
geom = json.dumps(geojson)
|
||||
except AttributeError:
|
||||
# If no geometry exists for this form, we simply set the value to None and zoom to the maximum level
|
||||
@@ -62,7 +63,7 @@ class SimpleGeomForm(BaseForm):
|
||||
is_valid = True
|
||||
|
||||
# Get geojson from form
|
||||
geom = self.data["output"]
|
||||
geom = self.data.get("output", None)
|
||||
if geom is None or len(geom) == 0:
|
||||
# empty geometry is a valid geometry
|
||||
self.cleaned_data["output"] = MultiPolygon(srid=DEFAULT_SRID_RLP).ewkt
|
||||
@@ -73,9 +74,8 @@ class SimpleGeomForm(BaseForm):
|
||||
# will be rendered again on failed submit
|
||||
self.initialize_form_field("output", self.data["output"])
|
||||
|
||||
# Read geojson into gdal geometry
|
||||
# HINT: This can be simplified if the geojson format holds data in epsg:4326 (GDAL provides direct creation for
|
||||
# this case)
|
||||
# Initialize features list with empty MultiPolygon, so that an empty input will result in a
|
||||
# proper empty MultiPolygon object
|
||||
features = []
|
||||
features_json = geom.get("features", [])
|
||||
accepted_ogr_types = [
|
||||
@@ -102,24 +102,32 @@ class SimpleGeomForm(BaseForm):
|
||||
is_valid &= False
|
||||
return is_valid
|
||||
|
||||
is_valid &= self.__is_area_valid(g)
|
||||
is_area_valid = self.__is_area_valid(g)
|
||||
if not is_area_valid:
|
||||
# Geometries with an invalid size will not be saved to the db
|
||||
# We assume these are malicious snippets which are not supposed to be in the geometry in the first place
|
||||
self._num_geometries_ignored += 1
|
||||
continue
|
||||
|
||||
polygon = Polygon.from_ewkt(g.ewkt)
|
||||
is_valid &= polygon.valid
|
||||
if not polygon.valid:
|
||||
self.add_error("output", polygon.valid_reason)
|
||||
g = Polygon.from_ewkt(g.ewkt)
|
||||
is_valid &= g.valid
|
||||
if not g.valid:
|
||||
self.add_error("output", g.valid_reason)
|
||||
return is_valid
|
||||
|
||||
features.append(polygon)
|
||||
if isinstance(g, Polygon):
|
||||
features.append(g)
|
||||
elif isinstance(g, MultiPolygon):
|
||||
features.extend(list(g))
|
||||
|
||||
# Unionize all geometry features into one new MultiPolygon
|
||||
form_geom = MultiPolygon(srid=DEFAULT_SRID_RLP)
|
||||
for feature in features:
|
||||
form_geom = form_geom.union(feature)
|
||||
if features:
|
||||
form_geom = MultiPolygon(*features, srid=DEFAULT_SRID_RLP).unary_union
|
||||
else:
|
||||
form_geom = MultiPolygon(srid=DEFAULT_SRID_RLP)
|
||||
|
||||
# Make sure to convert into a MultiPolygon. Relevant if a single Polygon is provided.
|
||||
if form_geom.geom_type != "MultiPolygon":
|
||||
form_geom = MultiPolygon(form_geom, srid=DEFAULT_SRID_RLP)
|
||||
form_geom = Geometry.cast_to_multipolygon(form_geom)
|
||||
|
||||
# Write unioned Multipolygon into cleaned data
|
||||
if self.cleaned_data is None:
|
||||
@@ -147,15 +155,6 @@ class SimpleGeomForm(BaseForm):
|
||||
|
||||
"""
|
||||
is_area_valid = geom.area > 1 # > 1m² (SRID:25832)
|
||||
|
||||
if not is_area_valid:
|
||||
self.add_error(
|
||||
"output",
|
||||
_("Geometry must be greater than 1m². Currently is {}m²").format(
|
||||
float(geom.area)
|
||||
)
|
||||
)
|
||||
|
||||
return is_area_valid
|
||||
|
||||
def __simplify_geometry(self, geom, max_vert: int):
|
||||
@@ -208,13 +207,29 @@ class SimpleGeomForm(BaseForm):
|
||||
if not is_vertices_num_valid:
|
||||
geometry.geom = self.__simplify_geometry(geometry.geom, max_vert=GEOM_MAX_VERTICES)
|
||||
geometry.save()
|
||||
self.geometry_simplified = True
|
||||
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)
|
||||
return geometry
|
||||
|
||||
def get_num_geometries_ignored(self):
|
||||
""" Returns the number of geometries which had to be ignored for various reasons
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
return self._num_geometries_ignored
|
||||
|
||||
def has_geometry_simplified(self):
|
||||
""" Returns whether the geometry has been simplified or not.
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
return self._geometry_simplified
|
||||
|
||||
def __flatten_geom_to_2D(self, geom):
|
||||
"""
|
||||
Enforces a given OGRGeometry from higher dimensions into 2D
|
||||
@@ -225,11 +240,12 @@ class SimpleGeomForm(BaseForm):
|
||||
geom = gdal.OGRGeometry(g_wkt)
|
||||
return geom
|
||||
|
||||
def _set_properties(self, geojson: dict, title: str):
|
||||
def _set_geojson_properties(self, geojson: dict, title: str = None):
|
||||
""" Toggles the editable property of the geojson for proper handling in map client
|
||||
|
||||
Args:
|
||||
geojson (dict): The GeoJson
|
||||
title (str): An alternative title for the geometry
|
||||
|
||||
Returns:
|
||||
geojson (dict): The altered GeoJson
|
||||
|
||||
@@ -11,6 +11,7 @@ from django.contrib.gis.db.models import MultiPolygonField
|
||||
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
|
||||
from django.db import models, transaction
|
||||
from django.utils import timezone
|
||||
from django.contrib.gis.geos import MultiPolygon
|
||||
|
||||
from konova.models import BaseResource, UuidModel
|
||||
from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP
|
||||
@@ -384,6 +385,36 @@ class Geometry(BaseResource):
|
||||
|
||||
return complexity_factor
|
||||
|
||||
@staticmethod
|
||||
def cast_to_multipolygon(input_geom):
|
||||
""" If input_geom is not a MultiPolygon, cast to MultiPolygon
|
||||
|
||||
Args:
|
||||
input_geom ():
|
||||
|
||||
Returns:
|
||||
output_geom
|
||||
"""
|
||||
output_geom = input_geom
|
||||
if not isinstance(input_geom, MultiPolygon):
|
||||
output_geom = MultiPolygon(input_geom, srid=DEFAULT_SRID_RLP)
|
||||
return output_geom
|
||||
|
||||
@staticmethod
|
||||
def cast_to_rlp_srid(input_geom):
|
||||
""" If input_geom is not of RLP SRID (25832), cast to RLP SRID
|
||||
|
||||
Args:
|
||||
input_geom ():
|
||||
|
||||
Returns:
|
||||
output_geom
|
||||
"""
|
||||
output_geom = input_geom
|
||||
if output_geom.srid != DEFAULT_SRID_RLP:
|
||||
output_geom.transform(DEFAULT_SRID_RLP)
|
||||
return output_geom
|
||||
|
||||
|
||||
class GeometryConflict(UuidModel):
|
||||
"""
|
||||
|
||||
BIN
konova/static/images/error_imgs/croc_technician_400.png
Normal file
BIN
konova/static/images/error_imgs/croc_technician_400.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 MiB |
BIN
konova/static/images/error_imgs/croc_technician_500.png
Normal file
BIN
konova/static/images/error_imgs/croc_technician_500.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 MiB |
@@ -124,6 +124,7 @@ class GeometryTestCase(BaseTestCase):
|
||||
{
|
||||
"type": "Feature",
|
||||
"geometry": json.loads(p.json),
|
||||
"properties": {}
|
||||
}
|
||||
for p in polygons
|
||||
]
|
||||
|
||||
@@ -469,7 +469,7 @@ class BaseTestCase(TestCase):
|
||||
eco_account.save()
|
||||
return eco_account
|
||||
|
||||
def assert_equal_geometries(self, geom1: MultiPolygon, geom2: MultiPolygon, tolerance = 0.001):
|
||||
def assert_equal_geometries(self, geom1: MultiPolygon, geom2: MultiPolygon, tolerance=0.001):
|
||||
""" Assert for geometries to be equal
|
||||
|
||||
Transforms the geometries to matching srids before checking
|
||||
@@ -491,7 +491,10 @@ class BaseTestCase(TestCase):
|
||||
# transformation from one coordinate system into the other, which is valid
|
||||
geom1.transform(geom2.srid)
|
||||
geom2.transform(geom1.srid)
|
||||
self.assertTrue(geom1.equals_exact(geom2, tolerance) or geom2.equals_exact(geom1, tolerance))
|
||||
self.assertTrue(
|
||||
geom1.equals_exact(geom2, tolerance=tolerance),
|
||||
msg=f"Difference is {abs(geom1.area - geom2.area)} with {geom1.area} and {geom2.area} in a tolerance of {tolerance}"
|
||||
)
|
||||
|
||||
|
||||
class BaseViewTestCase(BaseTestCase):
|
||||
|
||||
@@ -42,5 +42,6 @@ urlpatterns = [
|
||||
path('client/proxy/wfs', ClientProxyParcelWFS.as_view(), name="client-proxy-wfs"),
|
||||
]
|
||||
|
||||
handler400 = "konova.views.error.get_400_view"
|
||||
handler404 = "konova.views.error.get_404_view"
|
||||
handler500 = "konova.views.error.get_500_view"
|
||||
|
||||
@@ -83,6 +83,7 @@ EDITED_GENERAL_DATA = _("Edited general data")
|
||||
# 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)
|
||||
GEOMETRIES_IGNORED_TEMPLATE = _("The geometry contained {} parts which have been detected as invalid (e.g. too small to be valid). These parts have been removed. Please check the stored geometry.")
|
||||
|
||||
# INTERVENTION
|
||||
INTERVENTION_HAS_REVOCATIONS_TEMPLATE = _("This intervention has {} revocations")
|
||||
|
||||
@@ -25,6 +25,20 @@ def get_404_view(request: HttpRequest, exception=None):
|
||||
return render(request, "404.html", context, status=404)
|
||||
|
||||
|
||||
def get_400_view(request: HttpRequest, exception=None):
|
||||
""" Returns a 400 handling view
|
||||
|
||||
Args:
|
||||
request ():
|
||||
exception ():
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
context = BaseContext.context
|
||||
return render(request, "400.html", context, status=400)
|
||||
|
||||
|
||||
def get_500_view(request: HttpRequest):
|
||||
""" Returns a 404 handling view
|
||||
|
||||
|
||||
Binary file not shown.
@@ -45,7 +45,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2025-01-08 15:26+0100\n"
|
||||
"POT-Creation-Date: 2025-10-15 09:11+0200\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
@@ -1298,13 +1298,13 @@ msgid "Compensation {} edited"
|
||||
msgstr "Kompensation {} bearbeitet"
|
||||
|
||||
#: compensation/views/compensation/compensation.py:196
|
||||
#: compensation/views/eco_account/eco_account.py:173 ema/views/ema.py:232
|
||||
#: compensation/views/eco_account/eco_account.py:173 ema/views/ema.py:238
|
||||
#: intervention/views/intervention.py:253
|
||||
msgid "Edit {}"
|
||||
msgstr "Bearbeite {}"
|
||||
|
||||
#: compensation/views/compensation/report.py:34
|
||||
#: compensation/views/eco_account/report.py:34 ema/views/report.py:34
|
||||
#: compensation/views/compensation/report.py:35
|
||||
#: compensation/views/eco_account/report.py:36 ema/views/report.py:35
|
||||
#: intervention/views/report.py:35
|
||||
msgid "Report {}"
|
||||
msgstr "Bericht {}"
|
||||
@@ -1325,7 +1325,7 @@ msgstr "Ökokonto {} bearbeitet"
|
||||
msgid "Eco-account removed"
|
||||
msgstr "Ökokonto entfernt"
|
||||
|
||||
#: ema/forms.py:42 ema/tests/unit/test_forms.py:27 ema/views/ema.py:102
|
||||
#: ema/forms.py:42 ema/tests/unit/test_forms.py:27 ema/views/ema.py:108
|
||||
msgid "New EMA"
|
||||
msgstr "Neue EMA hinzufügen"
|
||||
|
||||
@@ -1361,11 +1361,11 @@ msgstr "EMAs - Übersicht"
|
||||
msgid "EMA {} added"
|
||||
msgstr "EMA {} hinzugefügt"
|
||||
|
||||
#: ema/views/ema.py:217
|
||||
#: ema/views/ema.py:223
|
||||
msgid "EMA {} edited"
|
||||
msgstr "EMA {} bearbeitet"
|
||||
|
||||
#: ema/views/ema.py:256
|
||||
#: ema/views/ema.py:262
|
||||
msgid "EMA removed"
|
||||
msgstr "EMA entfernt"
|
||||
|
||||
@@ -1815,10 +1815,6 @@ msgid "Only surfaces allowed. Points or lines must be buffered."
|
||||
msgstr ""
|
||||
"Nur Flächen erlaubt. Punkte oder Linien müssen zu Flächen gepuffert werden."
|
||||
|
||||
#: konova/forms/geometry_form.py:153
|
||||
msgid "Geometry must be greater than 1m². Currently is {}m²"
|
||||
msgstr "Geometrie muss größer als 1m² sein. Aktueller Flächeninhalt: {}m²"
|
||||
|
||||
#: konova/forms/modals/document_form.py:37
|
||||
msgid "When has this file been created? Important for photos."
|
||||
msgstr "Wann wurde diese Datei erstellt oder das Foto aufgenommen?"
|
||||
@@ -1928,11 +1924,11 @@ msgstr "Kontrolle am"
|
||||
msgid "Other"
|
||||
msgstr "Sonstige"
|
||||
|
||||
#: konova/sub_settings/django_settings.py:157
|
||||
#: konova/sub_settings/django_settings.py:156
|
||||
msgid "German"
|
||||
msgstr ""
|
||||
|
||||
#: konova/sub_settings/django_settings.py:158
|
||||
#: konova/sub_settings/django_settings.py:157
|
||||
msgid "English"
|
||||
msgstr ""
|
||||
|
||||
@@ -2266,39 +2262,36 @@ msgstr ""
|
||||
"Die Geometrie enthielt mehr als {} Eckpunkte. Sie musste vereinfacht werden "
|
||||
"um die Obergrenze von {} erlaubten Eckpunkten einzuhalten."
|
||||
|
||||
#: konova/utils/message_templates.py:88
|
||||
#: konova/utils/message_templates.py:86
|
||||
msgid ""
|
||||
"The geometry contained {} parts which have been detected as invalid (e.g. "
|
||||
"too small to be valid). These parts have been removed. Please check the "
|
||||
"stored geometry."
|
||||
msgstr ""
|
||||
"Die Geometrie enthielt {} invalide Bestandteile (z.B. unaussagekräftige Kleinstflächen)."
|
||||
"Diese Bestandteile wurden automatisch entfernt. Bitte überprüfen Sie die angepasste Geometrie."
|
||||
|
||||
#: konova/utils/message_templates.py:89
|
||||
msgid "This intervention has {} revocations"
|
||||
msgstr "Dem Eingriff liegen {} Widersprüche vor"
|
||||
|
||||
#: konova/utils/message_templates.py:91
|
||||
#: konova/utils/message_templates.py:92
|
||||
msgid "Checked on {} by {}"
|
||||
msgstr "Am {} von {} geprüft worden"
|
||||
|
||||
#: konova/utils/message_templates.py:92
|
||||
#: konova/utils/message_templates.py:93
|
||||
msgid "Data has changed since last check on {} by {}"
|
||||
msgstr ""
|
||||
"Daten wurden nach der letzten Prüfung geändert. Letzte Prüfung am {} durch {}"
|
||||
|
||||
#: konova/utils/message_templates.py:93
|
||||
#: konova/utils/message_templates.py:94
|
||||
msgid "Current data not checked yet"
|
||||
msgstr "Momentane Daten noch nicht geprüft"
|
||||
|
||||
#: konova/utils/message_templates.py:96
|
||||
#: konova/utils/message_templates.py:97
|
||||
msgid "New token generated. Administrators need to validate."
|
||||
msgstr "Neuer Token generiert. Administratoren sind informiert."
|
||||
|
||||
#: konova/utils/messenger.py:70
|
||||
msgid "{} checked"
|
||||
msgstr "{} geprüft"
|
||||
|
||||
#: konova/utils/messenger.py:72
|
||||
msgid "<a href=\"{}\">Check it out</a>"
|
||||
msgstr "<a href=\"{}\">Schauen Sie rein</a>"
|
||||
|
||||
#: konova/utils/messenger.py:73
|
||||
msgid "{} has been checked successfully by user {}! {}"
|
||||
msgstr "{} wurde erfolgreich vom Nutzer {} geprüft! {}"
|
||||
|
||||
#: konova/utils/quality.py:32
|
||||
msgid "missing"
|
||||
msgstr "fehlend"
|
||||
@@ -2325,14 +2318,6 @@ msgstr "Home"
|
||||
msgid "Log"
|
||||
msgstr "Log"
|
||||
|
||||
#: konova/views/map_proxy.py:84
|
||||
msgid ""
|
||||
"The external service is currently unavailable.<br>Please try again in a few "
|
||||
"moments..."
|
||||
msgstr ""
|
||||
"Der externe Dienst ist zur Zeit nicht erreichbar.<br>Versuchen Sie es in ein "
|
||||
"paar Sekunden nochmal."
|
||||
|
||||
#: konova/views/record.py:30
|
||||
msgid "{} unrecorded"
|
||||
msgstr "{} entzeichnet"
|
||||
@@ -2389,6 +2374,20 @@ msgstr "Alle"
|
||||
msgid "News"
|
||||
msgstr "Neuigkeiten"
|
||||
|
||||
#: templates/400.html:12
|
||||
msgid "Request was invalid"
|
||||
msgstr "Anfrage fehlerhaft"
|
||||
|
||||
#: templates/400.html:17
|
||||
msgid "There seems to be a problem with the link you opened."
|
||||
msgstr "Es scheint ein Problem mit dem Link zu geben, den Sie geöffnet haben."
|
||||
|
||||
#: templates/400.html:18
|
||||
msgid "Make sure the URL is valid (no whitespaces, properly copied, ...)."
|
||||
msgstr ""
|
||||
"Stellen Sie sicher, dass die URL gültig ist (keine Leerzeichen, fehlerfrei "
|
||||
"kopiert, ...)."
|
||||
|
||||
#: templates/404.html:7
|
||||
msgid "Not found"
|
||||
msgstr "Nicht gefunden"
|
||||
@@ -2401,11 +2400,11 @@ msgstr "Die angeforderten Daten existieren nicht."
|
||||
msgid "Make sure the URL is valid (no whitespaces, ...)."
|
||||
msgstr "Stellen Sie sicher, dass die URL gültig ist (keine Leerzeichen, ...)."
|
||||
|
||||
#: templates/500.html:7
|
||||
#: templates/500.html:12
|
||||
msgid "Server Error"
|
||||
msgstr ""
|
||||
|
||||
#: templates/500.html:10
|
||||
#: templates/500.html:17
|
||||
msgid "Something happened. Admins have been informed. We are working on it!"
|
||||
msgstr ""
|
||||
"Irgendetwas ist passiert. Die Administratoren wurden informiert. Wir "
|
||||
@@ -2884,7 +2883,8 @@ msgid ""
|
||||
"You are about to create a new API token. The existing one will not be usable "
|
||||
"afterwards."
|
||||
msgstr ""
|
||||
"Wenn Sie fortfahren, generieren Sie einen neuen API Token. Ihren existierenden werden Sie dann nicht länger nutzen können."
|
||||
"Wenn Sie fortfahren, generieren Sie einen neuen API Token. Ihren "
|
||||
"existierenden werden Sie dann nicht länger nutzen können."
|
||||
|
||||
#: user/forms/modals/api_token.py:31
|
||||
msgid "A new token needs to be validated by an administrator!"
|
||||
@@ -2912,11 +2912,11 @@ msgstr ""
|
||||
"Mehrfachauswahl möglich - Sie können nur Nutzer wählen, die noch nicht "
|
||||
"Mitglieder dieses Teams sind. Geben Sie den ganzen Nutzernamen an."
|
||||
|
||||
#: user/forms/modals/team.py:56 user/tests/unit/test_forms.py:29
|
||||
#: user/forms/modals/team.py:56 user/tests/unit/test_forms.py:30
|
||||
msgid "Create new team"
|
||||
msgstr "Neues Team anlegen"
|
||||
|
||||
#: user/forms/modals/team.py:57 user/tests/unit/test_forms.py:30
|
||||
#: user/forms/modals/team.py:57 user/tests/unit/test_forms.py:31
|
||||
msgid ""
|
||||
"You will become the administrator for this group by default. You do not need "
|
||||
"to add yourself to the list of members."
|
||||
@@ -2945,11 +2945,11 @@ msgid "There must be at least one admin on this team."
|
||||
msgstr "Es muss mindestens einen Administrator für das Team geben."
|
||||
|
||||
#: user/forms/modals/team.py:160 user/templates/user/team/index.html:60
|
||||
#: user/tests/unit/test_forms.py:86
|
||||
#: user/tests/unit/test_forms.py:87
|
||||
msgid "Edit team"
|
||||
msgstr "Team bearbeiten"
|
||||
|
||||
#: user/forms/modals/team.py:187 user/tests/unit/test_forms.py:163
|
||||
#: user/forms/modals/team.py:187 user/tests/unit/test_forms.py:164
|
||||
msgid ""
|
||||
"ATTENTION!\n"
|
||||
"\n"
|
||||
@@ -2966,7 +2966,7 @@ msgstr ""
|
||||
"Sind Sie sicher, dass Sie dieses Team löschen möchten?"
|
||||
|
||||
#: user/forms/modals/team.py:197 user/templates/user/team/index.html:56
|
||||
#: user/tests/unit/test_forms.py:196
|
||||
#: user/tests/unit/test_forms.py:197
|
||||
msgid "Leave team"
|
||||
msgstr "Team verlassen"
|
||||
|
||||
@@ -2998,7 +2998,7 @@ msgstr "Benachrichtigungen"
|
||||
msgid "Select the situations when you want to receive a notification"
|
||||
msgstr "Wann wollen Sie per E-Mail benachrichtigt werden?"
|
||||
|
||||
#: user/forms/user.py:38 user/tests/unit/test_forms.py:232
|
||||
#: user/forms/user.py:38 user/tests/unit/test_forms.py:233
|
||||
msgid "Edit notifications"
|
||||
msgstr "Benachrichtigungen bearbeiten"
|
||||
|
||||
@@ -3112,7 +3112,7 @@ msgstr "Token noch nicht freigeschaltet"
|
||||
msgid "Valid until"
|
||||
msgstr "Läuft ab am"
|
||||
|
||||
#: user/views/api_token.py:33
|
||||
#: user/views/api_token.py:34
|
||||
msgid "User API token"
|
||||
msgstr "API Nutzer Token"
|
||||
|
||||
|
||||
21
templates/400.html
Normal file
21
templates/400.html
Normal file
@@ -0,0 +1,21 @@
|
||||
{% extends 'public_base.html' %}
|
||||
{% load i18n fontawesome_5 static %}
|
||||
|
||||
{% block body %}
|
||||
<div class="jumbotron">
|
||||
<div class="row">
|
||||
<div class="col-auto">
|
||||
<img src="{% static 'images/error_imgs/croc_technician_400.png' %}" style="max-width: 150px">
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-9 col-lg-9 col-xl-10">
|
||||
<h1 class="display-4">{% fa5_icon 'question-circle' %}400</h1>
|
||||
<h1 class="display-4">{% trans 'Request was invalid' %}</h1>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<p class="lead">
|
||||
{% trans 'There seems to be a problem with the link you opened.' %}
|
||||
{% trans 'Make sure the URL is valid (no whitespaces, properly copied, ...).' %}
|
||||
</p>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -1,10 +1,17 @@
|
||||
{% extends 'public_base.html' %}
|
||||
{% load i18n fontawesome_5 %}
|
||||
{% load i18n fontawesome_5 static %}
|
||||
|
||||
{% block body %}
|
||||
<div class="jumbotron">
|
||||
<h1 class="display-4">{% fa5_icon 'fire-extinguisher' %} {% fa5_icon 'fire-alt' %} 500</h1>
|
||||
<h1 class="display-4">{% trans 'Server Error' %}</h1>
|
||||
<div class="row">
|
||||
<div class="col-auto">
|
||||
<img src="{% static 'images/error_imgs/croc_technician_500.png' %}" style="max-width: 150px">
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-9 col-lg-9 col-xl-10">
|
||||
<h1 class="display-4">{% fa5_icon 'fire-alt' %} 500</h1>
|
||||
<h1 class="display-4">{% trans 'Server Error' %}</h1>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<p class="lead">
|
||||
{% trans 'Something happened. Admins have been informed. We are working on it!' %}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
{
|
||||
"projection": "EPSG:25832",
|
||||
"center_lonlat": [ 7.0, 50.0 ],
|
||||
"zoom": 12,
|
||||
"zoom": 9,
|
||||
"min_zoom": 5,
|
||||
"max_zoom": 24,
|
||||
"scalebar": true,
|
||||
|
||||
@@ -15,6 +15,7 @@ class UserNotificationAdmin(admin.ModelAdmin):
|
||||
class UserAdmin(admin.ModelAdmin):
|
||||
list_display = [
|
||||
"id",
|
||||
"sso_identifier",
|
||||
"username",
|
||||
"first_name",
|
||||
"last_name",
|
||||
|
||||
18
user/migrations/0010_user_sso_identifier.py
Normal file
18
user/migrations/0010_user_sso_identifier.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.1.6 on 2025-09-12 06:10
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('user', '0009_user_oauth_token'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='sso_identifier',
|
||||
field=models.CharField(blank=True, db_comment='Identifies the account based on an unique identifier from the SSO system', max_length=255, null=True),
|
||||
),
|
||||
]
|
||||
@@ -6,6 +6,7 @@ Created on: 15.11.21
|
||||
|
||||
"""
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
|
||||
from django.db import models
|
||||
|
||||
@@ -32,6 +33,12 @@ class User(AbstractUser):
|
||||
db_comment="OAuth token for the user",
|
||||
related_name="+"
|
||||
)
|
||||
sso_identifier = models.CharField(
|
||||
blank=True,
|
||||
null=True,
|
||||
db_comment="Identifies the account based on an unique identifier from the SSO system",
|
||||
max_length=255,
|
||||
)
|
||||
|
||||
def is_notification_setting_set(self, notification_enum: UserNotificationEnum):
|
||||
return self.notifications.filter(
|
||||
@@ -264,4 +271,48 @@ class User(AbstractUser):
|
||||
self.oauth_token.delete()
|
||||
self.oauth_token = token
|
||||
self.save()
|
||||
return self
|
||||
return self
|
||||
|
||||
@staticmethod
|
||||
def resolve_user_using_propagation_data(data: dict):
|
||||
""" Fetches user from db by the given data from propagation process
|
||||
|
||||
Args:
|
||||
data (dict): json containing user information from the sso system
|
||||
|
||||
Returns:
|
||||
user (User): The resolved user
|
||||
"""
|
||||
username = data.get("username", None)
|
||||
sso_identifier = data.get("sso_identifier", None)
|
||||
if not username and not sso_identifier:
|
||||
raise AssertionError("No username or sso identifier provided")
|
||||
|
||||
try:
|
||||
user = User.objects.get(username=username)
|
||||
except ObjectDoesNotExist:
|
||||
try:
|
||||
user = User.objects.get(sso_identifier=sso_identifier)
|
||||
except ObjectDoesNotExist:
|
||||
raise ObjectDoesNotExist("No user with this username or sso identifier was found")
|
||||
|
||||
return user
|
||||
|
||||
def update_user_using_propagation_data(self, data: dict):
|
||||
""" Update user data based on propagation data from sso system
|
||||
|
||||
Args:
|
||||
data (dict): json containing user information from the sso system
|
||||
|
||||
Returns:
|
||||
user (User): The updated user
|
||||
"""
|
||||
skipable_attrs = {
|
||||
"is_staff",
|
||||
"is_superuser",
|
||||
}
|
||||
for _attr, _val in data.items():
|
||||
if _attr in skipable_attrs:
|
||||
continue
|
||||
setattr(self, _attr, _val)
|
||||
return self
|
||||
|
||||
@@ -44,17 +44,8 @@ class PropagateUserView(View):
|
||||
|
||||
try:
|
||||
status = "updated"
|
||||
user = User.objects.get(username=body.get('username'))
|
||||
# Update user data, excluding some changes
|
||||
skipable_attrs = {
|
||||
"username",
|
||||
"is_staff",
|
||||
"is_superuser",
|
||||
}
|
||||
for _attr, _val in body.items():
|
||||
if _attr in skipable_attrs:
|
||||
continue
|
||||
setattr(user, _attr, _val)
|
||||
user = User.resolve_user_using_propagation_data(body)
|
||||
user = user.update_user_using_propagation_data(body)
|
||||
except ObjectDoesNotExist:
|
||||
user = User(**body)
|
||||
status = "created"
|
||||
|
||||
Reference in New Issue
Block a user