udata 10.8.1.dev36652__py2.py3-none-any.whl → 10.8.2.dev36712__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of udata might be problematic. Click here for more details.
- udata/__init__.py +1 -1
- udata/mongo/slug_fields.py +24 -7
- udata/static/chunks/{10.8ca60413647062717b1e.js → 10.471164b2a9fe15614797.js} +3 -3
- udata/static/chunks/{10.8ca60413647062717b1e.js.map → 10.471164b2a9fe15614797.js.map} +1 -1
- udata/static/chunks/{11.b6f741fcc366abfad9c4.js → 11.51d706fb9521c16976bc.js} +3 -3
- udata/static/chunks/{11.b6f741fcc366abfad9c4.js.map → 11.51d706fb9521c16976bc.js.map} +1 -1
- udata/static/chunks/{13.2d06442dd9a05d9777b5.js → 13.f29411b06be1883356a3.js} +2 -2
- udata/static/chunks/{13.2d06442dd9a05d9777b5.js.map → 13.f29411b06be1883356a3.js.map} +1 -1
- udata/static/chunks/{17.e8e4caaad5cb0cc0bacc.js → 17.3bd0340930d4a314ce9c.js} +2 -2
- udata/static/chunks/{17.e8e4caaad5cb0cc0bacc.js.map → 17.3bd0340930d4a314ce9c.js.map} +1 -1
- udata/static/chunks/{19.f03a102365af4315f9db.js → 19.8da42e8359d72afc2618.js} +3 -3
- udata/static/chunks/{19.f03a102365af4315f9db.js.map → 19.8da42e8359d72afc2618.js.map} +1 -1
- udata/static/chunks/{8.778091d55cd8ea39af6b.js → 8.54e44b102164ae5e7a67.js} +2 -2
- udata/static/chunks/{8.778091d55cd8ea39af6b.js.map → 8.54e44b102164ae5e7a67.js.map} +1 -1
- udata/static/chunks/{9.033d7e190ca9e226a5d0.js → 9.07515e5187f475bce828.js} +3 -3
- udata/static/chunks/{9.033d7e190ca9e226a5d0.js.map → 9.07515e5187f475bce828.js.map} +1 -1
- udata/static/common.js +1 -1
- udata/static/common.js.map +1 -1
- {udata-10.8.1.dev36652.dist-info → udata-10.8.2.dev36712.dist-info}/METADATA +6 -1
- {udata-10.8.1.dev36652.dist-info → udata-10.8.2.dev36712.dist-info}/RECORD +24 -24
- {udata-10.8.1.dev36652.dist-info → udata-10.8.2.dev36712.dist-info}/LICENSE +0 -0
- {udata-10.8.1.dev36652.dist-info → udata-10.8.2.dev36712.dist-info}/WHEEL +0 -0
- {udata-10.8.1.dev36652.dist-info → udata-10.8.2.dev36712.dist-info}/entry_points.txt +0 -0
- {udata-10.8.1.dev36652.dist-info → udata-10.8.2.dev36712.dist-info}/top_level.txt +0 -0
udata/__init__.py
CHANGED
udata/mongo/slug_fields.py
CHANGED
|
@@ -172,21 +172,38 @@ def populate_slug(instance, field):
|
|
|
172
172
|
# Ensure uniqueness
|
|
173
173
|
if field.unique:
|
|
174
174
|
base_slug = slug
|
|
175
|
-
index = 1
|
|
176
175
|
qs = instance.__class__.objects
|
|
177
176
|
if previous:
|
|
178
177
|
qs = qs(id__ne=previous.id)
|
|
179
178
|
|
|
180
|
-
def exists(
|
|
181
|
-
return qs(**{field.db_field:
|
|
179
|
+
def exists(slug):
|
|
180
|
+
return qs(**{field.db_field: slug}).clear_cls_query().limit(1).count(True) > 0
|
|
182
181
|
|
|
183
|
-
|
|
184
|
-
|
|
182
|
+
def get_existing_slug_suffixes(slug):
|
|
183
|
+
qs_suffix = qs(slug__regex=f"^{slug}-\d*$").clear_cls_query().only(field.db_field)
|
|
184
|
+
return [getattr(obj, field.db_field) for obj in qs_suffix]
|
|
185
|
+
|
|
186
|
+
def trim_base_slug(base_slug, index):
|
|
185
187
|
slug_overflow = len("{0}-{1}".format(base_slug, index)) - field.max_length
|
|
186
188
|
if slug_overflow >= 1:
|
|
187
189
|
base_slug = base_slug[:-slug_overflow]
|
|
188
|
-
|
|
189
|
-
|
|
190
|
+
return base_slug
|
|
191
|
+
|
|
192
|
+
if exists(base_slug):
|
|
193
|
+
# We'll iterate to get the first free slug suffix
|
|
194
|
+
index = 1
|
|
195
|
+
existing_slugs = None
|
|
196
|
+
while True:
|
|
197
|
+
# Keep space for index suffix, trim slug if needed
|
|
198
|
+
trimmed_slug = trim_base_slug(base_slug, index)
|
|
199
|
+
# Find all existing slugs with suffixes
|
|
200
|
+
if existing_slugs is None or trimmed_slug != base_slug:
|
|
201
|
+
base_slug = trimmed_slug
|
|
202
|
+
existing_slugs = set(sorted(get_existing_slug_suffixes(base_slug)))
|
|
203
|
+
slug = "{0}-{1}".format(base_slug, index)
|
|
204
|
+
if slug not in existing_slugs:
|
|
205
|
+
break
|
|
206
|
+
index += 1
|
|
190
207
|
|
|
191
208
|
if is_uuid(slug):
|
|
192
209
|
slug = "{0}-uuid".format(slug)
|