fixes for addfield overwriting existant fields\n saucebrush sopr example fixed

This commit is contained in:
James Turk 2008-11-24 01:27:46 +00:00
parent c114d482da
commit e8da52e486
2 changed files with 10 additions and 12 deletions

View File

@ -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)
process_sopr_filing(fname)

View File

@ -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
return record