def save_legis_file(self, file_record, attachment_records, action_records): """ Take a legislative file record and do whatever needs to be done to get it into the database. """ file_record = self.__convert_or_delete_date(file_record, 'intro_date') file_record = self.__convert_or_delete_date(file_record, 'final_date') # Don't include the sponsors list, as the model framework doesn't allow # batch inserting of lists for a ManyToManyField, and we will need to # insert each sponsor individually. See below in 'Create the record'. sponsor_names = file_record['sponsors'] del file_record['sponsors'] # Create the record legfile = LegFile(**file_record) for sponsor_name in sponsor_names.split(','): sponsor_name = sponsor_name.strip() sponsor = CouncilMember.objects.get_or_create(name=sponsor_name)[0] legfile.sponsors.add(sponsor) legfile.save() # Create notes attached to the record for attachment_record in attachment_records: attachment_record = self.__replace_key_with_legfile(attachment_record) self.__save_or_ignore(LegFileAttachment, attachment_record) # Create actions attached to the record for action_record in action_records: action_record = self.__replace_key_with_legfile(action_record) self.__save_or_ignore(LegAction, action_record)
def returns_the_intro_date_of_a_piece_of_legislation (self): from phillyleg.models import LegFile legislation = LegFile() legislation.intro_date = date(2011,8,22) feed_data = SearchResultsFeed(None) last_updated = feed_data.get_last_updated(legislation) assert_equal(last_updated, date(2011,8,22))