Example #1
0
    def previous_info(self, user, form):

        if user.get('has_previous_name'):
            prev_first, prev_middle, prev_last = split_name(
                user.get('previous_name'))
            form['previousFirstName'] = prev_first
            form['previousMiddleName'] = prev_middle
            form['previousLastName'] = prev_last

        if user.get('has_previous_address'):
            form['chkPrvVote'].value = 'Y'
            form['chkPrvVote'].checked = 'checked'

            address_components = get_address_components(
                user['previous_address'], user['previous_city'],
                user['previous_state'], user['previous_zip'])
            street_name = address_components['street_name']
            if 'street_predirection' in address_components:
                street_name = "%s %s" % (
                    address_components['street_predirection'], street_name)
            if 'street_postdirection' in address_components:
                street_name = "%s %s" % (
                    street_name, address_components['street_postdirection'])
            form['previousAddressLine1'].value = street_name

            form['previousAddressCity'].value = address_components['city_name']
            form['previousAddressState'].value = address_components[
                'state_abbreviation']
            form['previousAddressZip'].value = address_components['zipcode']

        else:
            form['chkPrvVote'].value = 'N'
            form['chkPrvVote'].checked = 'checked'
Example #2
0
    def general_information(self, user, form):
        # these fields are all optional, fill in only if defined
        if user.get('gender'):
            form['gender'].options = [
                'Male', 'Female'
            ]  # they have two buttons with the same name but different ids
            gender_str = parse_gender(
                user['gender'])  # coerces free text to M/F
            if gender_str is 'F':
                form['gender'].value = 'Female'
            elif gender_str is 'M':
                form['gender'].value = 'Male'
            else:
                raise ValidationError(message='parse_gender error',
                                      payload=user['gender'])

        # poll_worker
        if user.get('ssn_last_4'):
            form['ssnId'] = user['ssn_last_4']
            # also accepts full SSN, but no dashes
        if user.get('email'):
            form['emailId'] = user['email']
        if user.get('phone'):
            form['telephone'] = user['phone']
            # format?
        # ethnicity requires a dropdown, and is optional
        # skip it

        # previous address appears here
        if user.get('has_previous_address'):
            prev_address_components = get_address_components(
                user['previous_address'], user['previous_city'],
                user['previous_state'], user['previous_zip'])
            form['preStreetNo'].value = prev_address_components[
                'primary_number']
            form['preStreetName'].value = get_street_name_from_components(
                prev_address_components).upper()
            if 'secondary_number' in prev_address_components:
                form['preAptNo'].value = prev_address_components[
                    'secondary_number']
            form['prePostalCity'].value = prev_address_components['city_name']
            form[
                'ctl00$MainContent$TxtPrevRegZip'].value = prev_address_components[
                    'zipcode']
            form['preState'].value = prev_address_components[
                'state_abbreviation']

        form.action = 'summary.do'
        self.browser.submit_form(form, submit=form['next'])

        return form
Example #3
0
    def illinois_address(self, user):
        self.browser.open('https://ova.elections.il.gov/Step5.aspx')
        frm = self.browser.get_form()

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

        frm['ctl00$MainContent$tbResidentStreetNumber'].value = address_components[
            'primary_number']

        if 'street_predirection' in address_components:
            frm['ctl00$MainContent$ddlResidentStreetDirection'].value = options_dict(
                frm['ctl00$MainContent$ddlResidentStreetDirection'])[
                    address_components['street_predirection'].upper()]

        frm['ctl00$MainContent$tbResidentStreetName'].value = address_components[
            'street_name']

        if 'street_suffix' in address_components:
            frm['ctl00$MainContent$ddlResidentStreetType'].value = options_dict(
                frm['ctl00$MainContent$ddlResidentStreetType'])[
                    address_components['street_suffix'].upper()]

        if 'street_postdirection' in address_components:
            frm['ctl00$MainContent$ddlResidentPostDirection'].value = options_dict(
                frm['ctl00$MainContent$ddlResidentPostDirection'])[
                    address_components['street_postdirection'].upper()]

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

            if 'secondary_designator' in address_components:
                try:
                    frm['ctl00$MainContent$ddlResidentAptRmBoxSuite'].value = options_dict(
                        frm['ctl00$MainContent$ddlResidentAptRmBoxSuite'])[
                            address_components['secondary_designator']]
                except:
                    pass

        frm['ctl00$MainContent$tbResidentCity'].value = address_components[
            'city_name']
        frm['ctl00$MainContent$tbResidentZip'].value = address_components[
            'zipcode']

        self.browser.submit_form(frm, submit=frm['ctl00$MainContent$btnNext'])
