From e6a90e6be588c73afa8308f61b4694a0ec68626b Mon Sep 17 00:00:00 2001 From: Lova ANDRIARIMALALA <43842786+Xpirix@users.noreply.github.com> Date: Thu, 19 Sep 2024 14:27:31 +0300 Subject: [PATCH] Fix layer definition datasource and provider in API --- qgis-app/api/serializers.py | 5 ++++- qgis-app/api/views.py | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/qgis-app/api/serializers.py b/qgis-app/api/serializers.py index 8011b6d7..43ebb4d7 100644 --- a/qgis-app/api/serializers.py +++ b/qgis-app/api/serializers.py @@ -14,7 +14,7 @@ from django.core.exceptions import ValidationError from django.utils.translation import gettext_lazy as _ from styles.file_handler import read_xml_style, validator as style_validator -from layerdefinitions.file_handler import validator as layer_validator +from layerdefinitions.file_handler import get_provider, get_url_datasource, validator as layer_validator import tempfile class ResourceBaseSerializer(serializers.ModelSerializer): @@ -163,6 +163,9 @@ def validate(self, attrs): with open(temp_file.name, 'rb') as qlr_file: layer_validator(qlr_file) + self.url_datasource = get_url_datasource(qlr_file) + self.provider = get_provider(qlr_file) + finally: import os diff --git a/qgis-app/api/views.py b/qgis-app/api/views.py index 774465aa..dc36a4f0 100644 --- a/qgis-app/api/views.py +++ b/qgis-app/api/views.py @@ -396,6 +396,12 @@ def post(self, request, *args, **kwargs): if hasattr(serializer, 'style_type'): serializer.instance.style_type = serializer.style_type serializer.instance.save() + if hasattr(serializer, 'url_datasource'): + serializer.instance.url_datasource = serializer.url_datasource + serializer.instance.save() + if hasattr(serializer, 'provider'): + serializer.instance.provider = serializer.provider + serializer.instance.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)