Skip to content

Commit

Permalink
Fix layer definition datasource and provider in API
Browse files Browse the repository at this point in the history
  • Loading branch information
Xpirix committed Sep 19, 2024
1 parent 0ba423a commit e6a90e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion qgis-app/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions qgis-app/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit e6a90e6

Please sign in to comment.