equal
deleted
inserted
replaced
9 |
9 |
10 from p4l.mapping.constants import get_empty_graph, IIEP |
10 from p4l.mapping.constants import get_empty_graph, IIEP |
11 from p4l.mapping.parsers import RecordParser, QueryCache |
11 from p4l.mapping.parsers import RecordParser, QueryCache |
12 from p4l.utils import show_progress |
12 from p4l.utils import show_progress |
13 import xml.etree.cElementTree as ET |
13 import xml.etree.cElementTree as ET |
|
14 from django.conf import settings |
14 |
15 |
15 |
16 |
16 logger = logging.getLogger(__name__) |
17 logger = logging.getLogger(__name__) |
17 |
18 |
18 |
19 |
40 make_option('-p', '--preserve', |
41 make_option('-p', '--preserve', |
41 dest= 'preserve', |
42 dest= 'preserve', |
42 action='store_true', |
43 action='store_true', |
43 default=False, |
44 default=False, |
44 help= 'preserve existing record' |
45 help= 'preserve existing record' |
|
46 ), |
|
47 make_option('-i', '--index', |
|
48 dest= 'index', |
|
49 action='store_true', |
|
50 default=False, |
|
51 help= 'index while importing' |
45 ), |
52 ), |
46 ) |
53 ) |
47 |
54 |
48 def __init__(self, *args, **kwargs): |
55 def __init__(self, *args, **kwargs): |
49 super(Command, self).__init__(*args, **kwargs) |
56 super(Command, self).__init__(*args, **kwargs) |
114 |
121 |
115 def handle(self, *args, **options): |
122 def handle(self, *args, **options): |
116 |
123 |
117 self.batch_size = options.get('batch_size', 50) |
124 self.batch_size = options.get('batch_size', 50) |
118 self.preserve = options.get("preserve", False) |
125 self.preserve = options.get("preserve", False) |
|
126 self.index = options.get("index", False) |
|
127 |
|
128 if not self.index: |
|
129 old_haystack_signal_processor = getattr(settings, "HAYSTACK_SIGNAL_PROCESSOR", None) |
|
130 #this is not recommended by the django manual, but in case of management command it seems to work |
|
131 if old_haystack_signal_processor: |
|
132 settings.HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.BaseSignalProcessor' |
|
133 |
119 transaction.enter_transaction_management() |
134 transaction.enter_transaction_management() |
120 transaction.managed(True) |
135 transaction.managed(True) |
121 |
136 |
122 for records_url in args: |
137 for records_url in args: |
123 print("Processing %s" % records_url) |
138 print("Processing %s" % records_url) |
125 print("Processing %s Done" % records_url) |
140 print("Processing %s Done" % records_url) |
126 if errors: |
141 if errors: |
127 print("%d error(s) when processing %s, check your log file." % (len(errors), records_url)) |
142 print("%d error(s) when processing %s, check your log file." % (len(errors), records_url)) |
128 |
143 |
129 transaction.leave_transaction_management() |
144 transaction.leave_transaction_management() |
|
145 |
|
146 if not self.index and old_haystack_signal_processor: |
|
147 settings.HAYSTACK_SIGNAL_PROCESSOR = old_haystack_signal_processor |
130 |
148 |