[browther2] Display error message instead of raising DataError when we find the same ids in ListElement

This commit is contained in:
Bezleputh 2014-04-18 12:03:48 +02:00
commit cdf2996d57

View file

@ -603,7 +603,7 @@ class ListElement(AbstractElement):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(ListElement, self).__init__(*args, **kwargs) super(ListElement, self).__init__(*args, **kwargs)
self.logger = getLogger(self.__class__.__name__.lower())
self.objects = {} self.objects = {}
def __call__(self, *args, **kwargs): def __call__(self, *args, **kwargs):
@ -650,7 +650,9 @@ 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:
raise DataError('There are two objects with the same ID! %s' % obj.id) self.logger.error('There are two objects with the same ID! %s' % obj.id)
return
else:
self.objects[obj.id] = obj self.objects[obj.id] = obj
return obj return obj
@ -659,7 +661,9 @@ class ListElement(AbstractElement):
attr = getattr(self, attrname) attr = getattr(self, attrname)
if isinstance(attr, type) and issubclass(attr, AbstractElement) and attr != type(self): if isinstance(attr, type) and issubclass(attr, AbstractElement) and attr != type(self):
for obj in attr(self.page, self, el): for obj in attr(self.page, self, el):
yield self.store(obj) obj = self.store(obj)
if obj:
yield obj
class SkipItem(Exception): class SkipItem(Exception):