Auto-creation of slugs for non-ASCII users #3054

Closed
opened 2025-12-29 18:25:10 +01:00 by adam · 2 comments
Owner

Originally created by @candlerb on GitHub (Dec 9, 2019).

Environment

  • Python version: 3.5.2
  • NetBox version: 2.6.7

Proposed Functionality

There are many objects which have a "slug" as well as a name: e.g. Site, Region, Rack Group, Rack Role, Device Roles, Platforms, Manufacturers, etc

Currently, when user creates one of these objects, then as they type a slug is generated from the ASCII parts of the text. Symbols and spaces are replaced with dash; high unicode characters do nothing.

In the limiting case of someone using a non-Roman alphabet, the name they enter will have no slug at all. The form cannot be saved, so they are forced to assign a Roman slug of their own.

Possible solutions:

  1. Allow non-ASCII slugs. Django's slugify function has an allow_unicode option.

    >>> slugify('What does 台灣 mean?', allow_unicode=True)
    'what-does-台灣-mean'
    

    Since slugs are intended for use in URLs, this opens a can of worms about how such slugs are actually used in URLs (percent-encoded UTF-8?)

  2. Auto-generate proposed slugs using a library such as unidecode (Python/AJAX) or entirely in the browser using a native Javascript version.

    This may work better for some languages (e.g. Chinese) than others (e.g. Japanese).

Use Case

Speakers of languages which are not based on the Roman alphabet

Database Changes

None

External Dependencies

Possibly a unidecode library.

Originally created by @candlerb on GitHub (Dec 9, 2019). ### Environment * Python version: 3.5.2 * NetBox version: 2.6.7 ### Proposed Functionality There are many objects which have a "slug" as well as a name: e.g. Site, Region, Rack Group, Rack Role, Device Roles, Platforms, Manufacturers, etc Currently, when user creates one of these objects, then as they type a slug is generated from the ASCII parts of the text. Symbols and spaces are replaced with dash; high unicode characters do nothing. In the limiting case of someone using a non-Roman alphabet, the name they enter will have no slug at all. The form cannot be saved, so they are forced to assign a Roman slug of their own. Possible solutions: 1. Allow non-ASCII slugs. Django's slugify function has an `allow_unicode` option. ``` >>> slugify('What does 台灣 mean?', allow_unicode=True) 'what-does-台灣-mean' ``` Since slugs are intended for use in URLs, this opens a can of worms about how such slugs are actually [used in URLs](https://stackoverflow.com/questions/2742852/unicode-characters-in-urls) (percent-encoded UTF-8?) 2. Auto-generate proposed slugs using a library such as `unidecode` (Python/AJAX) or entirely in the browser using a native [Javascript](https://www.npmjs.com/package/unidecode) version. This may work better for some languages (e.g. Chinese) than others (e.g. Japanese). ### Use Case Speakers of languages which are not based on the Roman alphabet ### Database Changes None ### External Dependencies Possibly a `unidecode` library.
adam closed this issue 2025-12-29 18:25:11 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jan 28, 2020):

This was addressed in the fix for #3721.

@jeremystretch commented on GitHub (Jan 28, 2020): This was addressed in the fix for #3721.
Author
Owner

@candlerb commented on GitHub (Apr 21, 2020):

I don't think this has been fixed as of v2.8.0. To replicate:

  • Devices > Device Roles > +
  • Enter a Device Role consisting of entirely non-ASCII characters
  • Click Create

The creation is blocked:

image

If you mix in some ASCII characters, only the ASCII characters appear in the slug:

image

However, the fix for #3721 now allows general Unicode characters in the slug. Hence the code which generates the slug could be changed to allow everything through (except spaces to dashes)

@candlerb commented on GitHub (Apr 21, 2020): I don't think this has been fixed as of v2.8.0. To replicate: * Devices > Device Roles > `+` * Enter a Device Role consisting of entirely non-ASCII characters * Click Create The creation is blocked: ![image](https://user-images.githubusercontent.com/44789/79882569-bc1fad80-83ea-11ea-9ec5-69bfbd320176.png) If you mix in some ASCII characters, only the ASCII characters appear in the slug: ![image](https://user-images.githubusercontent.com/44789/79882896-2b959d00-83eb-11ea-9afd-1decc43f75c4.png) However, the fix for #3721 now allows general Unicode characters in the slug. Hence the code which generates the slug could be changed to allow everything through (except spaces to dashes)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3054