Improved add parameter in item.attribute

--HG--
extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40431
This commit is contained in:
elpolilla 2008-11-26 14:48:07 +00:00
parent 26b4be78e3
commit 40b3f06f0b
1 changed files with 8 additions and 7 deletions

View File

@ -44,15 +44,16 @@ class ScrapedItem(object):
if val or val is False:
curr_val = getattr(self, attrname, None)
if not curr_val:
setattr(self, attrname, val)
newval = val
else:
if override:
setattr(self, attrname, val)
elif add and all(hasattr(var, '__iter__') for var in (curr_val, val)):
newval = []
newval.extend(curr_val)
newval.extend(val)
setattr(self, attrname, newval)
newval = val
elif add:
if all(isinstance(var, basestring) for var in (curr_val, val)):
newval = '%s %s' % (curr_val, val)
elif all(hasattr(var, '__iter__') for var in (curr_val, val)):
newval = curr_val + val
setattr(self, attrname, newval)
elif value:
setattr(self, attrname, value)