-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a name_slug field to Circuit, make it the natural key (#259) This new `name_slug` field is a URL-friendly version of the existing `name` field, which will allow us to have a friendly natural key without having to worry about conflicts with things such as slashes in the URL. The slugification is done by our own function rather than Django's built-in `slugify()`. The built-in is too agressive and would cause conflicts with certain interface names. For example, since it simply drops slashes, the two following interfaces would slugify out to be the same thing, causing a uniqueness conflict: * `Ethernet1/2/3` * `Ethernet12/3` Our slugify function simply replaces `/` with `_`, which is the bare minimum to make these names URL-friendly. The purpose of this is the same as #258, where this fixes a bug that keeps clients from working with circuits by their name if the name contains a slash.
- Loading branch information
Showing
11 changed files
with
137 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('nsot', '0029_auto__add_circuit'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='circuit', | ||
name='name_slug', | ||
field=models.CharField(db_index=True, editable=False, max_length=255, help_text='Slugified version of the name field, used for the natural key', null=True, unique=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
from nsot.util import slugify | ||
|
||
|
||
def add_name_slug(apps, schema_editor): | ||
""" Add a name_slug for every Circuit that doesn't already have one """ | ||
|
||
Circuit = apps.get_model('nsot', 'Circuit') | ||
for c in Circuit.objects.all(): | ||
if not c.name_slug: | ||
c.name_slug = slugify(c.name) | ||
c.save() | ||
|
||
|
||
def remove_name_slug(apps, schema_editor): | ||
Circuit = apps.get_model('nsot', 'Circuit') | ||
for c in Circuit.objects.all(): | ||
c.name_slug = None | ||
c.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('nsot', '0030_add_circuit_name_slug'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(add_name_slug, remove_name_slug) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '1.1' | ||
__version__ = '1.1.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters