示例#1
0
    def full_registration(self, user):
        # if given choice to register online, choose pdf form
        if self.browser.get_form(id='state_ovr'):
            finish_form = self.browser.get_form(id='finish')
            self.browser.submit_form(finish_form)

        full_form = self.browser.get_form(id='full_registration')
        if full_form:
            # BUG, user.get(field, '') results in silent 400 errors, wtf?
            # full_form['title'].value = user.get('title', '')
            # print 'set title', full_form['title'].value
            # full_form['suffix'].value = user.get('suffix', '')
            # print 'set suffix', full_form['suffix'].value

            full_form['state_id_number'].value = user['state_id_number']

            party_translated = get_party_from_list(user.get('political_party'), options_dict(full_form['political_party']).keys())
            
            if not party_translated:
                party_translated = 'No party'

            full_form['political_party'].value = options_dict(full_form['political_party'])[party_translated]
            # why does the form require bool as string?
            full_form['us_citizen'].value = str(bool_to_int(user['us_citizen']))

            self.browser.submit_form(full_form)

        else:
            errors_string = ','.join(self.parse_errors())
            raise ValidationError(message='unable to get_form full_registration.', payload=errors_string)
示例#2
0
    def edit_voter_information(self, user, form):
        party_options = options_dict(form['editVoterForm:partyAffiliationId'])
        # do fuzzy match to political party options
        party = get_party_from_list(user['political_party'],
                                    party_options.keys())

        # it is required. if we haven't found a match, defer to 'Unaffiliated'
        if not party:
            party = 'Unaffiliated'

        form['editVoterForm:partyAffiliationId'].value = party_options[party]

        if user['military_or_overseas']:
            form['editVoterForm:areUOCAVAId'].value = 'Y'
            form['editVoterForm:uocavaTypeId'].value = 'a' if user[
                'military_or_overseas'] == 'military' else 'c'
        else:
            form['editVoterForm:areUOCAVAId'].value = 'N'

        form['editVoterForm:uocavaBallotMethodId'].value = 'Mail' if user[
            'vote_by_mail'] else 'Email'  # or 'Fax'

        # email, phone and gender are prefilled
        form['editVoterForm:emailId'].value = user['email']
        form[
            'editVoterForm:receiveEmailCommunicationId'].checked = 'checked' if user[
                'email'] else ''
        if 'phone' in user:
            # strip country prefix
            form['editVoterForm:phoneId'].value = user['phone'].replace(
                '+1', '')

        gender_str = parse_gender(user['gender'])
        if gender_str is 'F':
            form['editVoterForm:genderSelectId'].value = '0'
        elif gender_str is 'M':
            form['editVoterForm:genderSelectId'].value = '1'
        else:
            raise ValidationError(message='parse_gender error',
                                  payload=user['gender'])

        form['editVoterForm:resAddress'].value = user['address']
        form['editVoterForm:resCity'].value = user['city']

        form['editVoterForm:resCounty'].value = options_dict(
            form['editVoterForm:resCounty'])[user['county']]

        form['editVoterForm:resZip'].value = user['zip']

        self.browser.submit_form(form, submit=form['editVoterForm:j_idt114'])
示例#3
0
 def party_affiliation(self, user, form):
     party_list = {
         "Democratic": "D",
         "Republican": "R",
         "Other": "O",
         "Constitution": "C",
         "Reform": "F",
         "Independent": "I",
         "Libertarian": "L",
         "Socialist Workers": "S",
         "Green": "G",
     }
     party_name = get_party_from_list(user['political_party'],
                                      party_list.keys())
     form['party'] = party_list[party_name]
