From 40b3f06f0bc65485a5f8dcc9c707627d08c9ae3f Mon Sep 17 00:00:00 2001 From: elpolilla Date: Wed, 26 Nov 2008 14:48:07 +0000 Subject: [PATCH] Improved add parameter in item.attribute --HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40431 --- scrapy/trunk/scrapy/item/models.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/scrapy/trunk/scrapy/item/models.py b/scrapy/trunk/scrapy/item/models.py index abe3861a3..ad34aafe2 100644 --- a/scrapy/trunk/scrapy/item/models.py +++ b/scrapy/trunk/scrapy/item/models.py @@ -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)