def delete(self, *args, current_user=None, **kwargs): with_user = current_user # On supprime la ressource CKAN if with_user: username = with_user.username apikey = CkanHandler.get_user(username)['apikey'] with CkanUserHandler(apikey=apikey) as ckan_user: ckan_user.delete_resource(self.name) else: CkanHandler.delete_resource(self.name) # On supprime les ressources MRA try: MRAHandler.del_layer(self.name) ws_name = self.resource.dataset.organisation.slug if self.type == 'vector': MRAHandler.del_featuretype(ws_name, 'public', self.name) if self.type == 'raster': MRAHandler.del_coverage(ws_name, self.name, self.name) # MRAHandler.del_coveragestore(ws_name, self.name) except Exception as e: logger.error(e) pass # On supprime la table de données PostGIS try: drop_table(self.name) except Exception as e: logger.error(e) pass # Puis on supprime l'instance super().delete(*args, **kwargs)
def save_raster_layer(self, *args, **kwargs): """Synchronizer la couche de données matricielle avec le service OGC via MRA.""" organisation = self.resource.dataset.organisation ws_name = organisation.slug cs_name = self.name 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-z_\-]+)/coveragestores/' matched = re.search(regex, previous_layer['resource']['href']) if matched: previous_ws_name = matched.group('ws_name') if not ws_name == previous_ws_name: MRAHandler.del_layer(self.name) MRAHandler.del_coverage(previous_ws_name, cs_name, self.name) MRAHandler.get_or_create_workspace(organisation) MRAHandler.get_or_create_coveragestore(ws_name, cs_name, filename=self.filename) MRAHandler.get_or_create_coverage(ws_name, cs_name, self.name, enabled=True, title=self.resource.title, abstract=self.resource.description)