示例#4
0
    def step2(self, form, user):
        #  Eligibility
        form['IsUSCitizen'].value = bool_to_string(user['us_citizen'])
        if user['will_be_18']:
            form['RegistrationChoice'].value = '1'
            # I will be 18 or older by the next election.
        else:
            # other options:
            # form['RegistrationChoice'].value = '2'
            # I am a 16 or 17 years old and I would like to pre-register to vote.
            # don't handle this yet, needs update in votebot-api
            raise ValidationError(message='not eligible',
                                  payload={
                                      'will_be_18': user['will_be_18'],
                                      'date_of_birth': user['date_of_birth']
                                  })

        prefix_options = options_dict(form['Prefix'])
        if 'name_prefix' in user:
            form['Prefix'].value = prefix_options.get(user['name_prefix'])
        form['FirstName'].value = user['first_name']
        form['MiddleName'].value = user.get('middle_name')
        form['LastName'].value = user['last_name']
        suffix_options = options_dict(form['Suffix'])
        if 'name_suffix' in user:
            form['Suffix'].value = suffix_options.get(user['name_suffix'])

        form['EmailAddress'].value = user.get('email', '')
        form['ConfirmEmail'].value = user.get('email', '')
        if user.get('phone'):
            phone = user.get('phone').replace('+1', '').replace('-', '')
            form['PhoneNumber'].value = phone

        # change of name
        if user.get('has_previous_name'):
            form['IsPreviouslyRegistered'].checked = 'checked'
            (prev_first, prev_middle,
             prev_last) = split_name(user.get('previous_name', ''))
            form['Previous.FirstName'] = prev_first
            form['Previous.MiddleName'] = prev_middle
            form['Previous.LastName'] = prev_last

        # change of address
        if user.get('has_previous_adress'):
            form['IsPreviouslyRegistered'].checked = 'checked'
            form['Previous.StreetAddress'] = user.get('previous_address', '')
            form['Previous.ApartmentLotNumber'] = user.get(
                'previous_address_unit', '')
            form['Previous.City'] = user.get('previous_city', '')
            form['Previous.Zip'] = user.get('previous_zip', '')
            form['Previous.StateId'] = user.get('previous_state', '')

        # separate mailing address
        if user.get('has_separate_mailing_addresss'):
            form['IsDifferentMailingAddress'].checked = 'checked'

            mailing_components = get_address_from_freeform(
                user.get('separate_mailing_address'))
            form['Mailing.StreetAddress'] = get_street_address_from_components(
                mailing_components)
            form[
                'Mailing.ApartmentLotNumber'] = get_address_unit_from_components(
                    mailing_components)
            form['Mailing.City'] = mailing_components('city_name')
            form['Mailing.State'] = mailing_components('state_abbreviation')
            form['Mailing.Zip'] = mailing_components('zipcode')

        (year, month, day) = split_date(user['date_of_birth'], padding=False)
        form['MonthOfBirth'].value = month
        form['DayOfBirth'].value = day
        form['YearOfBirth'].value = year

        #  ID and last 4 of SSN (CA requires both!)
        if 'state_id_number' in user:
            form['CaliforniaID'].value = user.get('state_id_number')
        else:
            form['HasNoCaliforniaID'].value = bool_to_string(True)
            # we actually require this, so shouldn't get here, but just in case
        if user.get('ssn_last4') == "NONE":
            form['HasNoSSN'].value = bool_to_string(True)
        else:
            form['SSN4'].value = user.get('ssn_last4')

        #  Home and Mailing Address
        form['Home.StreetAddress'].value = user['address']
        form['Home.ApartmentLotNumber'].value = user.get('address_unit')
        form['Home.City'].value = user['city']
        form['Home.Zip'].value = user['zip']
        county_options = options_dict(form['Home.CountyId'])
        try:
            form['Home.CountyId'].value = county_options.get(
                user['county'].strip().upper())
        except KeyError:
            raise ValidationError(message='no county match',
                                  payload=user['county'])

        # Ethnicity (optional)
        if 'ethnicity' in user:
            ethnicity_options = options_dict(form['EthnicityId'])
            form['EthnicityId'].value = ethnicity_options.get(
                user['ethnicity'].upper(), ethnicity_options['OTHER'])

        #  Political Party Preference
        user["political_party"] = user["political_party"].strip().upper()

        # they have two inputs with the same name but separated by other elements
        # so robobrowser's _group_flat_tags creates two entries, which their server won't validate
        form.fields.pop('PoliticalPreferenceType')
        # recreate with just one
        PoliticalPreferenceType = Input(
            "<input type='radio' name='PoliticalPreferenceType'/>")
        PoliticalPreferenceType.options = ['1', '2']
        form.add_field(PoliticalPreferenceType)

        if user['political_party'].lower(
        ) == 'independent' or user['political_party'].lower() == "none":
            PoliticalPreferenceType.value = '2'
            PoliticalPreferenceType.checked = 'checked'
            # also delete the politcal party select
            form.fields.pop('PoliticalPartyId')
        else:
            # mess with the DOM to un-disable Political Party
            del self.browser.select(
                'select[name="PoliticalPartyId"]')[0]['disabled']

            PoliticalPreferenceType.value = '1'
            PoliticalPreferenceType.checked = 'checked'
            party_options = options_dict(form['PoliticalPartyId'])
            # do fuzzy match to political party options
            party_choice = get_party_from_list(user['political_party'],
                                               party_options.keys())

            if party_choice in party_options.keys():
                form['PoliticalPartyId'].value = party_options[party_choice]
            else:
                form['PoliticalPartyId'].value = party_options.get('Other')
                form['OtherPoliticalParty'].value = user['political_party']

        self.submit_form_field(form, 'GoToNext')
