-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
…atible
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -*- coding: utf-8 -*- | ||
from django.core.paginator import Paginator | ||
from django.db import migrations | ||
Check warning on line 3 in ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py Codecov / codecov/patchecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py#L2-L3
|
||
|
||
|
||
def make_lineattribute_value_json_compatible(apps, schema_editor): | ||
Check warning on line 6 in ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py Codecov / codecov/patchecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py#L6
|
||
""" | ||
Makes line attribute value json compatible. | ||
""" | ||
LineAttribute = apps.get_model("order", "LineAttribute") | ||
attributes = LineAttribute.objects.order_by('id') | ||
paginator = Paginator(attributes, 1000) | ||
Check warning on line 12 in ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py Codecov / codecov/patchecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py#L10-L12
|
||
|
||
for page_number in paginator.page_range: | ||
page = paginator.page(page_number) | ||
updates = [] | ||
Check warning on line 16 in ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py Codecov / codecov/patchecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py#L14-L16
|
||
|
||
for obj in page.object_list: | ||
obj.value = '"{}"'.format(obj.value) | ||
updates.append(obj) | ||
Check warning on line 20 in ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py Codecov / codecov/patchecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py#L18-L20
|
||
|
||
LineAttribute.objects.bulk_update(updates, ['value']) | ||
Check warning on line 22 in ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py Codecov / codecov/patchecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py#L22
|
||
|
||
|
||
class Migration(migrations.Migration): | ||
Check warning on line 25 in ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py Codecov / codecov/patchecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py#L25
|
||
|
||
dependencies = [ | ||
Check warning on line 27 in ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py Codecov / codecov/patchecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py#L27
|
||
('order', '0026_auto_20231108_1355'), | ||
] | ||
|
||
operations = [ | ||
Check warning on line 31 in ecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py Codecov / codecov/patchecommerce/extensions/order/migrations/0027_make_lineattribute_value_json_compatible.py#L31
|
||
migrations.RunPython(make_lineattribute_value_json_compatible, migrations.RunPython.noop), | ||
] |