def add_person(self, person_data): # TODO Move this out of the view layer person = Person.objects.create(name=person_data['name']) person_extra = PersonExtra.objects.create(base=person) check_creation_allowed(self.request.user, person_extra.current_candidacies) change_metadata = get_change_metadata(self.request, person_data['source']) person_extra.record_version(change_metadata) person_extra.save() LoggedAction.objects.create( user=self.request.user, person=person, action_type='person-create', ip_address=get_client_ip(self.request), popit_person_new_version=change_metadata['version_id'], source=change_metadata['information_source'], ) # Add a message to be displayed after redirect: messages.add_message(self.request, messages.SUCCESS, get_call_to_action_flash_message(person, new_person=True), extra_tags='safe do-something-else') return person_extra
def add_person(self, person_data): # TODO Move this out of the view layer person = Person.objects.create(name=person_data['name']) person_extra = PersonExtra.objects.create(base=person) check_creation_allowed( self.request.user, person_extra.current_candidacies ) change_metadata = get_change_metadata( self.request, person_data['source'] ) person_extra.record_version(change_metadata) person_extra.save() LoggedAction.objects.create( user=self.request.user, person=person, action_type='person-create', ip_address=get_client_ip(self.request), popit_person_new_version=change_metadata['version_id'], source=change_metadata['information_source'], ) # Add a message to be displayed after redirect: messages.add_message( self.request, messages.SUCCESS, get_call_to_action_flash_message(person, new_person=True), extra_tags='safe do-something-else' ) return person_extra
def test_get_flash_message_updated_person(self): self.assertEqual( ' Thank-you for updating <a href="/person/42">Wreck-it-Ralph</a>! ' 'Now you can carry on to:' ' <ul> <li> <a href="/person/42/update">Edit Wreck-it-Ralph again</a> </li>' ' <li> Add a candidate for <a href="/numbers/attention-needed">one ' 'of the posts with fewest candidates</a> </li>' ' <li> <a href="/election/2015/person/create/">Add another ' 'candidate in the 2015 General Election</a> </li> </ul> ', normalize_whitespace( get_call_to_action_flash_message(self.fake_person_extra.base, new_person=False)))
def test_get_flash_message_new_person(self): self.assertEqual( ' Thank-you for adding <a href="/person/42">Wreck-it-Ralph</a>! ' "Now you can carry on to:" ' <ul> <li> <a href="/person/42/update">Edit Wreck-it-Ralph again</a> </li>' ' <li> Add a candidate for <a href="/numbers/attention-needed">one ' "of the posts with fewest candidates</a> </li>" ' <li> <a href="/election/parl.2015-05-07/person/create/">Add another ' "candidate in the 2015 General Election</a> </li> </ul> ", normalize_whitespace( get_call_to_action_flash_message(self.fake_person, new_person=True)), )
def test_get_flash_message_updated_person(self): self.assertEqual( u' Thank-you for updating <a href="/person/42">Wreck-it-Ralph</a>! ' u'Now you can carry on to:' u' <ul> <li> <a href="/person/42/update">Edit Wreck-it-Ralph again</a> </li>' u' <li> Add a candidate for <a href="/numbers/attention-needed">one ' u'of the posts with fewest candidates</a> </li>' u' <li> <a href="/election/2015/person/create/">Add another ' u'candidate in the 2015 General Election</a> </li> </ul> ', normalize_whitespace( get_call_to_action_flash_message(self.fake_person, new_person=False) ) )