File tree 1 file changed +3
-3
lines changed
1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change 33
33
VERSION_SLUG_REGEX = '(?:[a-z0-9][-._a-z0-9]+?)'
34
34
35
35
36
- version_slug_regex = re .compile (VERSION_SLUG_REGEX )
37
-
38
-
39
36
class VersionSlugField (models .CharField ):
40
37
"""
41
38
Implementation inspired by ``django_extensions.db.fields.AutoSlugField``.
@@ -45,6 +42,7 @@ class VersionSlugField(models.CharField):
45
42
allowed_chars = string .lowercase + string .digits + allowed_punctuation
46
43
placeholder = '-'
47
44
fallback_slug = 'unkown'
45
+ test_pattern = re .compile ('^{pattern}$' .format (pattern = VERSION_SLUG_REGEX ))
48
46
49
47
def __init__ (self , * args , ** kwargs ):
50
48
kwargs .setdefault ('db_index' , True )
@@ -154,6 +152,8 @@ def create_slug(self, model_instance):
154
152
slug = slug + end
155
153
kwargs [self .attname ] = slug
156
154
next += 1
155
+ assert self .test_pattern .match (slug ), (
156
+ 'Invalid generated slug: {slug}' .format (slug = slug ))
157
157
return slug
158
158
159
159
def pre_save (self , model_instance , add ):
You can’t perform that action at this time.
0 commit comments