Esempio n. 1
0
        def readLeaf(layer, container):
            if 'nodes' in layer:
                for node in layer['nodes']:
                    readLeaf(node, layer['nodes'])
            else:
                if layers[layer['id']].name in qgis_projectsettings_wms.layers:

                    # remove from tree layer without geometry
                    #if layers[layer['id']].geometrytype == QGIS_LAYER_TYPE_NO_GEOM:
                    #to_remove_from_layerstree.append((container, layer))

                    layer_serialized = LayerSerializer(
                        layers[layer['id']],
                        qgis_projectsettings_wms=qgis_projectsettings_wms)
                    layer_serialized_data = layer_serialized.data

                    # alter layer serialized data from plugin
                    # send layerseralized original and came back only key->value changed

                    for singnal_receiver, data in after_serialized_project_layer.send(
                            layer_serialized, layer=layers[layer['id']]):
                        update_serializer_data(layer_serialized_data, data)
                    layer_serialized_data[
                        'multilayer'] = meta_layer.getCurrentByLayer(
                            layer_serialized_data)

                    # check for vectorjoins and add to project relations
                    if layer_serialized_data['vectorjoins']:
                        ret['relations'] += self.get_map_layers_relations_from_vectorjoins(
                            layer['id'], layer_serialized_data['vectorjoins'],
                            layers)
                    del (layer_serialized_data['vectorjoins'])

                    ret['layers'].append(layer_serialized_data)

                    # get widgects for layer
                    widgets = layers[layer['id']].widget_set.all()
                    for widget in widgets:
                        widget_serializzer_data = WidgetSerializer(
                            widget, layer=layers[layer['id']]).data
                        if widget_serializzer_data['type'] == 'search':
                            widget_serializzer_data['options'][
                                'layerid'] = layer['id']
                            widget_serializzer_data['options'][
                                'querylayerid'] = layer['id']
                            ret['search'].append(widget_serializzer_data)
                        else:
                            load_qdjango_widget_layer.send(self,
                                                           layer=layer,
                                                           ret=ret,
                                                           widget=widget)

                    # add exclude to legend
                    if layers[layer['id']].exclude_from_legend:
                        ret['no_legend'].append(
                            layers[layer['id']].qgs_layer_id)
                else:

                    # keep layer for remove after
                    to_remove_from_layerstree.append((container, layer))
Esempio n. 2
0
    def get(self, request, format=None, group_slug=None, project_type=None, project_id=None):

        # get serializer
        projectAppModule = __import__('{}.api.serializers'.format(project_type))
        projectSerializer = projectAppModule.api.serializers.ProjectSerializer

        project = projectAppModule.models.Project.objects.get(pk=project_id)

        ps = projectSerializer(project)

        # add wms_url to project metadata il user i anonynous

        if request.user.is_anonymous and 'metadata' in ps.data and not ps.data['metadata']['onlineresource']:
            ps.data['metadata']['wms_url'] = '{}://{}/ows/{}/{}/{}/'.format(
                request._request.META['wsgi.url_scheme'],
                request._request.META['HTTP_HOST'],
                project.group.slug,
                project_type,
                project_id
            )
        elif 'onlineresource' in ps.data['metadata']:
            ps.data['metadata']['wms_url'] = ps.data['metadata']['onlineresource']

        if 'onlineresource' in ps.data['metadata']:
            del(ps.data['metadata']['onlineresource'])

        # signal after serialization project
        ps_data = ps.data
        for singnal_receiver, data in post_serialize_project.send(ps, app_name=project_type, request=self.request):
            if data:
                update_serializer_data(ps_data, data)

        return Response(ps.data)
Esempio n. 3
0
    def get(self, request, format=None, group_slug=None, project_type=None, project_id=None):

        # get serializer
        projectAppModule = __import__('{}.api.projects.serializers'.format(project_type))
        projectSerializer = projectAppModule.api.projects.serializers.ProjectSerializer

        project = projectAppModule.models.Project.objects.get(pk=project_id)

        ps = projectSerializer(project, request=request)

        # add wms_url to project metadata if user anonimous has grant view on project
        if get_anonymous_user().has_perm('{}.view_project'.format(project_type), project) and \
                'metadata' in ps.data and \
                (
                        ps.data['metadata'].get('onlineresource', False) or
                        ps.data['metadata'].get('onlineresource', '').startswith(settings.QDJANGO_SERVER_URL)
                ):
            ps.data['metadata']['wms_url'] = '{}://{}/ows/{}/{}/{}/'.format(
                request._request.META['wsgi.url_scheme'],
                request._request.META['HTTP_HOST'],
                project.group.slug,
                project_type,
                project_id
            )
        elif 'onlineresource' in ps.data['metadata'] and \
                not ps.data['metadata']['onlineresource'].startswith(settings.QDJANGO_SERVER_URL):
            ps.data['metadata']['wms_url'] = ps.data['metadata']['onlineresource']

        if 'onlineresource' in ps.data['metadata']:
            del(ps.data['metadata']['onlineresource'])

        # signal after serialization project
        ps_data = ps.data
        for signal_receiver, data in post_serialize_project.send(ps, app_name=project_type, request=self.request):
            if data:
                update_serializer_data(ps_data, data)

        return Response(ps_data)
Esempio n. 4
0
        def readLeaf(layer, container):

            if 'nodes' in layer:
                for node in layer['nodes']:
                    readLeaf(node, layer['nodes'])
            else:

                # Check for empty vector layer
                if settings.G3W_CLIENT_NOT_SHOW_EMPTY_VECTORLAYER and self.layer_is_empty(
                        layers[layer['id']]):
                    return

                # Check if layer is visible for user
                if self.request and not layer['id'] in view_layer_ids:
                    return

                try:
                    layer_serialized = LayerSerializer(layers[layer['id']],
                                                       qgs_project=qgs_project)
                except KeyError:
                    logger.error('Layer %s is missing from QGIS project!' %
                                 layer['id'])
                    return

                layer_serialized_data = layer_serialized.data

                # alter layer serialized data from plugin
                # send layerseralized original and came back only key->value changed
                for signal_receiver, data in after_serialized_project_layer.send(
                        layer_serialized,
                        layer=layers[layer['id']],
                        request=self.request):
                    update_serializer_data(layer_serialized_data, data)
                layer_serialized_data[
                    'multilayer'] = meta_layer.getCurrentByLayer(
                        layer_serialized_data)

                # check for vectorjoins and add to project relations
                if layer_serialized_data['vectorjoins']:
                    ret['relations'] += self.get_map_layers_relations_from_vectorjoins(
                        layer['id'], layer_serialized_data['vectorjoins'],
                        layers)
                del (layer_serialized_data['vectorjoins'])

                if qgs_project.layerTreeRoot().hasCustomLayerOrder():
                    ret['layers'].update(
                        {layer_serialized_data['id']: layer_serialized_data})
                else:
                    ret['layers'].append(layer_serialized_data)

                # get widgects for layer
                widgets = layers[layer['id']].widget_set.all()
                for widget in widgets:
                    widget_serializzer_data = WidgetSerializer(
                        widget, layer=layers[layer['id']]).data
                    if widget_serializzer_data['type'] == 'search':
                        widget_serializzer_data['options']['layerid'] = layer[
                            'id']
                        widget_serializzer_data['options'][
                            'querylayerid'] = layer['id']
                        ret['search'].append(widget_serializzer_data)
                    else:
                        load_qdjango_widget_layer.send(self,
                                                       layer=layer,
                                                       ret=ret,
                                                       widget=widget)