Example #4
0
    def residence_address(self, user, form):
        # reassemble address_components to match street name dropdowns
        # in the browser this autofills, but we get to do it manually
        address_components = get_address_components(user['address'],
                                                    user['city'],
                                                    user['state'], user['zip'])

        form['streetNum'].value = address_components['primary_number']

        full_street_name = get_street_name_from_components(address_components)
        form['streetName1'].value = options_dict(
            form['streetName1'])[full_street_name.upper()]

        street_value = form['streetName1'].value

        # look up postal city key and rural_flag from street_value
        postal_city = self.get_postal_city(
            street_value, address_components['county_name'])[0]
        rural_flag = postal_city['fl_Rural_Flag']
        form['ruralcityFlag'].value = rural_flag.lower()
        if rural_flag == "Y":
            form['rural_city'].options = (postal_city['key'], )
            form['rural_city'].value = str(postal_city['key'])
        else:
            # replace weird city selector with a regular input
            form.fields.pop('city')
            city_field = robobrowser.forms.fields.Input(
                '<input type="hidden" id="city" name="city"></input>')
            city_field.value = str(postal_city['key'])
            form.add_field(city_field)

        # of course, there's also a hidden cityName field to append
        city_name = robobrowser.forms.fields.Input(
            '<input type="hidden" id="cityName" name="cityName"></input>')
        city_name.value = address_components['city_name'].upper()
        form.add_field(city_name)

        form['state'].value = address_components['state_abbreviation']
        form['zip5'].value = address_components['zipcode']
        form['countyS3'].value = address_components['county_name'].upper()

        # update form action, this happens in javascript on validateForm
        form.action = 'regStep4.do'

        self.browser.submit_form(form, submit=form['next'])
        return form
Example #5
0
    def illinois_different_address(self, user):
        self.browser.open('https://ova.elections.il.gov/Step10b.aspx')
        frm = self.browser.get_form()

        if user["has_previous_address"]:
            address_components = get_address_components(
                user['previous_address'], user['previous_city'],
                user['previous_state'], user['previous_zip'])

            frm['ctl00$MainContent$tbFormerStreetNumber'].value = address_components[
                'primary_number']

            if 'street_predirection' in address_components:
                frm['ctl00$MainContent$ddlFormerStreetDirection'].value = options_dict(
                    frm['ctl00$MainContent$ddlFormerStreetDirection'])[
                        address_components['street_predirection'].upper()]

            frm['ctl00$MainContent$tbFormerStreetName'].value = address_components[
                'street_name']

            if 'street_suffix' in address_components:
                frm['ctl00$MainContent$ddlFormerStreetType'].value = options_dict(
                    frm['ctl00$MainContent$ddlFormerStreetType'])[
                        address_components['street_suffix'].upper()]

            if 'street_postdirection' in address_components:
                frm['ctl00$MainContent$ddlFormerPostDirection'].value = options_dict(
                    frm['ctl00$MainContent$ddlFormerPostDirection'])[
                        address_components['street_postdirection'].upper()]

            frm['ctl00$MainContent$tbFormerCity'].value = address_components[
                'city_name']
            frm['ctl00$MainContent$tbFormerZip'].value = address_components[
                'zipcode']

            election_authority = self.determine_election_authority(
                address_components['city_name'],
                address_components['county_name'])
            frm['ctl00$MainContent$ddlCountySelect'].value = options_dict(
                frm['ctl00$MainContent$ddlCountySelect'])[election_authority]

        else:
            frm["ctl00$MainContent$rblFormerAddress"].value = "No"

        self.browser.submit_form(frm, submit=frm['ctl00$MainContent$btnNext'])
Example #6
0
    def address(self, user, form):
        address_components = get_address_components(user['address'],
                                                    user['city'],
                                                    user['state'], user['zip'])

        form['addressNumber'].value = address_components['primary_number']
        form['addressStreet1'].value = get_street_name_from_components(
            address_components)

        if user.get('address_unit'
                    ) and not user.get('address_unit').lower() == "none":
            form['addressUnit'].value = user.get('address_unit')

        form['addressCity'].value = user['city']
        form['addressZip'].value = user['zip']

        if user.get('has_separate_mailing_address'):
            # TODO
            pass
        else:
            form['chkSameResidence'].checked = 'checked'
