From e8da52e4868dbf21c54107cf31578814b9321125 Mon Sep 17 00:00:00 2001 From: James Turk Date: Mon, 24 Nov 2008 01:27:46 +0000 Subject: [PATCH] fixes for addfield overwriting existant fields\n saucebrush sopr example fixed --- examples/sopr_lobbyists.py | 11 ++++------- saucebrush/filters.py | 11 ++++++----- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/examples/sopr_lobbyists.py b/examples/sopr_lobbyists.py index 24e2020..4ac9020 100644 --- a/examples/sopr_lobbyists.py +++ b/examples/sopr_lobbyists.py @@ -9,7 +9,7 @@ from saucebrush.emitters import DjangoModelEmitter, DebugEmitter import lobbyists def process_sopr_filing(sopr_xml_file): - from sunlightapi import settings as DJ_SETTINGS + from sunlightapi import live_settings as DJ_SETTINGS DJ_APPLABEL = 'lobbyists' saucebrush.run_recipe(lobbyists.parse_filings(sopr_xml_file), @@ -22,9 +22,7 @@ def process_sopr_filing(sopr_xml_file): # process names & dates FieldAdder('client_contact_name', ''), - FieldAdder('registrant_name', ''), - NameCleaner('client_contact_name', prefix='client_', nomatch_name='client_raw_contact_name'), - NameCleaner('registrant_name', prefix='registrant_', nomatch_name='registrant_raw_name'), + NameCleaner('client_contact_name', prefix='client_contact_', nomatch_name='client_raw_contact_name'), FieldModifier('filing_date', lambda x: x.split('.')[0]), DateCleaner('filing_date', from_format='%Y-%m-%dT%H:%M:%S', to_format='%Y-%m-%d'), @@ -37,8 +35,7 @@ def process_sopr_filing(sopr_xml_file): saucebrush.filters.Splitter({ 'issues':[DjangoModelEmitter(DJ_SETTINGS, DJ_APPLABEL, 'issue')], 'lobbyists':[FieldRemover(['indicator', 'status']), - NameCleaner(['name']), - FieldRenamer({'raw_name': 'name'}), + NameCleaner('name', nomatch_name='raw_name'), Unique(), # remove some duplicate lobbyists on a form DjangoModelEmitter(DJ_SETTINGS, DJ_APPLABEL, 'lobbyist') ], @@ -51,4 +48,4 @@ if __name__ == '__main__': import sys for fname in sys.argv[1:]: print 'processing', fname - process_sopr_filing(fname) \ No newline at end of file + process_sopr_filing(fname) diff --git a/saucebrush/filters.py b/saucebrush/filters.py index 40ab008..1de572d 100644 --- a/saucebrush/filters.py +++ b/saucebrush/filters.py @@ -197,10 +197,11 @@ class FieldAdder(Filter): self._field_value = field_value def process_record(self, record): - if callable(self._field_value): - record[self._field_name] = self._field_value() - else: - record[self._field_name] = self._field_value + if self._field_name not in record: + if callable(self._field_value): + record[self._field_name] = self._field_value() + else: + record[self._field_name] = self._field_value return record def __unicode__(self): @@ -432,4 +433,4 @@ class NameCleaner(Filter): record.pop(key) record[self._nomatch_name] = name - return record \ No newline at end of file + return record