示例#5
0
    def complete_form(self, user, form):

        address_components = get_address_components(user['address'],
                                                    user['city'],
                                                    user['state'], user['zip'])

        form['ctl00$MainContent$txtStNum'].value = address_components[
            'primary_number']
        street_name = get_street_name_from_components(address_components)
        form['ctl00$MainContent$txStNameSuffix'].value = street_name[:25]

        if user.get('address_unit'
                    ) and not user.get('address_unit').lower() == "none":
            form['ctl00$MainContent$txtUnitApt'].value = user.get(
                'address_unit')

        if 'street_suffix' in address_components:
            street_suffix_options = options_dict(
                form['ctl00$MainContent$ddlStreetSuffix'])
            try:
                form[
                    'ctl00$MainContent$ddlStreetSuffix'].value = street_suffix_options[
                        address_components['street_suffix'].upper()]
            except KeyError:
                form[
                    'ctl00$MainContent$ddlStreetSuffix'].value = street_suffix_options[
                        'No suffix']

        city_normalized = MA_ARCHAIC_COMMUNITIES.get(user['city'],
                                                     user['city'])
        try:
            form['ctl00$MainContent$ddlCityTown'].value = options_dict(
                form['ctl00$MainContent$ddlCityTown'])[city_normalized]
        except KeyError:
            raise ValidationError(
                message='unable to find city in MA CityTown list',
                payload=user['city'])

        form['ctl00$MainContent$txtZip'].value = user['zip']

        user_party = user['political_party'].strip()
        parties = options_dict(form['ctl00$MainContent$ddlPartyList'])
        designations = options_dict(
            form['ctl00$MainContent$ddlPoliticalDesig'])

        party = get_party_from_list(user_party, parties.keys())
        designation = get_party_from_list(user_party, designations.keys())

        user_party = user_party.lower()

        if user_party and user_party != 'independent' and user_party != 'none':

            if party:
                form['ctl00$MainContent$PartyEnrolled'].value = 'rdoBtnParty'
                # crucial - un-disable the party list
                del self.browser.select(
                    'select[name="ctl00$MainContent$ddlPartyList"]'
                )[0]['disabled']
                form['ctl00$MainContent$ddlPartyList'].value = parties[party]

            elif designation:
                form[
                    'ctl00$MainContent$PartyEnrolled'].value = 'rdoBtnPolDesig'
                # crucial - un-disable the designation list
                del self.browser.select(
                    'select[name="ctl00$MainContent$ddlPoliticalDesig"]'
                )[0]['disabled']
                form[
                    'ctl00$MainContent$ddlPoliticalDesig'].value = designations[
                        designation]

            else:
                # unable to match designation, unenrolled
                self.add_error(
                    "We were unable to match that political designation",
                    field='political_party')
                form['ctl00$MainContent$PartyEnrolled'].value = 'rdoBtnNoParty'

        else:
            # No Party (Unenrolled, commonly referred to as ''Independent'')
            form['ctl00$MainContent$PartyEnrolled'].value = 'rdoBtnNoParty'

        # phone number, optional
        if user.get('phone'):
            phone = user.get('phone').replace('+1', '')
            form['ctl00$MainContent$txtAreaCode'].value = phone[0:3]
            form['ctl00$MainContent$txtPhone3'].value = phone[3:6]
            form['ctl00$MainContent$txtPhone4'].value = phone[6:10]

        # separate mailing address
        if user.get('has_separate_mailing_address'):
            form['ctl00$MainContent$ChkDiffMailAddr'].checked = 'checked'
            form['ctl00$MainContent$ChkDiffMailAddr'].value = 'on'

            # remove the disabled attr on the relevant fields
            del self.browser.select(
                'input[name="ctl00$MainContent$txtDiffStNamePO"]'
            )[0]['disabled']
            del self.browser.select(
                'input[name="ctl00$MainContent$txtDiffUnitApt"]'
            )[0]['disabled']
            del self.browser.select(
                'input[name="ctl00$MainContent$txtDiffCityTownCounty"]'
            )[0]['disabled']
            del self.browser.select(
                'input[name="ctl00$MainContent$txtDiffZip"]')[0]['disabled']
            del self.browser.select(
                'select[name="ctl00$MainContent$ddlDiffStateTerr"]'
            )[0]['disabled']

            # parse mailing address components
            mailing_address = get_address_from_freeform(
                user['separate_mailing_address'])
            mailing_components = mailing_address['components']

            # update fields with mailing address data
            form[
                'ctl00$MainContent$txtDiffStNamePO'].value = get_street_address_from_components(
                    mailing_components)
            if mailing_components.get('secondary_number'):
                form[
                    'ctl00$MainContent$txtDiffUnitApt'].value = get_address_unit_from_components(
                        mailing_components)
            form[
                'ctl00$MainContent$txtDiffCityTownCounty'].value = mailing_components[
                    'city_name']
            form['ctl00$MainContent$txtDiffZip'].value = mailing_components[
                'zipcode']
            form[
                'ctl00$MainContent$ddlDiffStateTerr'].value = mailing_components[
                    'state_abbreviation']

        # former name
        if user.get('has_previous_name'):
            prev_first, prev_middle, prev_last = split_name(
                user.get('previous_name'))

            del self.browser.select(
                'input[name="ctl00$MainContent$txtFirstNameFormer"]'
            )[0]['disabled']
            del self.browser.select(
                'input[name="ctl00$MainContent$txtLastNameFormer"]'
            )[0]['disabled']

            form['ctl00$MainContent$txtFirstNameFormer'].value = prev_first
            form['ctl00$MainContent$txtLastNameFormer'].value = prev_last

        # address where you were last registered to vote
        if user.get('has_previous_address'):
            form['ctl00$MainContent$ChkPrevRegAddr'].checked = 'checked'
            form['ctl00$MainContent$ChkPrevRegAddr'].value = 'on'

            # remove the disabled attr on the relevant fields
            del self.browser.select(
                'input[name="ctl00$MainContent$TxtPrevRegStAddr"]'
            )[0]['disabled']
            del self.browser.select(
                'input[name="ctl00$MainContent$TxtPrevRegUnitApt"]'
            )[0]['disabled']
            del self.browser.select(
                'input[name="ctl00$MainContent$TxtPrevRegCityTownCounty"]'
            )[0]['disabled']
            del self.browser.select(
                'input[name="ctl00$MainContent$TxtPrevRegZip"]')[0]['disabled']
            del self.browser.select(
                'select[name="ctl00$MainContent$ddlPrevRegStateTerr"]'
            )[0]['disabled']

            # update fields with previous address data
            form['ctl00$MainContent$TxtPrevRegStAddr'].value = user.get(
                'previous_address', '')
            form['ctl00$MainContent$TxtPrevRegUnitApt'].value = user.get(
                'previous_address_unit', '')
            form[
                'ctl00$MainContent$TxtPrevRegCityTownCounty'].value = user.get(
                    'previous_city', '')
            form['ctl00$MainContent$TxtPrevRegZip'].value = user.get(
                'previous_zip', '')
            state_options = options_dict(
                form['ctl00$MainContent$ddlPrevRegStateTerr'])
            try:
                prev_state = state_options[state_abbr_to_name(
                    user.get('previous_state'))]
                form[
                    'ctl00$MainContent$ddlPrevRegStateTerr'].value = prev_state
            except KeyError:
                pass

        self.browser.submit_form(form)
