本文整理汇总了Python中candidate.models.CandidateCampaignManager.retrieve_candidate_campaign_from_we_vote_id方法的典型用法代码示例。如果您正苦于以下问题:Python CandidateCampaignManager.retrieve_candidate_campaign_from_we_vote_id方法的具体用法?Python CandidateCampaignManager.retrieve_candidate_campaign_from_we_vote_id怎么用?Python CandidateCampaignManager.retrieve_candidate_campaign_from_we_vote_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类candidate.models.CandidateCampaignManager
的用法示例。
在下文中一共展示了CandidateCampaignManager.retrieve_candidate_campaign_from_we_vote_id方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: organization_position_new_view
# 需要导入模块: from candidate.models import CandidateCampaignManager [as 别名]
# 或者: from candidate.models.CandidateCampaignManager import retrieve_candidate_campaign_from_we_vote_id [as 别名]
def organization_position_new_view(request, organization_id):
authority_required = {'verified_volunteer'} # admin, verified_volunteer
authority_results = retrieve_voter_authority(request)
if not voter_has_authority(request, authority_required, authority_results):
return redirect_to_sign_in_page(request, authority_required)
google_civic_election_id = request.GET.get('google_civic_election_id', 0)
candidate_we_vote_id = request.GET.get('candidate_we_vote_id', False)
# Take in some incoming values
candidate_not_found = request.GET.get('candidate_not_found', False)
stance = request.GET.get('stance', SUPPORT) # Set a default if stance comes in empty
statement_text = request.GET.get('statement_text', '') # Set a default if stance comes in empty
more_info_url = request.GET.get('more_info_url', '')
# We pass candidate_we_vote_id to this page to pre-populate the form
candidate_campaign_id = 0
if positive_value_exists(candidate_we_vote_id):
candidate_campaign_manager = CandidateCampaignManager()
results = candidate_campaign_manager.retrieve_candidate_campaign_from_we_vote_id(candidate_we_vote_id)
if results['candidate_campaign_found']:
candidate_campaign = results['candidate_campaign']
candidate_campaign_id = candidate_campaign.id
messages_on_stage = get_messages(request)
organization_id = convert_to_int(organization_id)
all_is_well = True
organization_on_stage_found = False
organization_on_stage = Organization()
try:
organization_on_stage = Organization.objects.get(id=organization_id)
organization_on_stage_found = True
except Organization.MultipleObjectsReturned as e:
handle_record_found_more_than_one_exception(e, logger=logger)
except Organization.DoesNotExist:
# This is fine, create new
pass
if not organization_on_stage_found:
messages.add_message(request, messages.INFO,
'Could not find organization when trying to create a new position.')
return HttpResponseRedirect(reverse('organization:organization_position_list', args=([organization_id])))
# Prepare a drop down of candidates competing in this election
candidate_campaign_list = CandidateCampaignListManager()
candidate_campaigns_for_this_election_list = []
if positive_value_exists(google_civic_election_id):
results = candidate_campaign_list.retrieve_all_candidates_for_upcoming_election(google_civic_election_id, True)
if results['candidate_list_found']:
candidate_campaigns_for_this_election_list = results['candidate_list_objects']
else:
candidate_campaigns_for_this_election_list \
= candidate_campaign_list.retrieve_candidate_campaigns_from_all_elections_list()
try:
organization_position_list = PositionEntered.objects.order_by('stance')
organization_position_list = organization_position_list.filter(organization_id=organization_id)
if positive_value_exists(google_civic_election_id):
organization_position_list = organization_position_list.filter(
google_civic_election_id=google_civic_election_id)
organization_position_list = organization_position_list.order_by(
'google_civic_election_id', '-vote_smart_time_span')
if len(organization_position_list):
organization_position_list_found = True
except Exception as e:
organization_position_list = []
if all_is_well:
election_list = Election.objects.order_by('-election_day_text')
template_values = {
'candidate_campaigns_for_this_election_list': candidate_campaigns_for_this_election_list,
'candidate_campaign_id': candidate_campaign_id,
'messages_on_stage': messages_on_stage,
'organization': organization_on_stage,
'organization_position_candidate_campaign_id': 0,
'possible_stances_list': ORGANIZATION_STANCE_CHOICES,
'stance_selected': stance,
'election_list': election_list,
'google_civic_election_id': google_civic_election_id,
'organization_position_list': organization_position_list,
'voter_authority': authority_results,
# Incoming values from error state
'candidate_not_found': candidate_not_found,
'stance': stance,
'statement_text': statement_text,
'more_info_url': more_info_url,
}
return render(request, 'organization/organization_position_edit.html', template_values)
示例2: quick_info_edit_process_view
# 需要导入模块: from candidate.models import CandidateCampaignManager [as 别名]
# 或者: from candidate.models.CandidateCampaignManager import retrieve_candidate_campaign_from_we_vote_id [as 别名]
#.........这里部分代码省略.........
ready_to_save = True
# If entering text specific to this ballot item
elif not positive_value_exists(use_master_entry) or positive_value_exists(use_unique_text):
if not positive_value_exists(language):
messages.add_message(request, messages.ERROR, "Please choose a language for your new entry.")
ready_to_save = False
elif not (positive_value_exists(info_text) or positive_value_exists(info_html)):
messages.add_message(request, messages.ERROR,
"Please enter the text/html information about this ballot item.")
ready_to_save = False
elif not positive_value_exists(more_info_url):
messages.add_message(request, messages.ERROR, "Please enter the source URL for this description.")
ready_to_save = False
else:
ready_to_save = True
else:
messages.add_message(request, messages.ERROR, "More information needed to save this entry.")
ready_to_save = False
if not ready_to_save:
# Could we also just call the view directly with the request, instead of redirecting the browser?
if positive_value_exists(quick_info_id):
return quick_info_edit_view(request, quick_info_id)
# return HttpResponseRedirect(reverse('quick_info:quick_info_edit', args=()) + url_variables)
else:
return quick_info_new_view(request)
# return HttpResponseRedirect(reverse('quick_info:quick_info_new', args=()) + url_variables)
# Now that we know we are ready to save, we want to wipe out the values we don't want to save
if positive_value_exists(use_master_entry):
info_html = ""
info_text = ""
more_info_url = ""
more_info_credit = NOT_SPECIFIED
else:
quick_info_master_we_vote_id = ""
# Figure out what text to use for the Ballot Item Label
if not positive_value_exists(ballot_item_display_name):
if positive_value_exists(contest_office_we_vote_id):
contest_office_manager = ContestOfficeManager()
results = contest_office_manager.retrieve_contest_office_from_we_vote_id(contest_office_we_vote_id)
if results['success']:
contest_office = results['contest_office']
ballot_item_display_name = contest_office.office_name
else:
ballot_item_display_name = ''
elif positive_value_exists(candidate_campaign_we_vote_id):
candidate_campaign_manager = CandidateCampaignManager()
results = candidate_campaign_manager.retrieve_candidate_campaign_from_we_vote_id(
candidate_campaign_we_vote_id)
if results['success']:
candidate_campaign = results['candidate_campaign']
ballot_item_display_name = candidate_campaign.candidate_name
else:
ballot_item_display_name = ''
# if positive_value_exists(politician_we_vote_id):
# ballot_item_display_name = ''
elif positive_value_exists(contest_measure_we_vote_id):
contest_measure_manager = ContestMeasureManager()
results = contest_measure_manager.retrieve_contest_measure_from_we_vote_id(contest_measure_we_vote_id)
if results['success']:
contest_measure = results['contest_measure']
ballot_item_display_name = contest_measure.measure_title
else:
ballot_item_display_name = ""
last_editor_we_vote_id = "" # TODO We need to calculate this
quick_info_manager = QuickInfoManager()
results = quick_info_manager.update_or_create_quick_info(
quick_info_id=quick_info_id,
quick_info_we_vote_id=quick_info_we_vote_id,
ballot_item_display_name=ballot_item_display_name,
contest_office_we_vote_id=contest_office_we_vote_id,
candidate_campaign_we_vote_id=candidate_campaign_we_vote_id,
politician_we_vote_id=politician_we_vote_id,
contest_measure_we_vote_id=contest_measure_we_vote_id,
info_html=info_html,
info_text=info_text,
language=language,
last_editor_we_vote_id=last_editor_we_vote_id,
quick_info_master_we_vote_id=quick_info_master_we_vote_id,
more_info_url=more_info_url,
more_info_credit=more_info_credit,
google_civic_election_id=google_civic_election_id
)
if results['success']:
messages.add_message(request, messages.INFO, results['status'])
else:
messages.add_message(request, messages.ERROR,
results['status'] + "language: {language}".format(
language=language,
))
if positive_value_exists(quick_info_id):
return quick_info_edit_view(request, quick_info_id)
else:
return quick_info_new_view(request)
return HttpResponseRedirect(reverse('quick_info:quick_info_list', args=()))
示例3: positions_count_for_candidate_campaign
# 需要导入模块: from candidate.models import CandidateCampaignManager [as 别名]
# 或者: from candidate.models.CandidateCampaignManager import retrieve_candidate_campaign_from_we_vote_id [as 别名]
def positions_count_for_candidate_campaign(voter_id, candidate_id, candidate_we_vote_id, stance_we_are_looking_for,
show_positions_this_voter_follows=True):
"""
We want to return a JSON file with the number of orgs, friends and public figures the voter follows who support
this particular candidate's campaign
"""
# This implementation is built to make limited database calls. We do as many calculations as we can here in the
# application layer
position_list_manager = PositionListManager()
all_positions_list_for_candidate_campaign = \
position_list_manager.retrieve_all_positions_for_candidate_campaign(
candidate_id, candidate_we_vote_id, stance_we_are_looking_for)
follow_organization_list_manager = FollowOrganizationList()
organizations_followed_by_voter = \
follow_organization_list_manager.retrieve_follow_organization_by_voter_id_simple_id_array(voter_id)
# Since we can take in either candidate_id or candidate_we_vote_id, we need to retrieve the candidate object
# so we make sure we have both of these values to return
if positive_value_exists(candidate_id):
candidate_campaign_manager = CandidateCampaignManager()
results = candidate_campaign_manager.retrieve_candidate_campaign_from_id(candidate_id)
if results['candidate_campaign_found']:
candidate_campaign = results['candidate_campaign']
candidate_we_vote_id = candidate_campaign.we_vote_id
elif positive_value_exists(candidate_we_vote_id):
candidate_campaign_manager = CandidateCampaignManager()
results = candidate_campaign_manager.retrieve_candidate_campaign_from_we_vote_id(candidate_we_vote_id)
if results['candidate_campaign_found']:
candidate_campaign = results['candidate_campaign']
candidate_id = candidate_campaign.id
if show_positions_this_voter_follows:
positions_followed = position_list_manager.calculate_positions_followed_by_voter(
voter_id, all_positions_list_for_candidate_campaign, organizations_followed_by_voter)
positions_followed_count = len(positions_followed)
json_data = {
'status': 'SUCCESSFUL_RETRIEVE_OF_POSITIONS_FOLLOWED_RE_CANDIDATE',
'success': True,
'count': positions_followed_count,
'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
else:
positions_not_followed = position_list_manager.calculate_positions_not_followed_by_voter(
all_positions_list_for_candidate_campaign, organizations_followed_by_voter)
positions_not_followed_count = len(positions_not_followed)
json_data = {
'status': 'SUCCESSFUL_RETRIEVE_OF_POSITIONS_NOT_FOLLOWED_CC',
'success': True,
'count': positions_not_followed_count,
'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
示例4: position_list_for_ballot_item_for_api
# 需要导入模块: from candidate.models import CandidateCampaignManager [as 别名]
# 或者: from candidate.models.CandidateCampaignManager import retrieve_candidate_campaign_from_we_vote_id [as 别名]
def position_list_for_ballot_item_for_api(voter_device_id, # positionListForBallotItem
office_id, office_we_vote_id,
candidate_id, candidate_we_vote_id,
measure_id, measure_we_vote_id,
stance_we_are_looking_for=ANY_STANCE,
show_positions_this_voter_follows=True):
"""
We want to return a JSON file with the position identifiers from orgs, friends and public figures the voter follows
This list of information is used to retrieve the detailed information
"""
position_manager = PositionEnteredManager()
# Get voter_id from the voter_device_id so we can know who is supporting/opposing
results = is_voter_device_id_valid(voter_device_id)
if not results['success']:
position_list = []
json_data = {
'status': 'VALID_VOTER_DEVICE_ID_MISSING',
'success': False,
'count': 0,
'kind_of_ballot_item': "UNKNOWN",
'ballot_item_id': 0,
'position_list': position_list,
}
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):
position_list = []
json_data = {
'status': "VALID_VOTER_ID_MISSING ",
'success': False,
'count': 0,
'kind_of_ballot_item': "UNKNOWN",
'ballot_item_id': 0,
'position_list': position_list,
}
return HttpResponse(json.dumps(json_data), content_type='application/json')
position_list_manager = PositionListManager()
ballot_item_found = False
if positive_value_exists(candidate_id) or positive_value_exists(candidate_we_vote_id):
all_positions_list = position_list_manager.retrieve_all_positions_for_candidate_campaign(
candidate_id, candidate_we_vote_id, stance_we_are_looking_for)
kind_of_ballot_item = CANDIDATE
# Since we want to return the id and we_vote_id, and we don't know for sure that there are any positions
# for this ballot_item, we retrieve the following so we can get the id and we_vote_id (per the request of
# the WebApp team)
candidate_campaign_manager = CandidateCampaignManager()
if positive_value_exists(candidate_id):
results = candidate_campaign_manager.retrieve_candidate_campaign_from_id(candidate_id)
else:
results = candidate_campaign_manager.retrieve_candidate_campaign_from_we_vote_id(candidate_we_vote_id)
if results['candidate_campaign_found']:
candidate_campaign = results['candidate_campaign']
ballot_item_id = candidate_campaign.id
ballot_item_we_vote_id = candidate_campaign.we_vote_id
ballot_item_found = True
else:
ballot_item_id = candidate_id
ballot_item_we_vote_id = candidate_we_vote_id
elif positive_value_exists(measure_id) or positive_value_exists(measure_we_vote_id):
all_positions_list = position_list_manager.retrieve_all_positions_for_contest_measure(
measure_id, measure_we_vote_id, stance_we_are_looking_for)
kind_of_ballot_item = MEASURE
# Since we want to return the id and we_vote_id, and we don't know for sure that there are any positions
# for this ballot_item, we retrieve the following so we can get the id and we_vote_id (per the request of
# the WebApp team)
contest_measure_manager = ContestMeasureManager()
if positive_value_exists(measure_id):
results = contest_measure_manager.retrieve_contest_measure_from_id(measure_id)
else:
results = contest_measure_manager.retrieve_contest_measure_from_we_vote_id(measure_we_vote_id)
if results['contest_measure_found']:
contest_measure = results['contest_measure']
ballot_item_id = contest_measure.id
ballot_item_we_vote_id = contest_measure.we_vote_id
ballot_item_found = True
else:
ballot_item_id = measure_id
ballot_item_we_vote_id = measure_we_vote_id
elif positive_value_exists(office_id) or positive_value_exists(office_we_vote_id):
all_positions_list = position_list_manager.retrieve_all_positions_for_contest_office(
office_id, office_we_vote_id, stance_we_are_looking_for)
kind_of_ballot_item = OFFICE
# Since we want to return the id and we_vote_id, and we don't know for sure that there are any positions
# for this ballot_item, we retrieve the following so we can get the id and we_vote_id (per the request of
# the WebApp team)
contest_office_manager = ContestOfficeManager()
if positive_value_exists(office_id):
results = contest_office_manager.retrieve_contest_office_from_id(office_id)
else:
results = contest_office_manager.retrieve_contest_office_from_we_vote_id(office_we_vote_id)
if results['contest_office_found']:
contest_office = results['contest_office']
#.........这里部分代码省略.........