Update statistics migration to rename duplicates
Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
@@ -177,6 +177,8 @@
|
||||
- Move the file patching code from the Dependency class to a
|
||||
generalized utility of the storages app.
|
||||
- Add book link to the documentation.
|
||||
- Update mayan_statistics migration 0002 to rename
|
||||
duplicate slugs.
|
||||
|
||||
3.2.11 (2019-XX-XX)
|
||||
===================
|
||||
|
||||
@@ -1,10 +1,30 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.25 on 2019-11-16 02:36
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def operation_rename_duplicates(apps, schema_editor):
|
||||
StatisticResult = apps.get_model(
|
||||
app_label='mayan_statistics', model_name='StatisticResult'
|
||||
)
|
||||
slugs = []
|
||||
|
||||
for entry in StatisticResult.objects.using(schema_editor.connection.alias).all():
|
||||
if entry.slug in slugs:
|
||||
counter = 1
|
||||
while(True):
|
||||
attempt = '{}_{}'.format(entry.slug, counter)
|
||||
if attempt not in slugs:
|
||||
break
|
||||
else:
|
||||
counter = counter + 1
|
||||
|
||||
entry.slug = attempt
|
||||
entry.save()
|
||||
|
||||
slugs.append(entry.slug)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
@@ -12,6 +32,10 @@ class Migration(migrations.Migration):
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(
|
||||
code=operation_rename_duplicates,
|
||||
reverse_code=migrations.RunPython.noop
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='statisticresult',
|
||||
name='slug',
|
||||
|
||||
Reference in New Issue
Block a user