summaryrefslogtreecommitdiff
path: root/ishtar_common/views_api.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2025-05-09 10:42:44 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2025-06-13 18:16:05 +0200
commitd829d11aec86a015d3898738ae9d73b5067bb865 (patch)
tree699c21e561d4335880985f39ccb68ecb678d2560 /ishtar_common/views_api.py
parent5b0c5f805eb444269668e318082ec7809719ff8f (diff)
downloadIshtar-d829d11aec86a015d3898738ae9d73b5067bb865.tar.bz2
Ishtar-d829d11aec86a015d3898738ae9d73b5067bb865.zip
✨ GIS API: get data sources list
Diffstat (limited to 'ishtar_common/views_api.py')
-rw-r--r--ishtar_common/views_api.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/ishtar_common/views_api.py b/ishtar_common/views_api.py
new file mode 100644
index 000000000..c054246e4
--- /dev/null
+++ b/ishtar_common/views_api.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+# Copyright (C) 2025 Étienne Loks <etienne.loks at iggdrasil dot net>
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# See the file COPYING for details.
+
+from rest_framework import serializers
+from rest_framework.response import Response
+
+from ishtar_common.rest import GISAPIView
+from ishtar_common.models_imports import ImporterType
+
+
+class ImporterTypeSerializer(serializers.ModelSerializer):
+ model = serializers.SerializerMethodField()
+
+ class Meta:
+ model = ImporterType
+ fields = ['slug', 'name', 'description', 'is_import', 'is_template', 'model']
+
+ def get_model(self, obj):
+ if not obj.associated_models:
+ return ""
+ return str(obj.associated_models)
+
+
+class GISSourceAPI(GISAPIView):
+ model = ImporterType
+
+ def get_queryset(self):
+ user = self.request.user
+ if not user.ishtaruser:
+ return self.model.filter(pk__isnull=True)
+ return self.model.q_qgis_importers(user.ishtaruser)
+
+ def get(self, request, format=None):
+ serializer = ImporterTypeSerializer(self.get_queryset(), many=True)
+ return Response(serializer.data)