Exemplo n.º 1
0
def process_contest_referendum_from_structured_json(
        one_contest_referendum_structured_json, google_civic_election_id, ocd_division_id, local_ballot_order,
        state_code, voter_id, polling_location_we_vote_id):
    """
    "referendumTitle": "Proposition 45",
    "referendumSubtitle": "Healthcare Insurance. Rate Changes. Initiative Statute.",
    "referendumUrl": "http://vig.cdn.sos.ca.gov/2014/general/en/pdf/proposition-45-title-summary-analysis.pdf",
    "district" <= this is an array
    """
    referendum_title = one_contest_referendum_structured_json['referendumTitle'] if \
        'referendumTitle' in one_contest_referendum_structured_json else ''
    referendum_subtitle = one_contest_referendum_structured_json['referendumSubtitle'] if \
        'referendumSubtitle' in one_contest_referendum_structured_json else ''
    referendum_url = one_contest_referendum_structured_json['referendumUrl'] if \
        'referendumUrl' in one_contest_referendum_structured_json else ''
    referendum_text = one_contest_referendum_structured_json['referendumText'] if \
        'referendumText' in one_contest_referendum_structured_json else ''

    # These following fields exist for both candidates and referendum
    results = process_contest_common_fields_from_structured_json(one_contest_referendum_structured_json)
    google_ballot_placement = results['ballot_placement']  # A number specifying the position of this contest
    # on the voter's ballot.
    primary_party = results['primary_party']  # If this is a partisan election, the name of the party it is for.
    district_name = results['district_name']  # The name of the district.
    district_scope = results['district_scope']   # The geographic scope of this district. If unspecified the
    # district's geography is not known. One of: national, statewide, congressional, stateUpper, stateLower,
    # countywide, judicial, schoolBoard, cityWide, township, countyCouncil, cityCouncil, ward, special
    district_id = results['district_id']

    # Note that all of the information saved here is independent of a particular voter
    we_vote_id = ''
    if google_civic_election_id and (district_id or district_name) and referendum_title:
        update_contest_measure_values = {
            # Values we search against
            'google_civic_election_id': google_civic_election_id,
            'state_code': state_code.lower(),  # Not required for cases of federal offices
            'district_id': district_id,
            'district_name': district_name,
            'measure_title': referendum_title,
            # The rest of the values
            'measure_subtitle': referendum_subtitle,
            'measure_url': referendum_url,
            'measure_text': referendum_text,
            'ocd_division_id': ocd_division_id,
            'primary_party': primary_party,
            'district_scope': district_scope,
        }
        contest_measure_manager = ContestMeasureManager()
        update_or_create_contest_measure_results = contest_measure_manager.update_or_create_contest_measure(
            we_vote_id, google_civic_election_id, district_id, district_name, referendum_title, state_code,
            update_contest_measure_values)  # , create_contest_measure_values
    else:
        update_or_create_contest_measure_results = {
            'success': False,
            'saved': 0,
            'updated': 0,
            'not_processed': 1,
        }

    if update_or_create_contest_measure_results['success']:
        contest_measure = update_or_create_contest_measure_results['contest_measure']
        contest_measure_id = contest_measure.id
        contest_measure_we_vote_id = contest_measure.we_vote_id
        ballot_item_display_name = contest_measure.measure_title
        measure_subtitle = contest_measure.measure_subtitle
        ballot_item_manager = BallotItemManager()

        # If a voter_id was passed in, save an entry for this office for the voter's ballot
        if positive_value_exists(voter_id) and positive_value_exists(google_civic_election_id) \
                and positive_value_exists(contest_measure_id):
            contest_office_id = 0
            contest_office_we_vote_id = ''
            ballot_item_manager.update_or_create_ballot_item_for_voter(
                voter_id, google_civic_election_id, google_ballot_placement, ballot_item_display_name,
                measure_subtitle, local_ballot_order,
                contest_office_id, contest_office_we_vote_id,
                contest_measure_id, contest_measure_we_vote_id)

        if positive_value_exists(polling_location_we_vote_id) and positive_value_exists(google_civic_election_id) \
                and positive_value_exists(contest_measure_id):
            contest_office_id = 0
            contest_office_we_vote_id = ''
            ballot_item_manager.update_or_create_ballot_item_for_polling_location(
                polling_location_we_vote_id, google_civic_election_id, google_ballot_placement,
                ballot_item_display_name, measure_subtitle,
                local_ballot_order,
                contest_office_id, contest_office_we_vote_id,
                contest_measure_id, contest_measure_we_vote_id)

    return update_or_create_contest_measure_results
