本文整理汇总了Python中candidate.models.CandidateCampaignManager.fetch_candidate_campaign_id_from_we_vote_id方法的典型用法代码示例。如果您正苦于以下问题:Python CandidateCampaignManager.fetch_candidate_campaign_id_from_we_vote_id方法的具体用法?Python CandidateCampaignManager.fetch_candidate_campaign_id_from_we_vote_id怎么用?Python CandidateCampaignManager.fetch_candidate_campaign_id_from_we_vote_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类candidate.models.CandidateCampaignManager
的用法示例。
在下文中一共展示了CandidateCampaignManager.fetch_candidate_campaign_id_from_we_vote_id方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: positions_public_count_for_candidate_campaign
# 需要导入模块: from candidate.models import CandidateCampaignManager [as 别名]
# 或者: from candidate.models.CandidateCampaignManager import fetch_candidate_campaign_id_from_we_vote_id [as 别名]
def positions_public_count_for_candidate_campaign(candidate_id, candidate_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 candidate's campaign
"""
# 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_candidate_campaign = \
position_list_manager.retrieve_public_positions_count_for_candidate_campaign(
candidate_id,
candidate_we_vote_id,
stance_we_are_looking_for)
if positive_value_exists(candidate_id) or positive_value_exists(candidate_we_vote_id):
candidate_campaign_manager = CandidateCampaignManager()
# Since we can take in either candidate_id or candidate_we_vote_id, we need to retrieve the value we don't have
if positive_value_exists(candidate_id):
candidate_we_vote_id = candidate_campaign_manager.fetch_candidate_campaign_we_vote_id_from_id(candidate_id)
elif positive_value_exists(candidate_we_vote_id):
candidate_id = candidate_campaign_manager.fetch_candidate_campaign_id_from_we_vote_id(candidate_we_vote_id)
json_data = {
'status': 'SUCCESSFUL_RETRIEVE_OF_PUBLIC_POSITION_COUNT_RE_CANDIDATE',
'success': True,
'count': all_positions_count_for_candidate_campaign,
'ballot_item_id': convert_to_int(candidate_id),
'ballot_item_we_vote_id': candidate_we_vote_id,
'kind_of_ballot_item': CANDIDATE,
}
results = {
'json_data': json_data,
}
return results
示例2: quick_info_import_from_sample_file
# 需要导入模块: from candidate.models import CandidateCampaignManager [as 别名]
# 或者: from candidate.models.CandidateCampaignManager import fetch_candidate_campaign_id_from_we_vote_id [as 别名]
def quick_info_import_from_sample_file(request=None): # , load_from_uri=False # TODO to be converted
"""
Get the json data, and either create new entries or update existing
:return:
"""
# if load_from_uri:
# # Request json file from We Vote servers
# messages.add_message(request, messages.INFO, "Loading quick_info from We Vote Master servers")
# request = requests.get(QUICK_INFO_URL, params={
# "key": WE_VOTE_API_KEY, # This comes from an environment variable
# })
# structured_json = json.loads(request.text)
# else:
# Load saved json from local file
with open("quick_info/import_data/quick_info_sample.json") as json_data:
structured_json = json.load(json_data)
quick_info_saved = 0
quick_info_updated = 0
quick_info_not_processed = 0
for one_quick_info in structured_json:
# Make sure we have the minimum required variables
if not positive_value_exists(one_quick_info["we_vote_id"]) \
or not positive_value_exists(one_quick_info["organization_we_vote_id"])\
or not positive_value_exists(one_quick_info["candidate_campaign_we_vote_id"]):
quick_info_not_processed += 1
continue
# Check to see if this quick_info is already being used anywhere
quick_info_found = False
try:
if len(one_quick_info["we_vote_id"]) > 0:
quick_info_query = QuickInfo.objects.filter(we_vote_id=one_quick_info["we_vote_id"])
if len(quick_info_query):
quick_info = quick_info_query[0]
quick_info_found = True
except QuickInfo.DoesNotExist as e:
handle_record_not_found_exception(e, logger=logger)
pass
except Exception as e:
handle_record_not_found_exception(e, logger=logger)
# We need to look up the local organization_id based on the newly saved we_vote_id
organization_manager = OrganizationManager()
organization_id = organization_manager.fetch_organization_id(one_quick_info["organization_we_vote_id"])
# We need to look up the local candidate_campaign_id
candidate_campaign_manager = CandidateCampaignManager()
candidate_campaign_id = candidate_campaign_manager.fetch_candidate_campaign_id_from_we_vote_id(
one_quick_info["candidate_campaign_we_vote_id"])
# Find the google_civic_candidate_name so we have a backup way to link quick_info if the we_vote_id is lost
google_civic_candidate_name = one_quick_info["google_civic_candidate_name"] if \
"google_civic_candidate_name" in one_quick_info else ''
if not positive_value_exists(google_civic_candidate_name):
google_civic_candidate_name = candidate_campaign_manager.fetch_google_civic_candidate_name_from_we_vote_id(
one_quick_info["candidate_campaign_we_vote_id"])
# TODO We need to look up contest_measure_id
contest_measure_id = 0
try:
if quick_info_found:
# Update
quick_info.we_vote_id = one_quick_info["we_vote_id"]
quick_info.organization_id = organization_id
quick_info.organization_we_vote_id = one_quick_info["organization_we_vote_id"]
quick_info.candidate_campaign_id = candidate_campaign_id
quick_info.candidate_campaign_we_vote_id = one_quick_info["candidate_campaign_we_vote_id"]
quick_info.google_civic_candidate_name = google_civic_candidate_name
quick_info.contest_measure_id = contest_measure_id
quick_info.date_entered = one_quick_info["date_entered"]
quick_info.google_civic_election_id = one_quick_info["google_civic_election_id"]
quick_info.stance = one_quick_info["stance"]
quick_info.more_info_url = one_quick_info["more_info_url"]
quick_info.statement_text = one_quick_info["statement_text"]
quick_info.statement_html = one_quick_info["statement_html"]
quick_info.save()
quick_info_updated += 1
# messages.add_message(request, messages.INFO, u"QuickInfo updated: {we_vote_id}".format(
# we_vote_id=one_quick_info["we_vote_id"]))
else:
# Create new
quick_info = QuickInfo(
we_vote_id=one_quick_info["we_vote_id"],
organization_id=organization_id,
organization_we_vote_id=one_quick_info["organization_we_vote_id"],
candidate_campaign_id=candidate_campaign_id,
candidate_campaign_we_vote_id=one_quick_info["candidate_campaign_we_vote_id"],
google_civic_candidate_name=google_civic_candidate_name,
contest_measure_id=contest_measure_id,
date_entered=one_quick_info["date_entered"],
google_civic_election_id=one_quick_info["google_civic_election_id"],
stance=one_quick_info["stance"],
more_info_url=one_quick_info["more_info_url"],
statement_text=one_quick_info["statement_text"],
statement_html=one_quick_info["statement_html"],
)
quick_info.save()
quick_info_saved += 1
#.........这里部分代码省略.........
示例3: voter_supporting_save_for_api
# 需要导入模块: from candidate.models import CandidateCampaignManager [as 别名]
# 或者: from candidate.models.CandidateCampaignManager import fetch_candidate_campaign_id_from_we_vote_id [as 别名]
def voter_supporting_save_for_api(voter_device_id, candidate_id, candidate_we_vote_id, measure_id, measure_we_vote_id):
# Get voter_id from the voter_device_id so we can know who is supporting/opposing, voterSupportingSave
results = is_voter_device_id_valid(voter_device_id)
if not results['success']:
json_data = {
'status': 'VALID_VOTER_DEVICE_ID_MISSING',
'success': False,
'ballot_item_id': 0,
'ballot_item_we_vote_id': '',
'kind_of_ballot_item': '',
}
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,
'ballot_item_id': 0,
'ballot_item_we_vote_id': '',
'kind_of_ballot_item': '',
}
return HttpResponse(json.dumps(json_data), content_type='application/json')
position_entered_manager = PositionEnteredManager()
if positive_value_exists(candidate_id) or positive_value_exists(candidate_we_vote_id):
candidate_campaign_manager = CandidateCampaignManager()
# Since we can take in either candidate_id or candidate_we_vote_id, we need to retrieve the value we don't have
if positive_value_exists(candidate_id):
candidate_we_vote_id = candidate_campaign_manager.fetch_candidate_campaign_we_vote_id_from_id(candidate_id)
elif positive_value_exists(candidate_we_vote_id):
candidate_id = candidate_campaign_manager.fetch_candidate_campaign_id_from_we_vote_id(candidate_we_vote_id)
results = position_entered_manager.toggle_on_voter_support_for_candidate_campaign(voter_id, candidate_id)
status = "SUPPORTING_CANDIDATE " + results['status']
success = results['success']
json_data = {
'status': status,
'success': success,
'ballot_item_id': convert_to_int(candidate_id),
'ballot_item_we_vote_id': candidate_we_vote_id,
'kind_of_ballot_item': CANDIDATE,
}
return HttpResponse(json.dumps(json_data), content_type='application/json')
elif 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)
results = position_entered_manager.toggle_on_voter_support_for_contest_measure(voter_id, measure_id)
status = "SUPPORTING_MEASURE " + results['status']
success = results['success']
json_data = {
'status': status,
'success': success,
'ballot_item_id': convert_to_int(measure_id),
'ballot_item_we_vote_id': measure_we_vote_id,
'kind_of_ballot_item': MEASURE,
}
return HttpResponse(json.dumps(json_data), content_type='application/json')
else:
status = 'UNABLE_TO_SAVE-CANDIDATE_ID_AND_MEASURE_ID_MISSING'
success = False
json_data = {
'status': status,
'success': success,
'ballot_item_id': 0,
'ballot_item_we_vote_id': '',
'kind_of_ballot_item': '',
}
return HttpResponse(json.dumps(json_data), content_type='application/json')
示例4: voter_star_status_retrieve_for_api
# 需要导入模块: from candidate.models import CandidateCampaignManager [as 别名]
# 或者: from candidate.models.CandidateCampaignManager import fetch_candidate_campaign_id_from_we_vote_id [as 别名]
def voter_star_status_retrieve_for_api(voter_device_id,
office_id, office_we_vote_id,
candidate_id, candidate_we_vote_id,
measure_id, measure_we_vote_id):
# Get voter_id from the voter_device_id so we can know who is doing the starring
results = is_voter_device_id_valid(voter_device_id)
if not results['success']:
json_data = {
'status': 'VALID_VOTER_DEVICE_ID_MISSING',
'success': False,
'voter_device_id': voter_device_id,
'is_starred': False,
'office_id': convert_to_int(office_id),
'candidate_id': convert_to_int(candidate_id),
'measure_id': convert_to_int(measure_id),
'ballot_item_id': 0,
'ballot_item_we_vote_id': '',
'kind_of_ballot_item': '',
}
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,
'voter_device_id': voter_device_id,
'is_starred': False,
'office_id': convert_to_int(office_id),
'candidate_id': convert_to_int(candidate_id),
'measure_id': convert_to_int(measure_id),
'ballot_item_id': 0,
'ballot_item_we_vote_id': '',
'kind_of_ballot_item': '',
}
return HttpResponse(json.dumps(json_data), content_type='application/json')
star_item_manager = StarItemManager()
if positive_value_exists(office_id) or positive_value_exists(office_we_vote_id):
contest_office_manager = ContestOfficeManager()
# Since we can take in either office_id or office_we_vote_id, we need to retrieve the value we don't have
if positive_value_exists(office_id):
office_we_vote_id = contest_office_manager.fetch_contest_office_we_vote_id_from_id(office_id)
elif positive_value_exists(office_we_vote_id):
office_id = contest_office_manager.fetch_contest_office_id_from_we_vote_id(office_we_vote_id)
# Zero out the unused values
star_item_id = 0
candidate_campaign_id = 0
contest_measure_id = 0
results = star_item_manager.retrieve_star_item(star_item_id, voter_id, office_id,
candidate_campaign_id, contest_measure_id)
status = results['status']
success = results['success']
is_starred = results['is_starred']
json_data = {
'status': status,
'success': success,
'voter_device_id': voter_device_id,
'is_starred': is_starred,
'ballot_item_id': convert_to_int(office_id),
'ballot_item_we_vote_id': office_we_vote_id,
'kind_of_ballot_item': OFFICE,
'office_id': convert_to_int(office_id),
'candidate_id': convert_to_int(candidate_id),
'measure_id': convert_to_int(measure_id),
}
return HttpResponse(json.dumps(json_data), content_type='application/json')
elif positive_value_exists(candidate_id) or positive_value_exists(candidate_we_vote_id):
candidate_campaign_manager = CandidateCampaignManager()
# Since we can take in either candidate_id or candidate_we_vote_id, we need to retrieve the value we don't have
if positive_value_exists(candidate_id):
candidate_we_vote_id = candidate_campaign_manager.fetch_candidate_campaign_we_vote_id_from_id(candidate_id)
elif positive_value_exists(candidate_we_vote_id):
candidate_id = candidate_campaign_manager.fetch_candidate_campaign_id_from_we_vote_id(candidate_we_vote_id)
# Zero out the unused values
star_item_id = 0
contest_office_id = 0
contest_measure_id = 0
results = star_item_manager.retrieve_star_item(star_item_id, voter_id, contest_office_id, candidate_id,
contest_measure_id)
status = results['status']
success = results['success']
is_starred = results['is_starred']
json_data = {
'status': status,
'success': success,
'voter_device_id': voter_device_id,
'is_starred': is_starred,
'ballot_item_id': convert_to_int(candidate_id),
'ballot_item_we_vote_id': candidate_we_vote_id,
'kind_of_ballot_item': CANDIDATE,
'office_id': convert_to_int(office_id),
'candidate_id': convert_to_int(candidate_id),
'measure_id': convert_to_int(measure_id),
}
return HttpResponse(json.dumps(json_data), content_type='application/json')
#.........这里部分代码省略.........
示例5: positions_import_from_sample_file
# 需要导入模块: from candidate.models import CandidateCampaignManager [as 别名]
# 或者: from candidate.models.CandidateCampaignManager import fetch_candidate_campaign_id_from_we_vote_id [as 别名]
def positions_import_from_sample_file(request=None, load_from_uri=False):
"""
Get the json data, and either create new entries or update existing
:return:
"""
# if load_from_uri:
# # Request json file from We Vote servers
# messages.add_message(request, messages.INFO, "Loading positions from We Vote Master servers")
# request = requests.get(POSITIONS_URL, params={
# "key": WE_VOTE_API_KEY, # This comes from an environment variable
# })
# structured_json = json.loads(request.text)
# else:
# Load saved json from local file
with open("position/import_data/positions_sample.json") as json_data:
structured_json = json.load(json_data)
positions_saved = 0
positions_updated = 0
positions_not_processed = 0
for one_position in structured_json:
# Make sure we have the minimum required variables
if not positive_value_exists(one_position["we_vote_id"]) \
or not positive_value_exists(one_position["organization_we_vote_id"])\
or not positive_value_exists(one_position["candidate_campaign_we_vote_id"]):
positions_not_processed += 1
continue
# Check to see if this position is already being used anywhere
position_on_stage_found = False
try:
if len(one_position["we_vote_id"]) > 0:
position_query = PositionEntered.objects.filter(we_vote_id=one_position["we_vote_id"])
if len(position_query):
position_on_stage = position_query[0]
position_on_stage_found = True
except PositionEntered.DoesNotExist as e:
handle_record_not_found_exception(e, logger=logger)
pass
except Exception as e:
handle_record_not_found_exception(e, logger=logger)
# We need to look up the local organization_id based on the newly saved we_vote_id
organization_manager = OrganizationManager()
organization_id = organization_manager.fetch_organization_id(one_position["organization_we_vote_id"])
# We need to look up the local candidate_campaign_id
candidate_campaign_manager = CandidateCampaignManager()
candidate_campaign_id = candidate_campaign_manager.fetch_candidate_campaign_id_from_we_vote_id(
one_position["candidate_campaign_we_vote_id"])
# Find the google_civic_candidate_name so we have a backup way to link position if the we_vote_id is lost
google_civic_candidate_name = one_position["google_civic_candidate_name"] if \
"google_civic_candidate_name" in one_position else ''
if not positive_value_exists(google_civic_candidate_name):
google_civic_candidate_name = candidate_campaign_manager.fetch_google_civic_candidate_name_from_we_vote_id(
one_position["candidate_campaign_we_vote_id"])
# TODO We need to look up measure_campaign_id
measure_campaign_id = 0
try:
if position_on_stage_found:
# Update
position_on_stage.we_vote_id = one_position["we_vote_id"]
position_on_stage.organization_id = organization_id
position_on_stage.organization_we_vote_id = one_position["organization_we_vote_id"]
position_on_stage.candidate_campaign_id = candidate_campaign_id
position_on_stage.candidate_campaign_we_vote_id = one_position["candidate_campaign_we_vote_id"]
position_on_stage.google_civic_candidate_name = google_civic_candidate_name
position_on_stage.measure_campaign_id = measure_campaign_id
position_on_stage.date_entered = one_position["date_entered"]
position_on_stage.google_civic_election_id = one_position["google_civic_election_id"]
position_on_stage.stance = one_position["stance"]
position_on_stage.more_info_url = one_position["more_info_url"]
position_on_stage.statement_text = one_position["statement_text"]
position_on_stage.statement_html = one_position["statement_html"]
position_on_stage.save()
positions_updated += 1
# messages.add_message(request, messages.INFO, u"Position updated: {we_vote_id}".format(
# we_vote_id=one_position["we_vote_id"]))
else:
# Create new
position_on_stage = PositionEntered(
we_vote_id=one_position["we_vote_id"],
organization_id=organization_id,
organization_we_vote_id=one_position["organization_we_vote_id"],
candidate_campaign_id=candidate_campaign_id,
candidate_campaign_we_vote_id=one_position["candidate_campaign_we_vote_id"],
google_civic_candidate_name=google_civic_candidate_name,
measure_campaign_id=measure_campaign_id,
date_entered=one_position["date_entered"],
google_civic_election_id=one_position["google_civic_election_id"],
stance=one_position["stance"],
more_info_url=one_position["more_info_url"],
statement_text=one_position["statement_text"],
statement_html=one_position["statement_html"],
)
position_on_stage.save()
positions_saved += 1
#.........这里部分代码省略.........