-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
69 additions
and
130 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
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,30 +0,0 @@ | ||
import datetime | ||
import os | ||
import random | ||
import string | ||
|
||
from django.utils.text import slugify | ||
|
||
|
||
def random_string_generator(size=10, chars=string.ascii_lowercase + string.digits): | ||
return "".join(random.choice(chars) for _ in range(size)) | ||
|
||
|
||
def unique_slug_generator(instance, new_slug=None): | ||
""" | ||
This is for a Django project and it assumes your instance | ||
has a model with a slug field and a title character (char) field. | ||
""" | ||
if new_slug is not None: | ||
slug = new_slug | ||
else: | ||
slug = slugify(instance.title) | ||
|
||
Klass = instance.__class__ | ||
qs_exists = Klass.objects.filter(slug=slug).exists() | ||
if qs_exists: | ||
new_slug = "{slug}-{randstr}".format( | ||
slug=slug, randstr=random_string_generator(size=4) | ||
) | ||
return unique_slug_generator(instance, new_slug=new_slug) | ||
return 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,30 +0,0 @@ | ||
import datetime | ||
import os | ||
import random | ||
import string | ||
|
||
from django.utils.text import slugify | ||
|
||
|
||
def random_string_generator(size=10, chars=string.ascii_lowercase + string.digits): | ||
return "".join(random.choice(chars) for _ in range(size)) | ||
|
||
|
||
def unique_slug_generator(instance, new_slug=None): | ||
""" | ||
This is for a Django project and it assumes your instance | ||
has a model with a slug field and a title character (char) field. | ||
""" | ||
if new_slug is not None: | ||
slug = new_slug | ||
else: | ||
slug = slugify(instance.title) | ||
|
||
Klass = instance.__class__ | ||
qs_exists = Klass.objects.filter(slug=slug).exists() | ||
if qs_exists: | ||
new_slug = "{slug}-{randstr}".format( | ||
slug=slug, randstr=random_string_generator(size=4) | ||
) | ||
return unique_slug_generator(instance, new_slug=new_slug) | ||
return 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