Exemplo n.º 2
0
def process_contest_referendum_from_structured_json(
        one_contest_referendum_structured_json, google_civic_election_id,
        ocd_division_id, local_ballot_order, state_code, voter_id,
        polling_location_we_vote_id):
    """
    "referendumTitle": "Proposition 45",
    "referendumSubtitle": "Healthcare Insurance. Rate Changes. Initiative Statute.",
    "referendumUrl": "http://vig.cdn.sos.ca.gov/2014/general/en/pdf/proposition-45-title-summary-analysis.pdf",
    "district" <= this is an array
    """
    referendum_title = one_contest_referendum_structured_json['referendumTitle'] if \
        'referendumTitle' in one_contest_referendum_structured_json else ''
    referendum_subtitle = one_contest_referendum_structured_json['referendumSubtitle'] if \
        'referendumSubtitle' in one_contest_referendum_structured_json else ''
    referendum_url = one_contest_referendum_structured_json['referendumUrl'] if \
        'referendumUrl' in one_contest_referendum_structured_json else ''
    referendum_text = one_contest_referendum_structured_json['referendumText'] if \
        'referendumText' in one_contest_referendum_structured_json else ''

    # These following fields exist for both candidates and referendum
    results = process_contest_common_fields_from_structured_json(
        one_contest_referendum_structured_json)
    google_ballot_placement = results[
        'ballot_placement']  # A number specifying the position of this contest
    # on the voter's ballot.
    primary_party = results[
        'primary_party']  # If this is a partisan election, the name of the party it is for.
    district_name = results['district_name']  # The name of the district.
    district_scope = results[
        'district_scope']  # The geographic scope of this district. If unspecified the
    # district's geography is not known. One of: national, statewide, congressional, stateUpper, stateLower,
    # countywide, judicial, schoolBoard, cityWide, township, countyCouncil, cityCouncil, ward, special
    district_id = results['district_id']

    # Note that all of the information saved here is independent of a particular voter
    we_vote_id = ''
    if google_civic_election_id and (district_id
                                     or district_name) and referendum_title:
        update_contest_measure_values = {
            # Values we search against
            'google_civic_election_id': google_civic_election_id,
            'state_code':
            state_code.lower(),  # Not required for cases of federal offices
            'district_id': district_id,
            'district_name': district_name,
            'measure_title': referendum_title,
            # The rest of the values
            'measure_subtitle': referendum_subtitle,
            'measure_url': referendum_url,
            'measure_text': referendum_text,
            'ocd_division_id': ocd_division_id,
            'primary_party': primary_party,
            'district_scope': district_scope,
        }
        contest_measure_manager = ContestMeasureManager()
        update_or_create_contest_measure_results = contest_measure_manager.update_or_create_contest_measure(
            we_vote_id, google_civic_election_id, district_id, district_name,
            referendum_title, state_code,
            update_contest_measure_values)  # , create_contest_measure_values
    else:
        update_or_create_contest_measure_results = {
            'success': False,
            'saved': 0,
            'updated': 0,
            'not_processed': 1,
        }

    if update_or_create_contest_measure_results['success']:
        contest_measure = update_or_create_contest_measure_results[
            'contest_measure']
        contest_measure_id = contest_measure.id
        contest_measure_we_vote_id = contest_measure.we_vote_id
        ballot_item_display_name = contest_measure.measure_title
        measure_subtitle = contest_measure.measure_subtitle
        ballot_item_manager = BallotItemManager()

        # If a voter_id was passed in, save an entry for this office for the voter's ballot
        if positive_value_exists(voter_id) and positive_value_exists(google_civic_election_id) \
                and positive_value_exists(contest_measure_id):
            contest_office_id = 0
            contest_office_we_vote_id = ''
            ballot_item_manager.update_or_create_ballot_item_for_voter(
                voter_id, google_civic_election_id, google_ballot_placement,
                ballot_item_display_name, measure_subtitle, local_ballot_order,
                contest_office_id, contest_office_we_vote_id,
                contest_measure_id, contest_measure_we_vote_id)

        if positive_value_exists(polling_location_we_vote_id) and positive_value_exists(google_civic_election_id) \
                and positive_value_exists(contest_measure_id):
            contest_office_id = 0
            contest_office_we_vote_id = ''
            ballot_item_manager.update_or_create_ballot_item_for_polling_location(
                polling_location_we_vote_id, google_civic_election_id,
                google_ballot_placement, ballot_item_display_name,
                measure_subtitle, local_ballot_order, contest_office_id,
                contest_office_we_vote_id, contest_measure_id,
                contest_measure_we_vote_id)

    return update_or_create_contest_measure_results