-
Notifications
You must be signed in to change notification settings - Fork 253
feat: make basket_lineattribute value json compatible #4071
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
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/basket/migrations/0016_make_lineattribute_value_json_compatible.py Codecov / codecov/patchecommerce/extensions/basket/migrations/0016_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/basket/migrations/0016_make_lineattribute_value_json_compatible.py Codecov / codecov/patchecommerce/extensions/basket/migrations/0016_make_lineattribute_value_json_compatible.py#L6
|
||
""" | ||
Makes line attribute value json compatible. | ||
""" | ||
LineAttribute = apps.get_model("basket", "LineAttribute") | ||
attributes = LineAttribute.objects.order_by('id') | ||
paginator = Paginator(attributes, 1000) | ||
Check warning on line 12 in ecommerce/extensions/basket/migrations/0016_make_lineattribute_value_json_compatible.py Codecov / codecov/patchecommerce/extensions/basket/migrations/0016_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/basket/migrations/0016_make_lineattribute_value_json_compatible.py Codecov / codecov/patchecommerce/extensions/basket/migrations/0016_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/basket/migrations/0016_make_lineattribute_value_json_compatible.py Codecov / codecov/patchecommerce/extensions/basket/migrations/0016_make_lineattribute_value_json_compatible.py#L18-L20
|
||
|
||
LineAttribute.objects.bulk_update(updates, ['value']) | ||
Check warning on line 22 in ecommerce/extensions/basket/migrations/0016_make_lineattribute_value_json_compatible.py Codecov / codecov/patchecommerce/extensions/basket/migrations/0016_make_lineattribute_value_json_compatible.py#L22
|
||
|
||
|
||
class Migration(migrations.Migration): | ||
Check warning on line 25 in ecommerce/extensions/basket/migrations/0016_make_lineattribute_value_json_compatible.py Codecov / codecov/patchecommerce/extensions/basket/migrations/0016_make_lineattribute_value_json_compatible.py#L25
|
||
|
||
dependencies = [ | ||
Check warning on line 27 in ecommerce/extensions/basket/migrations/0016_make_lineattribute_value_json_compatible.py Codecov / codecov/patchecommerce/extensions/basket/migrations/0016_make_lineattribute_value_json_compatible.py#L27
|
||
('basket', '0015_add_paymentintentid'), | ||
] | ||
|
||
operations = [ | ||
Check warning on line 31 in ecommerce/extensions/basket/migrations/0016_make_lineattribute_value_json_compatible.py Codecov / codecov/patchecommerce/extensions/basket/migrations/0016_make_lineattribute_value_json_compatible.py#L31
|
||
migrations.RunPython(make_lineattribute_value_json_compatible, migrations.RunPython.noop), | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test for this migration