Пример #1
0
    def post(self,
             request,
             dataset_id=None,
             resource_id=None,
             layer_id=None,
             *args,
             **kwargs):

        sld = request.POST.get('sldBody')

        try:
            MRAHandler.create_or_update_style(layer_id,
                                              data=sld.encode('utf-8'))
            MRAHandler.update_layer_defaultstyle(layer_id, layer_id)
        except ValidationError as e:
            messages.error(request, ' '.join(e))
        except MraBaseError as e:
            messages.error(request, e.__str__())
        else:
            message = 'Le style a été mis à jour avec succès.'
            messages.success(request, message)

        return HttpResponseRedirect(
            reverse('idgo_admin:layer_style_editor',
                    kwargs={
                        'dataset_id': dataset_id,
                        'resource_id': resource_id,
                        'layer_id': layer_id,
                    }))
Пример #2
0
    def put(self, request, dataset_name, resource_id, layer_name):
        if not request.content_type == 'application/vnd.ogc.sld+xml':
            raise Http404()

        try:
            resource_id = UUID(resource_id)
        except ValueError:
            raise Http404()
        sld = request.body
        MRAHandler.create_or_update_style(layer_name, data=sld)
        MRAHandler.update_layer_defaultstyle(layer_name, layer_name)

        return HttpResponse(status=204)
Пример #3
0
    def save_vector_layer(self, *args, **kwargs):
        """Synchronizer la couche de données vectorielle avec le service OGC via MRA."""
        organisation = self.resource.dataset.organisation
        ws_name = organisation.slug
        ds_name = 'public'

        styles_sld = []

        if self.pk:
            try:
                Layer.objects.get(pk=self.pk)
            except Layer.DoesNotExist:
                pass
            else:
                # On vérifie si l'organisation du jeu de données a changée,
                # auquel cas il est nécessaire de supprimer les objets MRA
                # afin de les recréer dans le bon workspace (c-à-d Mapfile).
                previous_layer = MRAHandler.get_layer(self.name)
                regex = '/workspaces/(?P<ws_name>[a-z0-9_\-]+)/datastores/'

                matched = re.search(regex, previous_layer['resource']['href'])
                if matched:
                    previous_ws_name = matched.group('ws_name')
                    if not ws_name == previous_ws_name:
                        layer_styles = MRAHandler.get_layer_styles(self.name)
                        for style in layer_styles:
                            sld = MRAHandler.get_style(style['name'])
                            styles_sld.append(sld)

                        MRAHandler.del_layer(self.name)
                        MRAHandler.del_featuretype(previous_ws_name, ds_name,
                                                   self.name)

        MRAHandler.get_or_create_workspace(organisation)
        MRAHandler.get_or_create_datastore(ws_name, ds_name)
        MRAHandler.get_or_create_featuretype(
            ws_name,
            ds_name,
            self.name,
            enabled=True,
            title=self.resource.title,
            abstract=self.resource.description)

        for sld in styles_sld:
            MRAHandler.create_or_update_style(self.name, data=sld)
            MRAHandler.update_layer_defaultstyle(self.name, self.name)
            break  # only first is default