<s> from django . db import models <EOL> from exception . models import handle_record_found_more_than_one_exception <EOL> import wevote_functions . admin <EOL> from wevote_functions . models import value_exists <EOL> logger = wevote_functions . admin . get_logger ( __name__ ) <EOL> class GoogleCivicElection ( models . Model ) : <EOL> google_civic_election_id = models . CharField ( <EOL> verbose_name = "<STR_LIT>" , max_length = <NUM_LIT:20> , null = False , unique = True ) <EOL> we_vote_election_id = models . CharField ( <EOL> verbose_name = "<STR_LIT>" , max_length = <NUM_LIT:20> , null = True , blank = True , unique = True ) <EOL> name = models . CharField ( verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = False , blank = False ) <EOL> election_day = models . CharField ( verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = False , blank = False ) <EOL> was_processed = models . BooleanField ( verbose_name = "<STR_LIT>" , default = False , null = False , blank = False ) <EOL> class GoogleCivicContestOffice ( models . Model ) : <EOL> office = models . CharField ( verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = False , blank = False ) <EOL> google_civic_election_id = models . CharField ( <EOL> verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = True , blank = True ) <EOL> we_vote_election_id = models . CharField ( verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = True , blank = True ) <EOL> we_vote_contest_office_id = models . CharField ( <EOL> verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = True , blank = True ) <EOL> number_voting_for = models . CharField ( verbose_name = "<STR_LIT>" , <EOL> max_length = <NUM_LIT> , null = True , blank = True ) <EOL> number_elected = models . CharField ( verbose_name = "<STR_LIT>" , <EOL> max_length = <NUM_LIT> , null = True , blank = True ) <EOL> contest_level0 = models . CharField ( verbose_name = "<STR_LIT>" , <EOL> max_length = <NUM_LIT> , null = True , blank = True ) <EOL> contest_level1 = models . CharField ( verbose_name = "<STR_LIT>" , <EOL> max_length = <NUM_LIT> , null = True , blank = True ) <EOL> contest_level2 = models . CharField ( verbose_name = "<STR_LIT>" , <EOL> max_length = <NUM_LIT> , null = True , blank = True ) <EOL> ballot_placement = models . CharField ( verbose_name = "<STR_LIT>" , <EOL> max_length = <NUM_LIT> , null = True , blank = True ) <EOL> primary_party = models . CharField ( verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = True , blank = True ) <EOL> district_name = models . CharField ( verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = False , blank = False ) <EOL> district_scope = models . CharField ( verbose_name = "<STR_LIT>" , <EOL> max_length = <NUM_LIT> , null = False , blank = False ) <EOL> district_ocd_id = models . CharField ( verbose_name = "<STR_LIT>" , <EOL> max_length = <NUM_LIT> , null = False , blank = False ) <EOL> electorate_specifications = models . CharField ( verbose_name = "<STR_LIT>" , <EOL> max_length = <NUM_LIT> , null = True , blank = True ) <EOL> special = models . CharField ( verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = True , blank = True ) <EOL> was_processed = models . BooleanField ( verbose_name = "<STR_LIT>" , default = False , null = False , blank = False ) <EOL> class GoogleCivicCandidateCampaign ( models . Model ) : <EOL> name = models . CharField ( verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = False , blank = False ) <EOL> party = models . CharField ( verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = True , blank = True ) <EOL> photo_url = models . CharField ( verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = True , blank = True ) <EOL> order_on_ballot = models . CharField ( <EOL> verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = True , blank = True ) <EOL> google_civic_contest_office_id = models . CharField ( verbose_name = "<STR_LIT>" , <EOL> max_length = <NUM_LIT> , null = False , blank = False ) <EOL> we_vote_contest_office_id = models . CharField ( <EOL> verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = True , blank = True ) <EOL> google_civic_election_id = models . CharField ( verbose_name = "<STR_LIT>" , <EOL> max_length = <NUM_LIT> , null = False , blank = False ) <EOL> we_vote_election_id = models . CharField ( verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = True , blank = True ) <EOL> we_vote_candidate_campaign_id = models . CharField ( verbose_name = "<STR_LIT>" , <EOL> max_length = <NUM_LIT> , null = True , blank = True ) <EOL> we_vote_politician_id = models . CharField ( <EOL> verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = True , blank = True ) <EOL> candidate_url = models . URLField ( verbose_name = '<STR_LIT>' , blank = True , null = True ) <EOL> facebook_url = models . URLField ( verbose_name = '<STR_LIT>' , blank = True , null = True ) <EOL> twitter_url = models . URLField ( verbose_name = '<STR_LIT>' , blank = True , null = True ) <EOL> google_plus_url = models . URLField ( verbose_name = '<STR_LIT>' , blank = True , null = True ) <EOL> youtube_url = models . URLField ( verbose_name = '<STR_LIT>' , blank = True , null = True ) <EOL> email = models . CharField ( verbose_name = "<STR_LIT>" , <EOL> max_length = <NUM_LIT> , null = True , blank = True ) <EOL> phone = models . CharField ( verbose_name = "<STR_LIT>" , <EOL> max_length = <NUM_LIT> , null = True , blank = True ) <EOL> was_processed = models . BooleanField ( verbose_name = "<STR_LIT>" , default = False , null = False , blank = False ) <EOL> class GoogleCivicContestReferendum ( models . Model ) : <EOL> referendum_title = models . CharField ( <EOL> verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = False , blank = False ) <EOL> referendum_subtitle = models . CharField ( <EOL> verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = False , blank = False ) <EOL> referendum_url = models . CharField ( <EOL> verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = True , blank = False ) <EOL> google_civic_election_id = models . CharField ( <EOL> verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = False , blank = False ) <EOL> we_vote_election_id = models . CharField ( <EOL> verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = True , blank = True ) <EOL> ballot_placement = models . CharField ( <EOL> verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = True , blank = True ) <EOL> primary_party = models . CharField ( verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = True , blank = True ) <EOL> district_name = models . CharField ( verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = False , blank = False ) <EOL> district_scope = models . CharField ( verbose_name = "<STR_LIT>" , <EOL> max_length = <NUM_LIT> , null = False , blank = False ) <EOL> district_ocd_id = models . CharField ( verbose_name = "<STR_LIT>" , <EOL> max_length = <NUM_LIT> , null = False , blank = False ) <EOL> electorate_specifications = models . CharField ( verbose_name = "<STR_LIT>" , <EOL> max_length = <NUM_LIT> , null = True , blank = True ) <EOL> special = models . CharField ( verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = True , blank = True ) <EOL> was_processed = models . BooleanField ( verbose_name = "<STR_LIT>" , default = False , null = False , blank = False ) <EOL> class GoogleCivicBallotItem ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> voter_id = models . IntegerField ( verbose_name = "<STR_LIT>" , unique = False , null = False , blank = False ) <EOL> google_civic_election_id = models . CharField ( <EOL> verbose_name = "<STR_LIT>" , max_length = <NUM_LIT:20> , null = False , unique = False ) <EOL> district_ocd_id = models . CharField ( <EOL> verbose_name = "<STR_LIT>" , max_length = <NUM_LIT> , null = False , blank = False , unique = False ) <EOL> google_ballot_order = models . SmallIntegerField ( <EOL> verbose_name = "<STR_LIT>" , null = True , blank = True , unique = False ) <EOL> ballot_order = models . SmallIntegerField ( <EOL> verbose_name = "<STR_LIT>" , null = True , blank = True ) <EOL> class GoogleCivicBallotItemManager ( models . Model ) : <EOL> def save_ballot_item_for_voter ( <EOL> self , voter_id , google_civic_election_id , google_civic_district_ocd_id , google_ballot_order , <EOL> local_ballot_order ) : <EOL> try : <EOL> google_civic_ballot_item = GoogleCivicBallotItem ( voter_id = voter_id , <EOL> google_civic_election_id = google_civic_election_id , <EOL> district_ocd_id = google_civic_district_ocd_id , <EOL> google_ballot_order = google_ballot_order , <EOL> ballot_order = local_ballot_order , ) <EOL> google_civic_ballot_item . save ( ) <EOL> except GoogleCivicBallotItem . DoesNotExist as e : <EOL> pass <EOL> def retrieve_ballot_item_for_voter ( self , voter_id , google_civic_election_id , google_civic_district_ocd_id ) : <EOL> error_result = False <EOL> exception_does_not_exist = False <EOL> exception_multiple_object_returned = False <EOL> google_civic_ballot_item_on_stage = GoogleCivicBallotItem ( ) <EOL> if value_exists ( voter_id ) and value_exists ( google_civic_election_id ) and value_exists ( <EOL> google_civic_district_ocd_id ) : <EOL> try : <EOL> google_civic_ballot_item_on_stage = GoogleCivicBallotItem . objects . get ( <EOL> voter_id = voter_id , <EOL> google_civic_election_id = google_civic_election_id , <EOL> district_ocd_id = google_civic_district_ocd_id , <EOL> ) <EOL> google_civic_ballot_item_id = google_civic_ballot_item_on_stage . id <EOL> except GoogleCivicBallotItem . MultipleObjectsReturned as e : <EOL> handle_record_found_more_than_one_exception ( e , logger = logger ) <EOL> exception_multiple_object_returned = True <EOL> except GoogleCivicBallotItem . DoesNotExist as e : <EOL> exception_does_not_exist = True <EOL> results = { <EOL> '<STR_LIT:success>' : True if google_civic_ballot_item_id > <NUM_LIT:0> else False , <EOL> '<STR_LIT>' : exception_does_not_exist , <EOL> '<STR_LIT>' : exception_multiple_object_returned , <EOL> '<STR_LIT>' : google_civic_ballot_item_on_stage , <EOL> } <EOL> return results <EOL> def fetch_ballot_order ( self , voter_id , google_civic_election_id , google_civic_district_ocd_id ) : <EOL> return <NUM_LIT:3> </s>
