Add ignore_duplicate option for crazy modules

This commit is contained in:
Florent 2014-04-24 16:16:50 +02:00
commit fe5bfee255

View file

@ -600,6 +600,7 @@ class AbstractElement(object):
class ListElement(AbstractElement): class ListElement(AbstractElement):
item_xpath = None item_xpath = None
flush_at_end = False flush_at_end = False
ignore_duplicate = False
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(ListElement, self).__init__(*args, **kwargs) super(ListElement, self).__init__(*args, **kwargs)
@ -650,9 +651,11 @@ class ListElement(AbstractElement):
def store(self, obj): def store(self, obj):
if obj.id: if obj.id:
if obj.id in self.objects: if obj.id in self.objects:
self.logger.error('There are two objects with the same ID! %s' % obj.id) if self.ignore_duplicate:
self.logger.warning('There are two objects with the same ID! %s' % obj.id)
return return
else: else:
raise DataError('There are two objects with the same ID! %s' % obj.id)
self.objects[obj.id] = obj self.objects[obj.id] = obj
return obj return obj