Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/objects/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,3 @@
)

NOTIFICATIONS_API_GET_DOMAIN = "objects.utils.get_domain"

#
# Needed for geo widget
#
CSP_SCRIPT_SRC = CSP_SCRIPT_SRC + ["cdn.jsdelivr.net"]
CSP_STYLE_SRC = CSP_STYLE_SRC + ["cdn.jsdelivr.net"]
CSP_IMG_SRC = CSP_IMG_SRC + ["tile.openstreetmap.org"]
20 changes: 18 additions & 2 deletions src/objects/core/admin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import logging

from django import forms
from django.contrib import admin
from django.contrib.gis.admin.options import GeoModelAdminMixin
from django.contrib.gis.db.models import GeometryField
from django.http import JsonResponse
from django.urls import path

import requests
from vng_api_common.utils import get_help_text

from objects.utils.client import get_objecttypes_client

Expand Down Expand Up @@ -46,7 +48,19 @@ def versions_view(self, request, objecttype_id):
return JsonResponse(versions, safe=False)


class ObjectRecordInline(GeoModelAdminMixin, admin.TabularInline):
class ObjectRecordForm(forms.ModelForm):

class Meta:
model: ObjectRecord
help_texts = {
"geometry": get_help_text("core.ObjectRecord", "geometry")
+ "\n\n format: SRID=4326;POINT|LINESTRING|POLYGON (LAT LONG, ...)"
}
fields = "__all__"


class ObjectRecordInline(admin.TabularInline):
form = ObjectRecordForm
model = ObjectRecord
extra = 1
readonly_fields = ("index", "registration_at", "end_at", "get_corrected_by")
Expand All @@ -62,6 +76,8 @@ class ObjectRecordInline(GeoModelAdminMixin, admin.TabularInline):
"correct",
)

formfield_overrides = {GeometryField: {"widget": forms.Textarea}}

def has_delete_permission(self, request, obj=None):
return False

Expand Down
10 changes: 3 additions & 7 deletions src/objects/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_objecttype_version_response():
return client.get_objecttype_version(object_type.uuid, version)
except (requests.RequestException, requests.JSONDecodeError):
raise ValidationError(
{"non_field_errors": "Object type version can not be retrieved."},
"Object type version can not be retrieved.",
code="invalid",
)

Expand All @@ -31,15 +31,11 @@ def get_objecttype_version_response():
jsonschema.validate(data, vesion_data["jsonSchema"])
except KeyError:
raise ValidationError(
{
"non_field_errors": f"{object_type.versions_url} does not appear to be a valid objecttype."
},
f"{object_type.versions_url} does not appear to be a valid objecttype.",
code="invalid_key",
)
except jsonschema.exceptions.ValidationError as exc:
raise ValidationError(
{"non_field_errors": exc.args[0]}, code="invalid_jsonschema"
)
raise ValidationError(exc.args[0], code="invalid_jsonschema")


def can_connect_to_objecttypes() -> bool:
Expand Down