diff --git a/CHANGELOG.md b/CHANGELOG.md index fa58b54..60ebce6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.10.2 (2024-06-26) + +* Replace n-dashes and m-dashes in boundary set slugs with hyphens, in management commands. + ## 0.10.1 (2024-06-26) * Make boundary set slug editable. diff --git a/boundaries/management/commands/analyzeshapefiles.py b/boundaries/management/commands/analyzeshapefiles.py index b72ea34..5b7f166 100644 --- a/boundaries/management/commands/analyzeshapefiles.py +++ b/boundaries/management/commands/analyzeshapefiles.py @@ -3,12 +3,11 @@ from shutil import rmtree from django.core.management.base import BaseCommand -from django.template.defaultfilters import slugify from django.utils.translation import gettext as _ import boundaries from boundaries.management.commands.loadshapefiles import create_data_sources -from boundaries.models import Definition, Feature, app_settings +from boundaries.models import Definition, Feature, app_settings, slugify log = logging.getLogger(__name__) diff --git a/boundaries/management/commands/loadshapefiles.py b/boundaries/management/commands/loadshapefiles.py index da5c9e0..046d95f 100644 --- a/boundaries/management/commands/loadshapefiles.py +++ b/boundaries/management/commands/loadshapefiles.py @@ -11,11 +11,10 @@ from django.contrib.gis.gdal import DataSource, SpatialReference from django.core.management.base import BaseCommand from django.db import transaction -from django.template.defaultfilters import slugify from django.utils.translation import gettext as _ import boundaries -from boundaries.models import Boundary, BoundarySet, Definition, Feature, app_settings +from boundaries.models import Boundary, BoundarySet, Definition, Feature, app_settings, slugify log = logging.getLogger(__name__) @@ -77,7 +76,7 @@ def add_arguments(self, parser): ) def get_version(self): - return '0.10.1' + return '0.10.2' def handle(self, *args, **options): if settings.DEBUG: diff --git a/boundaries/models.py b/boundaries/models.py index 7521b52..286af52 100644 --- a/boundaries/models.py +++ b/boundaries/models.py @@ -6,7 +6,7 @@ from django.contrib.gis.geos import GEOSGeometry from django.core.serializers.json import DjangoJSONEncoder -from django.template.defaultfilters import slugify +from django.template import defaultfilters from django.urls import reverse from django.utils.translation import gettext from django.utils.translation import gettext_lazy as _ @@ -33,6 +33,10 @@ class MyAppConf(AppConf): slug_re = re.compile(r'[–—]') # n-dash, m-dash +def slugify(value): + return defaultfilters.slugify(slug_re.sub('-', value)) + + class BoundarySet(models.Model): """ @@ -127,7 +131,7 @@ def __str__(self): def save(self, *args, **kwargs): if not self.slug: - self.slug = slugify(slug_re.sub('-', self.name)) + self.slug = slugify(self.name) return super().save(*args, **kwargs) def as_dict(self): @@ -429,7 +433,7 @@ def id(self): def slug(self): # Coerce to string, as the field in the feature from which the slug is # derived may be numeric. - return slugify(slug_re.sub('-', str(self.definition['slug_func'](self)))) + return slugify(str(self.definition['slug_func'](self))) @property def label_point(self): diff --git a/setup.cfg b/setup.cfg index fd194c4..fc449b6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = represent-boundaries -version = 0.10.1 +version = 0.10.2 author = Open North Inc. author_email = represent@opennorth.ca license = MIT