fixes for addfield overwriting existant fields\n saucebrush sopr example fixed
This commit is contained in:
parent
c114d482da
commit
e8da52e486
@ -9,7 +9,7 @@ from saucebrush.emitters import DjangoModelEmitter, DebugEmitter
|
|||||||
import lobbyists
|
import lobbyists
|
||||||
|
|
||||||
def process_sopr_filing(sopr_xml_file):
|
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'
|
DJ_APPLABEL = 'lobbyists'
|
||||||
|
|
||||||
saucebrush.run_recipe(lobbyists.parse_filings(sopr_xml_file),
|
saucebrush.run_recipe(lobbyists.parse_filings(sopr_xml_file),
|
||||||
@ -22,9 +22,7 @@ def process_sopr_filing(sopr_xml_file):
|
|||||||
|
|
||||||
# process names & dates
|
# process names & dates
|
||||||
FieldAdder('client_contact_name', ''),
|
FieldAdder('client_contact_name', ''),
|
||||||
FieldAdder('registrant_name', ''),
|
NameCleaner('client_contact_name', prefix='client_contact_', nomatch_name='client_raw_contact_name'),
|
||||||
NameCleaner('client_contact_name', prefix='client_', nomatch_name='client_raw_contact_name'),
|
|
||||||
NameCleaner('registrant_name', prefix='registrant_', nomatch_name='registrant_raw_name'),
|
|
||||||
FieldModifier('filing_date', lambda x: x.split('.')[0]),
|
FieldModifier('filing_date', lambda x: x.split('.')[0]),
|
||||||
DateCleaner('filing_date', from_format='%Y-%m-%dT%H:%M:%S', to_format='%Y-%m-%d'),
|
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({
|
saucebrush.filters.Splitter({
|
||||||
'issues':[DjangoModelEmitter(DJ_SETTINGS, DJ_APPLABEL, 'issue')],
|
'issues':[DjangoModelEmitter(DJ_SETTINGS, DJ_APPLABEL, 'issue')],
|
||||||
'lobbyists':[FieldRemover(['indicator', 'status']),
|
'lobbyists':[FieldRemover(['indicator', 'status']),
|
||||||
NameCleaner(['name']),
|
NameCleaner('name', nomatch_name='raw_name'),
|
||||||
FieldRenamer({'raw_name': 'name'}),
|
|
||||||
Unique(), # remove some duplicate lobbyists on a form
|
Unique(), # remove some duplicate lobbyists on a form
|
||||||
DjangoModelEmitter(DJ_SETTINGS, DJ_APPLABEL, 'lobbyist')
|
DjangoModelEmitter(DJ_SETTINGS, DJ_APPLABEL, 'lobbyist')
|
||||||
],
|
],
|
||||||
@ -51,4 +48,4 @@ if __name__ == '__main__':
|
|||||||
import sys
|
import sys
|
||||||
for fname in sys.argv[1:]:
|
for fname in sys.argv[1:]:
|
||||||
print 'processing', fname
|
print 'processing', fname
|
||||||
process_sopr_filing(fname)
|
process_sopr_filing(fname)
|
||||||
|
@ -197,10 +197,11 @@ class FieldAdder(Filter):
|
|||||||
self._field_value = field_value
|
self._field_value = field_value
|
||||||
|
|
||||||
def process_record(self, record):
|
def process_record(self, record):
|
||||||
if callable(self._field_value):
|
if self._field_name not in record:
|
||||||
record[self._field_name] = self._field_value()
|
if callable(self._field_value):
|
||||||
else:
|
record[self._field_name] = self._field_value()
|
||||||
record[self._field_name] = self._field_value
|
else:
|
||||||
|
record[self._field_name] = self._field_value
|
||||||
return record
|
return record
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
@ -432,4 +433,4 @@ class NameCleaner(Filter):
|
|||||||
record.pop(key)
|
record.pop(key)
|
||||||
record[self._nomatch_name] = name
|
record[self._nomatch_name] = name
|
||||||
|
|
||||||
return record
|
return record
|
||||||
|
Loading…
Reference in New Issue
Block a user