diff -r c05567404888 -r 93b45b4f423c src/p4l/management/commands/import_record.py --- a/src/p4l/management/commands/import_record.py Fri Sep 20 22:21:48 2013 +0200 +++ b/src/p4l/management/commands/import_record.py Sat Sep 21 23:49:04 2013 +0200 @@ -11,6 +11,7 @@ from p4l.mapping.parsers import RecordParser, QueryCache from p4l.utils import show_progress import xml.etree.cElementTree as ET +from django.conf import settings logger = logging.getLogger(__name__) @@ -43,6 +44,12 @@ default=False, help= 'preserve existing record' ), + make_option('-i', '--index', + dest= 'index', + action='store_true', + default=False, + help= 'index while importing' + ), ) def __init__(self, *args, **kwargs): @@ -116,6 +123,14 @@ self.batch_size = options.get('batch_size', 50) self.preserve = options.get("preserve", False) + self.index = options.get("index", False) + + if not self.index: + old_haystack_signal_processor = getattr(settings, "HAYSTACK_SIGNAL_PROCESSOR", None) + #this is not recommended by the django manual, but in case of management command it seems to work + if old_haystack_signal_processor: + settings.HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.BaseSignalProcessor' + transaction.enter_transaction_management() transaction.managed(True) @@ -127,4 +142,7 @@ print("%d error(s) when processing %s, check your log file." % (len(errors), records_url)) transaction.leave_transaction_management() + + if not self.index and old_haystack_signal_processor: + settings.HAYSTACK_SIGNAL_PROCESSOR = old_haystack_signal_processor