Skip to content

Commit 1845a7a

Browse files
committed
Fix settings add callback crudview, add admin
1 parent 1fb9d49 commit 1845a7a

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/custom/dataloader/geosource_callbacks.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from django.contrib.auth.models import Group
44
from django.contrib.gis.geos import GEOSGeometry
55
from geostore.models import Layer, LayerGroup
6+
from terra_geocrud.models import CrudView, CrudViewProperty
7+
from terra_geocrud.properties.schema import sync_layer_schema
68
from rest_framework.exceptions import MethodNotAllowed
79

810
from custom.receivers import * # noqa
@@ -22,6 +24,27 @@ def layer_callback(geosource):
2224

2325
layer_groups = Group.objects.filter(pk__in=geosource.settings.get('groups', []))
2426

27+
crud_view = CrudView.objects.get_or_create(layer=layer,
28+
defaults={"name": layer.name, "order": 0})[0]
29+
30+
fields = geosource.fields.all()
31+
for field in fields:
32+
data_type = field.data_type
33+
name = field.name
34+
label = field.label
35+
if data_type == 1:
36+
final_type = "string"
37+
elif data_type == 2:
38+
final_type = "string"
39+
elif data_type == 3:
40+
final_type = "float"
41+
elif data_type == 4:
42+
final_type = "boolean"
43+
property, created = CrudViewProperty.objects.get_or_create(view=crud_view, key=name)
44+
property.json_schema = {"title": label, "type": final_type}
45+
property.save()
46+
47+
sync_layer_schema(crud_view)
2548
if set(layer.authorized_groups.all()) != set(layer_groups):
2649
layer.authorized_groups.set(layer_groups)
2750

src/project/settings/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
'django.contrib.sessions',
2929
'django.contrib.staticfiles',
3030
'django.contrib.gis',
31+
'django_object_actions',
3132
'rest_framework',
3233
'rest_framework_gis',
3334
'corsheaders',

src/project/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
1515
"""
1616
from django.conf import settings
17+
from django.contrib import admin
1718
from django.conf.urls.static import static
1819
from django.urls import include, path
1920

2021
from custom.receivers import * # noqa
2122

2223
urlpatterns = [
24+
path('', admin.site.urls),
2325
path('api/', include('terra_layer.urls')),
2426
path('api/mapbox_baselayer/', include('mapbox_baselayer.urls')),
2527
path('api/crud/', include('terra_geocrud.urls')),

0 commit comments

Comments
 (0)