本文整理汇总了Python中wevote_functions.functions.positive_value_exists函数的典型用法代码示例。如果您正苦于以下问题:Python positive_value_exists函数的具体用法?Python positive_value_exists怎么用?Python positive_value_exists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了positive_value_exists函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: retrieve_address
def retrieve_address(self, voter_address_id, voter_id=0, address_type=''):
error_result = False
exception_does_not_exist = False
exception_multiple_object_returned = False
voter_address_on_stage = VoterAddress()
voter_address_has_value = False
if not positive_value_exists(address_type):
# Provide a default
address_type = BALLOT_ADDRESS
try:
if positive_value_exists(voter_address_id):
voter_address_on_stage = VoterAddress.objects.get(id=voter_address_id)
voter_address_id = voter_address_on_stage.id
voter_address_found = True
status = "VOTER_ADDRESS_FOUND_BY_ID"
success = True
voter_address_has_value = True if positive_value_exists(voter_address_on_stage.text_for_map_search) \
else False
elif positive_value_exists(voter_id) and address_type in (BALLOT_ADDRESS, MAILING_ADDRESS,
FORMER_BALLOT_ADDRESS):
voter_address_on_stage = VoterAddress.objects.get(voter_id=voter_id, address_type=address_type)
# If still here, we found an existing address
voter_address_id = voter_address_on_stage.id
voter_address_found = True
status = "VOTER_ADDRESS_FOUND_BY_VOTER_ID_AND_ADDRESS_TYPE"
success = True
voter_address_has_value = True if positive_value_exists(voter_address_on_stage.text_for_map_search) \
else False
else:
voter_address_found = False
status = "VOTER_ADDRESS_NOT_FOUND-MISSING_REQUIRED_VARIABLES"
success = False
except VoterAddress.MultipleObjectsReturned as e:
handle_record_found_more_than_one_exception(e, logger=logger)
error_result = True
status = "VOTER_ADDRESS_MULTIPLE_OBJECTS_RETURNED"
exception_multiple_object_returned = True
success = False
voter_address_found = False
except VoterAddress.DoesNotExist:
error_result = True
status = "VOTER_ADDRESS_DOES_NOT_EXIST"
exception_does_not_exist = True
success = True
voter_address_found = False
results = {
'success': success,
'status': status,
'error_result': error_result,
'DoesNotExist': exception_does_not_exist,
'MultipleObjectsReturned': exception_multiple_object_returned,
'voter_address_found': voter_address_found,
'voter_address_has_value': voter_address_has_value,
'voter_address_id': voter_address_id,
'voter_address': voter_address_on_stage,
}
return results
示例2: save_new_voter_device_link
def save_new_voter_device_link(self, voter_device_id, voter_id):
error_result = False
exception_record_not_saved = False
missing_required_variables = False
voter_device_link_on_stage = VoterDeviceLink()
voter_device_link_id = 0
try:
if positive_value_exists(voter_device_id) and positive_value_exists(voter_id):
voter_device_link_on_stage.voter_device_id = voter_device_id
voter_device_link_on_stage.voter_id = voter_id
voter_device_link_on_stage.save()
voter_device_link_id = voter_device_link_on_stage.id
else:
missing_required_variables = True
voter_device_link_id = 0
except Exception as e:
handle_record_not_saved_exception(e, logger=logger)
error_result = True
exception_record_not_saved = True
results = {
'error_result': error_result,
'missing_required_variables': missing_required_variables,
'RecordNotSaved': exception_record_not_saved,
'voter_device_link_created': True if voter_device_link_id > 0 else False,
'voter_device_link': voter_device_link_on_stage,
}
return results
示例3: positions_public_count_for_contest_measure
def positions_public_count_for_contest_measure(measure_id, measure_we_vote_id, stance_we_are_looking_for):
"""
We want to return a JSON file with the number of orgs and public figures who support
this particular measure
"""
# This implementation is built to make only two database calls. All other calculations are done here in the
# application layer
position_list_manager = PositionListManager()
all_positions_count_for_contest_measure = \
position_list_manager.retrieve_public_positions_count_for_contest_measure(
measure_id, measure_we_vote_id, stance_we_are_looking_for)
if positive_value_exists(measure_id) or positive_value_exists(measure_we_vote_id):
contest_measure_manager = ContestMeasureManager()
# Since we can take in either measure_id or measure_we_vote_id, we need to retrieve the value we don't have
if positive_value_exists(measure_id):
measure_we_vote_id = contest_measure_manager.fetch_contest_measure_we_vote_id_from_id(measure_id)
elif positive_value_exists(measure_we_vote_id):
measure_id = contest_measure_manager.fetch_contest_measure_id_from_we_vote_id(measure_we_vote_id)
json_data = {
'status': 'SUCCESSFUL_RETRIEVE_OF_PUBLIC_POSITION_COUNT_FOR_CONTEST_MEASURE',
'success': True,
'count': all_positions_count_for_contest_measure,
'ballot_item_id': convert_to_int(measure_id),
'ballot_item_we_vote_id': measure_we_vote_id,
'kind_of_ballot_item': MEASURE,
}
results = {
'json_data': json_data,
}
return results
示例4: retrieve_daily_summaries
def retrieve_daily_summaries(self, kind_of_action="", google_civic_election_id=0):
# Start with today and cycle backwards in time
daily_summaries = []
day_on_stage = date.today() # TODO: We need to work out the timezone questions
number_found = 0
maximum_attempts = 30
attempt_count = 0
try:
# Limit the number of times this runs to EITHER 1) 5 positive numbers
# OR 2) 30 days in the past, whichever comes first
while number_found <= 5 and attempt_count <= maximum_attempts:
attempt_count += 1
counter_queryset = GoogleCivicApiCounter.objects.all()
if positive_value_exists(kind_of_action):
counter_queryset = counter_queryset.filter(kind_of_action=kind_of_action)
if positive_value_exists(google_civic_election_id):
counter_queryset = counter_queryset.filter(google_civic_election_id=google_civic_election_id)
# Find the number of these entries on that particular day
counter_queryset = counter_queryset.filter(datetime_of_action__contains=day_on_stage)
api_call_count = len(counter_queryset)
# If any api calls were found on that date, pass it out for display
if positive_value_exists(api_call_count):
daily_summary = {"date_string": day_on_stage, "count": api_call_count}
daily_summaries.append(daily_summary)
number_found += 1
day_on_stage -= timedelta(days=1)
except Exception:
pass
return daily_summaries
示例5: refresh_existing_voter_guides_view
def refresh_existing_voter_guides_view(request):
authority_required = {'verified_volunteer'} # admin, verified_volunteer
if not voter_has_authority(request, authority_required):
return redirect_to_sign_in_page(request, authority_required)
voter_guide_updated_count = 0
# Cycle through existing voter_guides
voter_guide_list_manager = VoterGuideListManager()
voter_guide_manager = VoterGuideManager()
results = voter_guide_list_manager.retrieve_all_voter_guides()
if results['voter_guide_list_found']:
voter_guide_list = results['voter_guide_list']
for voter_guide in voter_guide_list:
if positive_value_exists(voter_guide.organization_we_vote_id):
if positive_value_exists(voter_guide.google_civic_election_id):
results = voter_guide_manager.update_or_create_organization_voter_guide_by_election_id(
voter_guide.organization_we_vote_id, voter_guide.google_civic_election_id)
if results['success']:
voter_guide_updated_count += 1
elif positive_value_exists(voter_guide.vote_smart_time_span):
results = voter_guide_manager.update_or_create_organization_voter_guide_by_time_span(
voter_guide.organization_we_vote_id, voter_guide.vote_smart_time_span)
if results['success']:
voter_guide_updated_count += 1
messages.add_message(request, messages.INFO,
'{voter_guide_updated_count} updated.'.format(
voter_guide_updated_count=voter_guide_updated_count,
))
return HttpResponseRedirect(reverse('voter_guide:voter_guide_list', args=()))
示例6: candidate_politician_match_view
def candidate_politician_match_view(request):
authority_required = {'verified_volunteer'} # admin, verified_volunteer
if not voter_has_authority(request, authority_required):
return redirect_to_sign_in_page(request, authority_required)
candidate_id = request.GET.get('candidate_id', 0)
candidate_id = convert_to_int(candidate_id)
# google_civic_election_id is included for interface usability reasons and isn't used in the processing
google_civic_election_id = request.GET.get('google_civic_election_id', 0)
google_civic_election_id = convert_to_int(google_civic_election_id)
if not positive_value_exists(candidate_id):
messages.add_message(request, messages.ERROR, "The candidate_id variable was not passed in.")
return HttpResponseRedirect(reverse('candidate:candidate_edit', args=(candidate_id,)))
candidate_campaign_manager = CandidateCampaignManager()
results = candidate_campaign_manager.retrieve_candidate_campaign_from_id(candidate_id)
if not positive_value_exists(results['candidate_campaign_found']):
messages.add_message(request, messages.ERROR,
"Candidate '{candidate_id}' not found.".format(candidate_id=candidate_id))
return HttpResponseRedirect(reverse('candidate:candidate_edit', args=(candidate_id,)))
we_vote_candidate = results['candidate_campaign']
# Make sure we have a politician for this candidate. If we don't, create a politician entry, and save the
# politician_we_vote_id in the candidate
results = candidate_politician_match(we_vote_candidate)
display_messages = True
if results['status'] and display_messages:
messages.add_message(request, messages.INFO, results['status'])
return HttpResponseRedirect(reverse('candidate:candidate_edit', args=(candidate_id,)) +
"?google_civic_election_id=" + str(google_civic_election_id))
示例7: toggle_off_voter_position_like
def toggle_off_voter_position_like(self, position_like_id, voter_id, position_entered_id):
if positive_value_exists(position_like_id):
try:
PositionLike.objects.filter(id=position_like_id).delete()
status = "DELETED_BY_POSITION_LIKE_ID"
success = True
except Exception as e:
status = "UNABLE_TO_DELETE_BY_POSITION_LIKE_ID: {error}".format(
error=e
)
success = False
elif positive_value_exists(voter_id) and positive_value_exists(position_entered_id):
try:
PositionLike.objects.filter(voter_id=voter_id, position_entered_id=position_entered_id).delete()
status = "DELETED_BY_VOTER_ID_AND_POSITION_ENTERED_ID"
success = True
except Exception as e:
status = "UNABLE_TO_DELETE_BY_VOTER_ID_AND_POSITION_ENTERED_ID: {error}".format(
error=e
)
success = False
else:
status = "UNABLE_TO_DELETE_NO_VARIABLES"
success = False
results = {
'status': status,
'success': success,
}
return results
示例8: save_twitter_user_values
def save_twitter_user_values(self, voter, twitter_user_object):
try:
# 'id': 132728535,
if positive_value_exists(twitter_user_object.id):
voter.twitter_id = twitter_user_object.id
# 'id_str': '132728535',
# 'utc_offset': 32400,
# 'description': "Cars, Musics, Games, Electronics, toys, food, etc... I'm just a typical boy!",
# 'profile_image_url': 'http://a1.twimg.com/profile_images/1213351752/_2_2__normal.jpg',
if positive_value_exists(twitter_user_object.profile_image_url_https):
voter.twitter_profile_image_url_https = twitter_user_object.profile_image_url_https
# 'profile_background_image_url': 'http://a2.twimg.com/a/1294785484/images/themes/theme15/bg.png',
# 'screen_name': 'jaeeeee',
if positive_value_exists(twitter_user_object.screen_name):
voter.twitter_screen_name = twitter_user_object.screen_name
# 'lang': 'en',
# 'name': 'Jae Jung Chung',
# 'url': 'http://www.carbonize.co.kr',
# 'time_zone': 'Seoul',
voter.save()
success = True
status = "SAVED_VOTER_TWITTER_VALUES"
except Exception as e:
status = "UNABLE_TO_SAVE_VOTER_TWITTER_VALUES"
success = False
handle_record_not_saved_exception(e, logger=logger, exception_message_optional=status)
results = {
'status': status,
'success': success,
'voter': voter,
}
return results
示例9: voter_ballot_items_retrieve_view
def voter_ballot_items_retrieve_view(request):
"""
(voterBallotItemsRetrieve) Request a skeleton of ballot data for this voter location,
so that the web_app has all of the ids it needs to make more requests for data about each ballot item.
:param request:
:return:
"""
voter_device_id = get_voter_device_id(request) # We look in the cookies for voter_device_id
# If passed in, we want to look at
google_civic_election_id = request.GET.get('google_civic_election_id', 0)
use_test_election = request.GET.get('use_test_election', False)
use_test_election = False if use_test_election == 'false' else use_test_election
use_test_election = False if use_test_election == 'False' else use_test_election
if positive_value_exists(use_test_election):
google_civic_election_id = 2000 # The Google Civic API Test election
elif not positive_value_exists(google_civic_election_id):
# We look in the cookies for google_civic_election_id
google_civic_election_id = get_google_civic_election_id_from_cookie(request)
# This 'voter_ballot_items_retrieve_for_api' lives in apis_v1/controllers.py
results = voter_ballot_items_retrieve_for_api(voter_device_id, google_civic_election_id)
response = HttpResponse(json.dumps(results['json_data']), content_type='application/json')
# Save google_civic_election_id in the cookie so the interface knows
google_civic_election_id_from_ballot_retrieve = results['google_civic_election_id']
if positive_value_exists(google_civic_election_id_from_ballot_retrieve):
set_google_civic_election_id_cookie(request, response, results['google_civic_election_id'])
return response
示例10: update_voter_guide_social_media_statistics
def update_voter_guide_social_media_statistics(self, organization):
"""
Update voter_guide entry with details retrieved from Twitter, Facebook, or ???
"""
success = False
status = "ENTERING_UPDATE_VOTER_GUIDE_SOCIAL_MEDIA_STATISTICS"
values_changed = False
voter_guide = VoterGuide()
if organization:
if positive_value_exists(organization.twitter_followers_count):
results = self.retrieve_most_recent_voter_guide_for_org(organization_we_vote_id=organization.we_vote_id)
if results['voter_guide_found']:
voter_guide = results['voter_guide']
if positive_value_exists(voter_guide.id):
if voter_guide.twitter_followers_count != organization.twitter_followers_count:
voter_guide.twitter_followers_count = organization.twitter_followers_count
values_changed = True
if positive_value_exists(values_changed):
voter_guide.save()
success = True
status = "SAVED_ORG_TWITTER_DETAILS"
else:
success = True
status = "NO_CHANGES_SAVED_TO_ORG_TWITTER_DETAILS"
results = {
'success': success,
'status': status,
'organization': organization,
'voter_guide': voter_guide,
}
return results
示例11: retrieve_ballot_item_for_voter
def retrieve_ballot_item_for_voter(self, voter_id, google_civic_election_id, google_civic_district_ocd_id):
exception_does_not_exist = False
exception_multiple_object_returned = False
google_civic_ballot_item_on_stage = BallotItem()
google_civic_ballot_item_id = 0
if positive_value_exists(voter_id) and positive_value_exists(google_civic_election_id) and \
positive_value_exists(google_civic_district_ocd_id):
try:
google_civic_ballot_item_on_stage = BallotItem.objects.get(
voter_id__exact=voter_id,
google_civic_election_id__exact=google_civic_election_id,
district_ocd_id=google_civic_district_ocd_id, # TODO This needs to be rethunk
)
google_civic_ballot_item_id = google_civic_ballot_item_on_stage.id
except BallotItem.MultipleObjectsReturned as e:
handle_record_found_more_than_one_exception(e, logger=logger)
exception_multiple_object_returned = True
except BallotItem.DoesNotExist:
exception_does_not_exist = True
results = {
'success': True if google_civic_ballot_item_id > 0 else False,
'DoesNotExist': exception_does_not_exist,
'MultipleObjectsReturned': exception_multiple_object_returned,
'google_civic_ballot_item': google_civic_ballot_item_on_stage,
}
return results
示例12: retrieve_voter_following_org_status
def retrieve_voter_following_org_status(self, voter_id, voter_we_vote_id,
organization_id, organization_we_vote_id):
"""
Retrieve one follow entry so we can see if a voter is following or ignoring a particular org
"""
if not positive_value_exists(voter_id) and positive_value_exists(voter_we_vote_id):
# We need voter_id to call retrieve_follow_organization
voter_manager = VoterManager()
voter_id = voter_manager.fetch_local_id_from_we_vote_id(voter_we_vote_id)
if not positive_value_exists(voter_id) and \
not (positive_value_exists(organization_id) or positive_value_exists(organization_we_vote_id)):
results = {
'status': 'RETRIEVE_VOTER_FOLLOWING_MISSING_VARIABLES',
'success': False,
'follow_organization_found': False,
'follow_organization_id': 0,
'follow_organization': FollowOrganization(),
'is_following': False,
'is_not_following': True,
'is_ignoring': False,
'error_result': True,
'DoesNotExist': False,
'MultipleObjectsReturned': False,
}
return results
return self.retrieve_follow_organization(0, voter_id, organization_id, organization_we_vote_id)
示例13: voter_position_like_off_save_for_api
def voter_position_like_off_save_for_api(voter_device_id, position_like_id, position_entered_id):
# Get voter_id from the voter_device_id so we can know who is doing the liking
results = is_voter_device_id_valid(voter_device_id)
if not results['success']:
json_data = {
'status': 'VALID_VOTER_DEVICE_ID_MISSING',
'success': False,
}
return HttpResponse(json.dumps(json_data), content_type='application/json')
voter_id = fetch_voter_id_from_voter_device_link(voter_device_id)
if not positive_value_exists(voter_id):
json_data = {
'status': "VALID_VOTER_ID_MISSING",
'success': False,
}
return HttpResponse(json.dumps(json_data), content_type='application/json')
position_like_manager = PositionLikeManager()
if positive_value_exists(position_like_id) or \
(positive_value_exists(voter_id) and positive_value_exists(position_entered_id)):
results = position_like_manager.toggle_off_voter_position_like(
position_like_id, voter_id, position_entered_id)
status = results['status']
success = results['success']
else:
status = 'UNABLE_TO_DELETE_POSITION_LIKE-INSUFFICIENT_VARIABLES'
success = False
json_data = {
'status': status,
'success': success,
}
return HttpResponse(json.dumps(json_data), content_type='application/json')
示例14: retrieve_candidate_photos_for_election_view
def retrieve_candidate_photos_for_election_view(request, election_id):
authority_required = {'admin'} # admin, verified_volunteer
if not voter_has_authority(request, authority_required):
return redirect_to_sign_in_page(request, authority_required)
google_civic_election_id = convert_to_int(election_id)
# We only want to process if a google_civic_election_id comes in
if not positive_value_exists(google_civic_election_id):
messages.add_message(request, messages.ERROR, "Google Civic Election ID required.")
return HttpResponseRedirect(reverse('candidate:candidate_list', args=()))
try:
candidate_list = CandidateCampaign.objects.order_by('candidate_name')
if positive_value_exists(google_civic_election_id):
candidate_list = candidate_list.filter(google_civic_election_id=google_civic_election_id)
except CandidateCampaign.DoesNotExist:
pass
display_messages = False
force_retrieve = False
# Loop through all of the candidates in this election
for we_vote_candidate in candidate_list:
retrieve_candidate_results = retrieve_candidate_photos(we_vote_candidate, force_retrieve)
if retrieve_candidate_results['status'] and display_messages:
messages.add_message(request, messages.INFO, retrieve_candidate_results['status'])
return HttpResponseRedirect(reverse('candidate:candidate_list', args=()) + "?google_civic_election_id={var}".format(
var=google_civic_election_id))
示例15: refresh_twitter_candidate_details_for_election
def refresh_twitter_candidate_details_for_election(google_civic_election_id):
twitter_handles_added = 0
profiles_refreshed_with_twitter_data = 0
google_civic_election_id = convert_to_int(google_civic_election_id)
candidate_list_manager = CandidateCampaignListManager()
return_list_of_objects = True
candidates_results = candidate_list_manager.retrieve_all_candidates_for_upcoming_election(
google_civic_election_id, return_list_of_objects)
if candidates_results['candidate_list_found']:
candidate_list = candidates_results['candidate_list_objects']
for candidate in candidate_list:
# Extract twitter_handle from google_civic_election information
if positive_value_exists(candidate.twitter_url) \
and not positive_value_exists(candidate.candidate_twitter_handle):
# If we got a twitter_url from Google Civic, and we haven't already stored a twitter handle, move it
candidate.candidate_twitter_handle = extract_twitter_handle_from_text_string(candidate.twitter_url)
candidate.save()
twitter_handles_added += 1
if positive_value_exists(candidate.candidate_twitter_handle):
refresh_twitter_candidate_details(candidate)
profiles_refreshed_with_twitter_data += 1
status = "CANDIDATE_SOCIAL_MEDIA_RETRIEVED"
results = {
'success': True,
'status': status,
'twitter_handles_added': twitter_handles_added,
'profiles_refreshed_with_twitter_data': profiles_refreshed_with_twitter_data,
}
return results