Make demo purge independent of Elasticsearch
This commit is contained in:
@@ -94,6 +94,10 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
def _purge_products(self, *, dry_run: bool, keep_only_idea_products: bool) -> int:
|
def _purge_products(self, *, dry_run: bool, keep_only_idea_products: bool) -> int:
|
||||||
from oscar.core.loading import get_model
|
from oscar.core.loading import get_model
|
||||||
|
from oscar_elasticsearch.search.signal_handlers import (
|
||||||
|
deregister_signal_handlers,
|
||||||
|
register_signal_handlers,
|
||||||
|
)
|
||||||
|
|
||||||
Product = get_model("catalogue", "Product")
|
Product = get_model("catalogue", "Product")
|
||||||
products = Product.objects.all()
|
products = Product.objects.all()
|
||||||
@@ -110,11 +114,20 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
removed = 0
|
removed = 0
|
||||||
iterable = candidates if isinstance(candidates, list) else list(candidates)
|
iterable = candidates if isinstance(candidates, list) else list(candidates)
|
||||||
for product in iterable:
|
if dry_run:
|
||||||
removed += 1
|
for product in iterable:
|
||||||
self.stdout.write(
|
removed += 1
|
||||||
f"PRODUCT {'[dry-run] ' if dry_run else ''}delete id={product.id} title={product.title}"
|
self.stdout.write(
|
||||||
)
|
f"PRODUCT [dry-run] delete id={product.id} title={product.title}"
|
||||||
if not dry_run:
|
)
|
||||||
|
return removed
|
||||||
|
|
||||||
|
deregister_signal_handlers()
|
||||||
|
try:
|
||||||
|
for product in iterable:
|
||||||
|
removed += 1
|
||||||
|
self.stdout.write(f"PRODUCT delete id={product.id} title={product.title}")
|
||||||
product.delete()
|
product.delete()
|
||||||
|
finally:
|
||||||
|
register_signal_handlers()
|
||||||
return removed
|
return removed
|
||||||
|
|||||||
Reference in New Issue
Block a user