本文整理汇总了Python中voter.models.fetch_voter_id_from_voter_device_link函数的典型用法代码示例。如果您正苦于以下问题:Python fetch_voter_id_from_voter_device_link函数的具体用法?Python fetch_voter_id_from_voter_device_link怎么用?Python fetch_voter_id_from_voter_device_link使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fetch_voter_id_from_voter_device_link函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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')
示例2: voter_stop_asking_candidate_campaign_view
def voter_stop_asking_candidate_campaign_view(request, candidate_campaign_id):
print "voter_stop_asking_candidate_campaign_view {candidate_campaign_id}".format(
candidate_campaign_id=candidate_campaign_id)
voter_device_id = get_voter_device_id(request)
voter_id = fetch_voter_id_from_voter_device_link(voter_device_id)
return JsonResponse({0: "not working yet - needs to be built"})
示例3: voter_guide_possibility_retrieve_for_api
def voter_guide_possibility_retrieve_for_api(voter_device_id, voter_guide_possibility_url):
results = is_voter_device_id_valid(voter_device_id)
voter_guide_possibility_url = voter_guide_possibility_url # TODO Use scrapy here
if not results['success']:
return HttpResponse(json.dumps(results['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': "VOTER_NOT_FOUND_FROM_VOTER_DEVICE_ID",
'success': False,
'voter_device_id': voter_device_id,
}
return HttpResponse(json.dumps(json_data), content_type='application/json')
# TODO We will need the voter_id here so we can control volunteer actions
voter_guide_possibility_manager = VoterGuidePossibilityManager()
results = voter_guide_possibility_manager.retrieve_voter_guide_possibility_from_url(voter_guide_possibility_url)
json_data = {
'voter_device_id': voter_device_id,
'voter_guide_possibility_url': results['voter_guide_possibility_url'],
'voter_guide_possibility_id': results['voter_guide_possibility_id'],
'organization_we_vote_id': results['organization_we_vote_id'],
'public_figure_we_vote_id': results['public_figure_we_vote_id'],
'owner_we_vote_id': results['owner_we_vote_id'],
'status': results['status'],
'success': results['success'],
}
return HttpResponse(json.dumps(json_data), content_type='application/json')
示例4: voter_star_on_save_for_api
def voter_star_on_save_for_api(voter_device_id, office_id, candidate_id, measure_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}
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")
star_item_manager = StarItemManager()
if positive_value_exists(office_id):
results = star_item_manager.toggle_on_voter_starred_office(voter_id, office_id)
status = "STAR_ON_OFFICE " + results["status"]
success = results["success"]
elif positive_value_exists(candidate_id):
results = star_item_manager.toggle_on_voter_starred_candidate(voter_id, candidate_id)
status = "STAR_ON_CANDIDATE " + results["status"]
success = results["success"]
elif positive_value_exists(measure_id):
results = star_item_manager.toggle_on_voter_starred_measure(voter_id, measure_id)
status = "STAR_ON_MEASURE " + results["status"]
success = results["success"]
else:
status = "UNABLE_TO_SAVE_ON-OFFICE_ID_AND_CANDIDATE_ID_AND_MEASURE_ID_MISSING"
success = False
json_data = {"status": status, "success": success}
return HttpResponse(json.dumps(json_data), content_type="application/json")
示例5: voter_authenticate_manually_process_view
def voter_authenticate_manually_process_view(request):
voter_api_device_id = get_voter_api_device_id(request) # We look in the cookies for voter_api_device_id
voter_id = fetch_voter_id_from_voter_device_link(voter_api_device_id)
voter_id = convert_to_int(voter_id)
voter_signed_in = False
try:
voter_on_stage = Voter.objects.get(id=voter_id)
# If the account associated with this voter_api_device_id is an admin, complete Django authentication
if voter_on_stage.is_admin:
voter_on_stage.backend = 'django.contrib.auth.backends.ModelBackend'
login(request, voter_on_stage)
messages.add_message(request, messages.INFO, 'Voter logged in.')
voter_signed_in = True
else:
messages.add_message(request, messages.INFO, 'This account does not have Admin access.')
except Voter.MultipleObjectsReturned as e:
handle_record_found_more_than_one_exception(e, logger=logger)
messages.add_message(request, messages.ERROR, 'More than one voter found. Voter not logged in.')
except Voter.DoesNotExist:
# This is fine, we will display an error
messages.add_message(request, messages.ERROR, 'Voter not found. Voter not logged in.')
if voter_signed_in:
return HttpResponseRedirect(reverse('admin_tools:admin_home', args=()))
else:
return HttpResponseRedirect(reverse('voter:authenticate_manually', args=()))
示例6: voter_authenticate_manually_view
def voter_authenticate_manually_view(request):
messages_on_stage = get_messages(request)
voter_api_device_id = get_voter_api_device_id(request) # We look in the cookies for voter_api_device_id
store_new_voter_api_device_id_in_cookie = False
if not positive_value_exists(voter_api_device_id):
# Create a voter_device_id and voter in the database if one doesn't exist yet
results = voter_setup(request)
voter_api_device_id = results['voter_api_device_id']
store_new_voter_api_device_id_in_cookie = results['store_new_voter_api_device_id_in_cookie']
voter_id = fetch_voter_id_from_voter_device_link(voter_api_device_id)
voter_id = convert_to_int(voter_id)
voter_on_stage_found = False
voter_on_stage = Voter()
try:
voter_on_stage = Voter.objects.get(id=voter_id)
voter_on_stage_found = True
except Voter.MultipleObjectsReturned as e:
handle_record_found_more_than_one_exception(e, logger=logger)
except Voter.DoesNotExist:
# This is fine, we will display an error
pass
if voter_on_stage_found:
set_this_voter_as_admin = "UPDATE voter_voter SET is_admin=True WHERE id={voter_id};".format(voter_id=voter_id)
unset_this_voter_as_admin = "UPDATE voter_voter SET is_admin=False WHERE id={voter_id};".format(
voter_id=voter_id)
set_as_verified_volunteer = "UPDATE voter_voter SET is_verified_volunteer=True WHERE id={voter_id};" \
"".format(voter_id=voter_id)
unset_as_verified_volunteer = "UPDATE voter_voter SET is_verified_volunteer=False WHERE id={voter_id};" \
"".format(voter_id=voter_id)
template_values = {
'messages_on_stage': messages_on_stage,
'voter': voter_on_stage,
'voter_api_device_id': voter_api_device_id,
'is_authenticated': request.user.is_authenticated(),
'set_this_voter_as_admin': set_this_voter_as_admin,
'unset_this_voter_as_admin': unset_this_voter_as_admin,
'set_as_verified_volunteer': set_as_verified_volunteer,
'unset_as_verified_volunteer': unset_as_verified_volunteer,
}
else:
template_values = {
'messages_on_stage': messages_on_stage,
}
response = render(request, 'voter/voter_authenticate_manually.html', template_values)
# We want to store the voter_api_device_id cookie if it is new
# if positive_value_exists(voter_api_device_id) and positive_value_exists(store_new_voter_api_device_id_in_cookie):
# DALE 2016-02-15 Always set if we have a voter_api_device_id
if positive_value_exists(store_new_voter_api_device_id_in_cookie):
set_voter_api_device_id(request, response, voter_api_device_id)
return response
示例7: voter_stop_asking_candidate_campaign_view
def voter_stop_asking_candidate_campaign_view(request, candidate_campaign_id):
logger.debug("voter_stop_asking_candidate_campaign_view {candidate_campaign_id}".format(
candidate_campaign_id=candidate_campaign_id
))
voter_api_device_id = get_voter_api_device_id(request)
voter_id = fetch_voter_id_from_voter_device_link(voter_api_device_id)
logger.debug("voter_stop_asking_candidate_campaign_view NOT BUILT YET, voter_id: {voter_id}".format(
voter_id=voter_id
))
return JsonResponse({0: "not working yet - needs to be built"})
示例8: voter_stance_for_contest_measure_view
def voter_stance_for_contest_measure_view(request, contest_measure_id):
logger.debug("voter_stance_for_contest_measure_view {contest_measure_id}".format(
contest_measure_id=contest_measure_id
))
voter_api_device_id = get_voter_api_device_id(request)
voter_id = fetch_voter_id_from_voter_device_link(voter_api_device_id)
logger.debug("voter_stance_for_contest_measure_view NOT BUILT YET, voter_id: {voter_id}".format(
voter_id=voter_id
))
return JsonResponse({0: "not working yet - needs to be built"})
示例9: organization_unfollow_view
def organization_unfollow_view(request, organization_id):
print "organization_unfollow_view {organization_id}".format(
organization_id=organization_id)
voter_device_id = get_voter_device_id(request)
voter_id = fetch_voter_id_from_voter_device_link(voter_device_id)
follow_organization_manager = FollowOrganizationManager()
results = follow_organization_manager.toggle_off_voter_following_organization(voter_id, organization_id)
if results['success']:
return JsonResponse({0: "success"})
else:
return JsonResponse({0: "failure"})
示例10: voter_supporting_candidate_campaign_view
def voter_supporting_candidate_campaign_view(request, candidate_campaign_id):
# print "voter_supporting_candidate_campaign_view {candidate_campaign_id}".format(
# candidate_campaign_id=candidate_campaign_id)
voter_device_id = get_voter_device_id(request)
voter_id = fetch_voter_id_from_voter_device_link(voter_device_id)
position_entered_manager = PositionEnteredManager()
results = position_entered_manager.toggle_on_voter_support_for_candidate_campaign(voter_id, candidate_campaign_id)
if results['success']:
return JsonResponse({0: "success"})
else:
return JsonResponse({0: "failure"})
示例11: voter_stop_opposing_candidate_campaign_view
def voter_stop_opposing_candidate_campaign_view(request, candidate_campaign_id):
logger.debug("voter_stop_opposing_candidate_campaign_view {candidate_campaign_id}".format(
candidate_campaign_id=candidate_campaign_id
))
voter_api_device_id = get_voter_api_device_id(request)
voter_id = fetch_voter_id_from_voter_device_link(voter_api_device_id)
position_entered_manager = PositionEnteredManager()
results = position_entered_manager.toggle_off_voter_oppose_for_candidate_campaign(voter_id, candidate_campaign_id)
if results['success']:
return JsonResponse({0: "success"})
else:
return JsonResponse({0: "failure"})
示例12: voter_position_like_status_retrieve_for_api
def voter_position_like_status_retrieve_for_api(voter_device_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,
'voter_device_id': voter_device_id,
'is_liked': False,
'position_entered_id': position_entered_id,
'position_like_id': 0,
}
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_liked': False,
'position_entered_id': position_entered_id,
'position_like_id': 0,
}
return HttpResponse(json.dumps(json_data), content_type='application/json')
position_like_manager = PositionLikeManager()
if positive_value_exists(position_entered_id):
position_like_id = 0
results = position_like_manager.retrieve_position_like(position_like_id, voter_id, position_entered_id)
status = results['status']
success = results['success']
is_liked = results['is_liked']
position_like_id = results['position_like_id']
else:
status = 'UNABLE_TO_RETRIEVE-POSITION_ENTERED_ID_MISSING'
success = False
is_liked = False
position_like_id = 0
json_data = {
'status': status,
'success': success,
'voter_device_id': voter_device_id,
'is_liked': is_liked,
'position_entered_id': position_entered_id,
'position_like_id': position_like_id,
}
return HttpResponse(json.dumps(json_data), content_type='application/json')
示例13: voter_create
def voter_create(voter_device_id):
results = is_voter_device_id_valid(voter_device_id)
if not results['success']:
return HttpResponse(json.dumps(results['json_data']), content_type='application/json')
voter_id = 0
# Make sure a voter record hasn't already been created for this
existing_voter_id = fetch_voter_id_from_voter_device_link(voter_device_id)
if existing_voter_id:
json_data = {
'status': "VOTER_ALREADY_EXISTS",
'success': False,
'voter_device_id': voter_device_id,
}
return HttpResponse(json.dumps(json_data), content_type='application/json')
# Create a new voter and return the id
voter_manager = VoterManager()
results = voter_manager.create_voter()
if results['voter_created']:
voter = results['voter']
# Now save the voter_device_link
voter_device_link_manager = VoterDeviceLinkManager()
results = voter_device_link_manager.save_new_voter_device_link(voter_device_id, voter.id)
if results['voter_device_link_created']:
voter_device_link = results['voter_device_link']
voter_id_found = True if voter_device_link.voter_id > 0 else False
if voter_id_found:
voter_id = voter_device_link.voter_id
if voter_id:
json_data = {
'status': "VOTER_CREATED",
'success': False,
'voter_device_id': voter_device_id,
'voter_id': voter_id, # We may want to remove this after initial testing
}
return HttpResponse(json.dumps(json_data), content_type='application/json')
else:
json_data = {
'status': "VOTER_NOT_CREATED",
'success': False,
'voter_device_id': voter_device_id,
}
return HttpResponse(json.dumps(json_data), content_type='application/json')
示例14: voter_guide_possibility_save_for_api
def voter_guide_possibility_save_for_api(voter_device_id, voter_guide_possibility_url):
results = is_voter_device_id_valid(voter_device_id)
if not results['success']:
return HttpResponse(json.dumps(results['json_data']), content_type='application/json')
if not voter_guide_possibility_url:
json_data = {
'status': "MISSING_POST_VARIABLE-URL",
'success': False,
'voter_device_id': voter_device_id,
}
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': "VOTER_NOT_FOUND_FROM_DEVICE_ID",
'success': False,
'voter_device_id': voter_device_id,
}
return HttpResponse(json.dumps(json_data), content_type='application/json')
# At this point, we have a valid voter
voter_guide_possibility_manager = VoterGuidePossibilityManager()
# We wrap get_or_create because we want to centralize error handling
results = voter_guide_possibility_manager.update_or_create_voter_guide_possibility(
voter_guide_possibility_url.strip())
if results['success']:
json_data = {
'status': "VOTER_GUIDE_POSSIBILITY_SAVED",
'success': True,
'voter_device_id': voter_device_id,
'voter_guide_possibility_url': voter_guide_possibility_url,
}
# elif results['status'] == 'MULTIPLE_MATCHING_ADDRESSES_FOUND':
# delete all currently matching addresses and save again?
else:
json_data = {
'status': results['status'],
'success': False,
'voter_device_id': voter_device_id,
}
return HttpResponse(json.dumps(json_data), content_type='application/json')
示例15: positions_count_for_api
def positions_count_for_api(voter_device_id,
candidate_id, candidate_we_vote_id,
measure_id, measure_we_vote_id,
stance_we_are_looking_for):
# 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']:
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')
show_positions_this_voter_follows = True
if positive_value_exists(candidate_id) or positive_value_exists(candidate_we_vote_id):
results = positions_count_for_candidate_campaign(voter_id,
candidate_id, candidate_we_vote_id,
stance_we_are_looking_for,
show_positions_this_voter_follows)
json_data = results['json_data']
return HttpResponse(json.dumps(json_data), content_type='application/json')
elif positive_value_exists(measure_id) or positive_value_exists(measure_we_vote_id):
results = positions_count_for_contest_measure(voter_id,
measure_id, measure_we_vote_id,
stance_we_are_looking_for,
show_positions_this_voter_follows)
json_data = results['json_data']
return HttpResponse(json.dumps(json_data), content_type='application/json')
else:
status = 'UNABLE_TO_RETRIEVE-CANDIDATE_ID_AND_MEASURE_ID_MISSING'
success = False
json_data = {
'status': status,
'success': success,
}
return HttpResponse(json.dumps(json_data), content_type='application/json')