Ejemplo n.º 1
0
    def dataset_config(self, user=None):
        # Try to use existing user-specific cache of layer config
        if self.id:
            cfg = cache.get("dataset_config" + str(self.id) + "_" +
                            str(0 if user is None else user.id))
            if cfg is not None:
                return cfg

        cfg = GXPLayerBase.dataset_config(self, user=user)
        # if this is a local layer, get the attribute configuration that
        # determines display order & attribute labels
        if Dataset.objects.filter(alternate=self.name).exists():
            try:
                if self.local:
                    layer = Dataset.objects.get(store=self.store,
                                                alternate=self.name)
                else:
                    layer = Dataset.objects.get(
                        alternate=self.name,
                        remote_service__base_url=self.ows_url)
                attribute_cfg = layer.attribute_config()
                if "ftInfoTemplate" in attribute_cfg:
                    cfg["ftInfoTemplate"] = attribute_cfg["ftInfoTemplate"]
                if "getFeatureInfo" in attribute_cfg:
                    cfg["getFeatureInfo"] = attribute_cfg["getFeatureInfo"]
                if not user.has_perm('base.view_resourcebase',
                                     obj=layer.resourcebase_ptr):
                    cfg['disabled'] = True
                    cfg['visibility'] = False
            except Exception:
                # shows maplayer with pink tiles,
                # and signals that there is problem
                # TODO: clear orphaned MapLayers
                layer = None

        if self.id:
            # Create temporary cache of maplayer config, should not last too long in case
            # local layer permissions or configuration values change (default
            # is 5 minutes)
            cache.set(
                "dataset_config" + str(self.id) + "_" +
                str(0 if user is None else user.id), cfg)
        return cfg