本文整理汇总了Python中candidate.models.CandidateCampaignManager.fetch_candidate_campaign_we_vote_id_from_id方法的典型用法代码示例。如果您正苦于以下问题:Python CandidateCampaignManager.fetch_candidate_campaign_we_vote_id_from_id方法的具体用法?Python CandidateCampaignManager.fetch_candidate_campaign_we_vote_id_from_id怎么用?Python CandidateCampaignManager.fetch_candidate_campaign_we_vote_id_from_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类candidate.models.CandidateCampaignManager
的用法示例。
在下文中一共展示了CandidateCampaignManager.fetch_candidate_campaign_we_vote_id_from_id方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ballot_item_we_vote_id
# 需要导入模块: from candidate.models import CandidateCampaignManager [as 别名]
# 或者: from candidate.models.CandidateCampaignManager import fetch_candidate_campaign_we_vote_id_from_id [as 别名]
def ballot_item_we_vote_id(self):
if self.candidate_campaign_we_vote_id:
return self.candidate_campaign_we_vote_id
elif self.contest_office_we_vote_id:
return self.contest_office_we_vote_id
elif self.contest_measure_we_vote_id:
return self.contest_measure_we_vote_id
elif self.candidate_campaign_id:
candidate_campaign_manager = CandidateCampaignManager()
return candidate_campaign_manager.fetch_candidate_campaign_we_vote_id_from_id(self.candidate_campaign_id)
elif self.contest_measure_id:
contest_measure_manager = ContestMeasureManager()
return contest_measure_manager.fetch_contest_measure_we_vote_id_from_id(self.contest_measure_id)
elif self.contest_office_id:
contest_office_manager = ContestOfficeManager()
return contest_office_manager.fetch_contest_office_we_vote_id_from_id(self.contest_office_id)
else:
return 'not_found'
示例2: positions_public_count_for_candidate_campaign
# 需要导入模块: from candidate.models import CandidateCampaignManager [as 别名]
# 或者: from candidate.models.CandidateCampaignManager import fetch_candidate_campaign_we_vote_id_from_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
示例3: toggle_voter_starred_item
# 需要导入模块: from candidate.models import CandidateCampaignManager [as 别名]
# 或者: from candidate.models.CandidateCampaignManager import fetch_candidate_campaign_we_vote_id_from_id [as 别名]
def toggle_voter_starred_item(
self, voter_id, star_status, candidate_campaign_id=0, contest_office_id=0, contest_measure_id=0,
contest_office_we_vote_id='', candidate_campaign_we_vote_id='', contest_measure_we_vote_id=''):
# Does a star_item entry exist from this voter already exist?
star_item_manager = StarItemManager()
star_item_id = 0
results = star_item_manager.retrieve_star_item(
star_item_id, voter_id,
contest_office_id, candidate_campaign_id, contest_measure_id)
star_item_on_stage_found = False
star_item_on_stage_id = 0
star_item_on_stage = StarItem()
if results['star_item_found']:
star_item_on_stage = results['star_item']
# Update this star_item entry with new values - we do not delete because we might be able to use
try:
star_item_on_stage.star_status = star_status
# We don't need to update date_last_changed here because set set auto_now=True in the field
star_item_on_stage.save()
star_item_on_stage_id = star_item_on_stage.id
star_item_on_stage_found = True
status = 'UPDATE ' + star_status
except Exception as e:
status = 'FAILED_TO_UPDATE ' + star_status
handle_record_not_saved_exception(e, logger=logger, exception_message_optional=status)
elif results['MultipleObjectsReturned']:
logger.warn("star_item: delete all but one and take it over?")
status = 'TOGGLE_ITEM_STARRED MultipleObjectsReturned ' + star_status
elif results['DoesNotExist']:
try:
# Create new star_item entry
if candidate_campaign_id and not candidate_campaign_we_vote_id:
candidate_campaign_manager = CandidateCampaignManager()
candidate_campaign_we_vote_id = \
candidate_campaign_manager.fetch_candidate_campaign_we_vote_id_from_id(candidate_campaign_id)
if contest_measure_id and not contest_measure_we_vote_id:
contest_measure_manager = ContestMeasureManager()
contest_measure_we_vote_id = contest_measure_manager.fetch_contest_measure_we_vote_id_from_id(
contest_measure_id)
if contest_office_id and not contest_office_we_vote_id:
contest_office_manager = ContestOfficeManager()
contest_office_we_vote_id = contest_office_manager.fetch_contest_office_we_vote_id_from_id(
contest_office_id)
# NOTE: For speed purposes, we are not validating the existence of the items being starred
# although we could if the we_vote_id is not returned.
star_item_on_stage = StarItem(
voter_id=voter_id,
candidate_campaign_id=candidate_campaign_id,
candidate_campaign_we_vote_id=candidate_campaign_we_vote_id,
contest_office_id=contest_office_id,
contest_office_we_vote_id=contest_office_we_vote_id,
contest_measure_id=contest_measure_id,
contest_measure_we_vote_id=contest_measure_we_vote_id,
star_status=star_status,
# We don't need to update date_last_changed here because set set auto_now=True in the field
)
star_item_on_stage.save()
star_item_on_stage_id = star_item_on_stage.id
star_item_on_stage_found = True
status = 'CREATE ' + star_status
except Exception as e:
status = 'FAILED_TO_UPDATE ' + star_status
handle_record_not_saved_exception(e, logger=logger, exception_message_optional=status)
else:
status = results['status']
results = {
'success': True if star_item_on_stage_found else False,
'status': status,
'star_item_found': star_item_on_stage_found,
'star_item_id': star_item_on_stage_id,
'star_item': star_item_on_stage,
}
return results
示例4: voter_supporting_save_for_api
# 需要导入模块: from candidate.models import CandidateCampaignManager [as 别名]
# 或者: from candidate.models.CandidateCampaignManager import fetch_candidate_campaign_we_vote_id_from_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')
示例5: voter_star_status_retrieve_for_api
# 需要导入模块: from candidate.models import CandidateCampaignManager [as 别名]
# 或者: from candidate.models.CandidateCampaignManager import fetch_candidate_campaign_we_vote_id_from_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')
#.........这里部分代码省略.........