示例#6
0
    def register_to_vote(self, user):
        frm = self.browser.get_form()

        user["political_party"] = user["political_party"].strip()

        if user['political_party'].lower(
        ) == 'independent' or user['political_party'].lower() == "none":
            frm['partyPreference'].value = "No Party Preference"

        else:
            party_options = options_dict(frm['partyPreference'])
            # do fuzzy match to political party options
            party_choice = get_party_from_list(user['political_party'],
                                               party_options.keys())

            if party_choice in party_options.keys():
                frm['partyPreference'].value = party_options[party_choice]
            else:
                frm['otherPartyPreference'].value = user['political_party']

        frm['email'].value = user['email']

        if user.get('has_previous_address'):
            frm['regOther'].checked = 'checked'
            prev_address_components = get_address_components(
                user['previous_address'], user['previous_city'],
                user['previous_state'], user['previous_zip'])
            # County or state where previously registered
            try:
                if prev_address_components['state_abbreviation'] == "AZ":
                    COUNTY_IDS = {
                        "Apache": "01",
                        "Cochise": "02",
                        "Coconino": "03",
                        "Gila": "04",
                        "Graham": "05",
                        "Greenlee": "06",
                        "Maricopa": "07",
                        "Mohave": "08",
                        "Navajo": "09",
                        "Pima": "10",
                        "Pinal": "11",
                        "Santa Cruz": "12",
                        "Yavapai": "13",
                        "Yuma": "14",
                        "La Paz": "15"
                    }
                    frm['regCounty'].value = COUNTY_IDS[
                        prev_address_components['county_name']]
                else:
                    frm['regCounty'].value = user['previous_state']
            except KeyError:
                raise ValidationError(
                    message='unable to match previous state/county',
                    payload=user['previous_zip'])

        if user.get('has_previous_name'):
            frm['nameChange'].checked = 'checked'
            (prev_first, prev_middle,
             prev_last) = split_name(user.get('previous_name'))
            frm['formerFirstName'] = prev_first
            frm['formerMiddleName'] = prev_middle
            frm['formerLastname'] = prev_last

        self.browser.submit_form(frm,
                                 submit=frm['_eventId_register'],
                                 headers=self.get_default_submit_headers())