Example #7
0
    def address(self, user, form):
        address_components = get_address_components(user['address'],
                                                    user['city'],
                                                    user['state'], user['zip'])

        form['resstreetnumber'] = address_components['primary_number']

        street_name = get_street_name_from_components(address_components)
        form["resaddress"] = street_name.upper()

        form['rescity'] = user['city'].upper()
        form['resstate'] = user['state'].upper()
        form['reszip'] = user['zip']

        county_list = {
            "ADAIR": 1,
            "ALLEN": 2,
            "ANDERSON": 3,
            "BALLARD": 4,
            "BARREN": 5,
            "BATH": 6,
            "BELL": 7,
            "BOONE": 8,
            "BOURBON": 9,
            "BOYD": 10,
            "BOYLE": 11,
            "BRACKEN": 12,
            "BREATHITT": 13,
            "BRECKINRIDGE": 14,
            "BULLITT": 15,
            "BUTLER": 16,
            "CALDWELL": 17,
            "CALLOWAY": 18,
            "CAMPBELL": 19,
            "CARLISLE": 20,
            "CARROLL": 21,
            "CARTER": 22,
            "CASEY": 23,
            "CHRISTIAN": 24,
            "CLARK": 25,
            "CLAY": 26,
            "CLINTON": 27,
            "CRITTENDEN": 28,
            "CUMBERLAND": 29,
            "DAVIESS": 30,
            "EDMONSON": 31,
            "ELLIOTT": 32,
            "ESTILL": 33,
            "FAYETTE": 34,
            "FLEMING": 35,
            "FLOYD": 36,
            "FRANKLIN": 37,
            "FULTON": 38,
            "GALLATIN": 39,
            "GARRARD": 40,
            "GRANT": 41,
            "GRAVES": 42,
            "GRAYSON": 43,
            "GREEN": 44,
            "GREENUP": 45,
            "HANCOCK": 46,
            "HARDIN": 47,
            "HARLAN": 48,
            "HARRISON": 49,
            "HART": 50,
            "HENDERSON": 51,
            "HENRY": 52,
            "HICKMAN": 53,
            "HOPKINS": 54,
            "JACKSON": 55,
            "JEFFERSON": 56,
            "JESSAMINE": 57,
            "JOHNSON": 58,
            "KENTON": 59,
            "KNOTT": 60,
            "KNOX": 61,
            "LARUE": 62,
            "LAUREL": 63,
            "LAWRENCE": 64,
            "LEE": 65,
            "LESLIE": 66,
            "LETCHER": 67,
            "LEWIS": 68,
            "LINCOLN": 69,
            "LIVINGSTON": 70,
            "LOGAN": 71,
            "LYON": 72,
            "MCCRACKEN": 73,
            "MCCREARY": 74,
            "MCLEAN": 75,
            "MADISON": 76,
            "MAGOFFIN": 77,
            "MARION": 78,
            "MARSHALL": 79,
            "MARTIN": 80,
            "MASON": 81,
            "MEADE": 82,
            "MENIFEE": 83,
            "MERCER": 84,
            "METCALFE": 85,
            "MONROE": 86,
            "MONTGOMERY": 87,
            "MORGAN": 88,
            "MUHLENBERG": 89,
            "NELSON": 90,
            "NICHOLAS": 91,
            "OHIO": 92,
            "OLDHAM": 93,
            "OWEN": 94,
            "OWSLEY": 95,
            "PENDLETON": 96,
            "PERRY": 97,
            "PIKE": 98,
            "POWELL": 99,
            "PULASKI": 100,
            "ROBERTSON": 101,
            "ROCKCASTLE": 102,
            "ROWAN": 103,
            "RUSSELL": 104,
            "SCOTT": 105,
            "SHELBY": 106,
            "SIMPSON": 107,
            "SPENCER": 108,
            "TAYLOR": 109,
            "TODD": 110,
            "TRIGG": 111,
            "TRIMBLE": 112,
            "UNION": 113,
            "WARREN": 114,
            "WASHINGTON": 115,
            "WAYNE": 116,
            "WEBSTER": 117,
            "WHITLEY": 118,
            "WOLFE": 119,
            "WOODFORD": 120
        }
        form['countycode'] = str(county_list[user['county'].upper()])

        # mailing address
        if user.get('has_separate_mailing_address'):
            # TODO
            pass
        else:
            # need to post nulls here
            form['mailaddress'] = None
            form['mailcity'] = None
            form['mailstate'] = None
            form['mailzip'] = None
Example #8
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)
Example #9
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())