Beispiel #1
0
def organization_unfollow_view(request, organization_id):
    print "organization_unfollow_view {organization_id}".format(
        organization_id=organization_id)
    voter_id = 1
    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"})
Beispiel #2
0
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"})
Beispiel #3
0
def organization_unfollow_view(request, organization_id):
    logger.debug("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"})
Beispiel #4
0
def organization_follow_all(voter_device_id, organization_id, organization_we_vote_id, follow_kind=FOLLOWING):
    if not positive_value_exists(voter_device_id):
        json_data = {
            'status': 'VALID_VOTER_DEVICE_ID_MISSING',
            'success': False,
            'voter_device_id': voter_device_id,
            'organization_id': organization_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': 'VALID_VOTER_ID_MISSING',
            'success': False,
            'voter_device_id': voter_device_id,
            'organization_id': organization_id,
        }
        return HttpResponse(json.dumps(json_data), content_type='application/json')

    organization_id = convert_to_int(organization_id)
    if not positive_value_exists(organization_id) and not positive_value_exists(organization_we_vote_id):
        json_data = {
            'status': 'VALID_ORGANIZATION_ID_MISSING',
            'success': False,
            'voter_device_id': voter_device_id,
            'organization_id': organization_id,
        }
        return HttpResponse(json.dumps(json_data), content_type='application/json')

    if follow_kind == FOLLOWING:
        follow_organization_manager = FollowOrganizationManager()
        results = follow_organization_manager.toggle_on_voter_following_organization(
            voter_id, organization_id, organization_we_vote_id)
        if results['follow_organization_found']:
            status = 'FOLLOWING'
            success = True
            follow_organization = results['follow_organization']
            organization_id = follow_organization.organization_id
            organization_we_vote_id = follow_organization.organization_we_vote_id
        else:
            status = results['status']
            success = False

    elif follow_kind == FOLLOW_IGNORE:
        follow_organization_manager = FollowOrganizationManager()
        results = follow_organization_manager.toggle_ignore_voter_following_organization(
            voter_id, organization_id, organization_we_vote_id)
        if results['follow_organization_found']:
            status = 'IGNORING'
            success = True
            follow_organization = results['follow_organization']
            organization_id = follow_organization.organization_id
            organization_we_vote_id = follow_organization.organization_we_vote_id
        else:
            status = results['status']
            success = False
    elif follow_kind == STOP_FOLLOWING:
        follow_organization_manager = FollowOrganizationManager()
        results = follow_organization_manager.toggle_off_voter_following_organization(
            voter_id, organization_id, organization_we_vote_id)
        if results['follow_organization_found']:
            status = 'STOPPED_FOLLOWING'
            success = True
            follow_organization = results['follow_organization']
            organization_id = follow_organization.organization_id
            organization_we_vote_id = follow_organization.organization_we_vote_id
        else:
            status = results['status']
            success = False
    else:
        status = 'INCORRECT_FOLLOW_KIND'
        success = False

    json_data = {
        'status': status,
        'success': success,
        'voter_device_id': voter_device_id,
        'organization_id': organization_id,
        'organization_we_vote_id': organization_we_vote_id,
    }
    return HttpResponse(json.dumps(json_data), content_type='application/json')
Beispiel #5
0
def organization_follow_all(voter_device_id,
                            organization_id,
                            organization_we_vote_id,
                            follow_kind=FOLLOWING):
    if not positive_value_exists(voter_device_id):
        json_data = {
            'status': 'VALID_VOTER_DEVICE_ID_MISSING',
            'success': False,
            'voter_device_id': voter_device_id,
            'organization_id': organization_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': 'VALID_VOTER_ID_MISSING',
            'success': False,
            'voter_device_id': voter_device_id,
            'organization_id': organization_id,
        }
        return HttpResponse(json.dumps(json_data),
                            content_type='application/json')

    organization_id = convert_to_int(organization_id)
    if not positive_value_exists(
            organization_id) and not positive_value_exists(
                organization_we_vote_id):
        json_data = {
            'status': 'VALID_ORGANIZATION_ID_MISSING',
            'success': False,
            'voter_device_id': voter_device_id,
            'organization_id': organization_id,
        }
        return HttpResponse(json.dumps(json_data),
                            content_type='application/json')

    if follow_kind == FOLLOWING:
        follow_organization_manager = FollowOrganizationManager()
        results = follow_organization_manager.toggle_on_voter_following_organization(
            voter_id, organization_id, organization_we_vote_id)
        if results['follow_organization_found']:
            status = 'FOLLOWING'
            success = True
            follow_organization = results['follow_organization']
            organization_id = follow_organization.organization_id
            organization_we_vote_id = follow_organization.organization_we_vote_id
        else:
            status = results['status']
            success = False

    elif follow_kind == FOLLOW_IGNORE:
        follow_organization_manager = FollowOrganizationManager()
        results = follow_organization_manager.toggle_ignore_voter_following_organization(
            voter_id, organization_id, organization_we_vote_id)
        if results['follow_organization_found']:
            status = 'IGNORING'
            success = True
            follow_organization = results['follow_organization']
            organization_id = follow_organization.organization_id
            organization_we_vote_id = follow_organization.organization_we_vote_id
        else:
            status = results['status']
            success = False
    elif follow_kind == STOP_FOLLOWING:
        follow_organization_manager = FollowOrganizationManager()
        results = follow_organization_manager.toggle_off_voter_following_organization(
            voter_id, organization_id, organization_we_vote_id)
        if results['follow_organization_found']:
            status = 'STOPPED_FOLLOWING'
            success = True
            follow_organization = results['follow_organization']
            organization_id = follow_organization.organization_id
            organization_we_vote_id = follow_organization.organization_we_vote_id
        else:
            status = results['status']
            success = False
    else:
        status = 'INCORRECT_FOLLOW_KIND'
        success = False

    json_data = {
        'status': status,
        'success': success,
        'voter_device_id': voter_device_id,
        'organization_id': organization_id,
        'organization_we_vote_id': organization_we_vote_id,
    }
    return HttpResponse(json.dumps(json_data), content_type='application/json')