update FieldAdder filter to update field if it already exists

This commit is contained in:
Jeremy Carbaugh 2009-08-14 16:48:25 -04:00
parent dc1d3eab14
commit 1d05d434b9

View File

@ -199,10 +199,11 @@ class FieldAdder(Filter):
to create sequentially numbered ids. to create sequentially numbered ids.
""" """
def __init__(self, field_name, field_value): def __init__(self, field_name, field_value, replace=True):
super(FieldAdder, self).__init__() super(FieldAdder, self).__init__()
self._field_name = field_name self._field_name = field_name
self._field_value = field_value self._field_value = field_value
self._replace = replace
def process_record(self, record): def process_record(self, record):
if self._field_name not in record: if self._field_name not in record:
@ -210,6 +211,8 @@ class FieldAdder(Filter):
record[self._field_name] = self._field_value() record[self._field_name] = self._field_value()
else: else:
record[self._field_name] = self._field_value record[self._field_name] = self._field_value
elif self._replace:
record[self._field_name] = self._field_value
return record return record
def __unicode__(self): def __unicode__(self):