Skip to content

Commit

Permalink
fix: Replace n-dashes and m-dashes in boundary set slugs with hyphens…
Browse files Browse the repository at this point in the history
…, in management commands
  • Loading branch information
jpmckinney committed Jun 26, 2024
1 parent bae69f7 commit f73350a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 1 addition & 2 deletions boundaries/management/commands/analyzeshapefiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
5 changes: 2 additions & 3 deletions boundaries/management/commands/loadshapefiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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:
Expand Down
10 changes: 7 additions & 3 deletions boundaries/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _
Expand All @@ -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):

"""
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = represent-boundaries
version = 0.10.1
version = 0.10.2
author = Open North Inc.
author_email = [email protected]
license = MIT
Expand Down

0 comments on commit f73350a

Please sign in to comment.