Exemple #1
0
def get_member_demographics():
    """Pulls the current membership demographics."""
    members = Members()
    jwt_user = get_jwt_identity()

    authorized = utils.check_access(jwt_user, conf.REPORT_GROUP,
                                    members.database)
    utils.log_request(request, jwt_user, authorized)

    if not authorized:
        response = {
            'message': '{} does not have access to reports.'.format(jwt_user)
        }
        return jsonify(response), 403

    only = request.args.get('only')
    new_members = only == 'new_members'

    response = members.get_demographics(new_members=new_members)
    return jsonify(response)
Exemple #2
0
def upload_members():
    """ Uploads membership data as a .csv or excel file """
    member_manager = Members()
    jwt_user = get_jwt_identity()
    user = member_manager.database.get_item('users', jwt_user)

    authorized = user['role'] == conf.ADMIN_ROLE
    log_request(request, jwt_user, authorized)

    if not authorized:
        response = {'message': 'only admins can upload files'}
        return jsonify(response), 403

    file_type = request.args.get('file_type')
    file_type = 'members' if not file_type else file_type

    good_upload = member_manager.upload_file(request, file_type=file_type)
    if good_upload:
        response = {'message': 'success'}
        return jsonify(response)
    else:
        abort(422)
Exemple #3
0
def get_new_members():
    """Pulls in a list of the most recent members of the Congregation."""
    database = Database()
    jwt_user = get_jwt_identity()

    authorized = utils.check_access(jwt_user, conf.REPORT_GROUP, database)
    utils.log_request(request, jwt_user, authorized)

    if not authorized:
        response = {
            'message': '{} does not have access to reports.'.format(jwt_user)
        }
        return jsonify(response), 403

    limit_param = request.args.get('limit')
    limit = limit_param if limit_param else 25
    new_members = database.read_table('members_view',
                                      limit=limit,
                                      order='desc',
                                      sort='membership_date')
    response = database.to_json(new_members)
    return jsonify(response)
Exemple #4
0
def get_event_locations():
    """ Pulls the most recent event at each location """
    event_manager = Events()
    # Make sure the user has access to the module
    jwt_user = get_jwt_identity()
    user = event_manager.database.get_item('users', jwt_user)

    authorized = conf.MAP_GROUP in user['modules']
    log_request(request, jwt_user, authorized)


    if not authorized:
        response = {'message': '%s does not have acccess to the map'%(jwt_user)}
        return jsonify(response), 403

    fake_data = request.args.get('fake_data')
    fake_data = fake_data is not None and fake_data == 'true'
    event_category = request.args.get('event_category')

    response = event_manager.get_event_locations(fake=fake_data,
                                                 event_category=event_category)
    return jsonify(response)
Exemple #5
0
def get_event(event_id):
    """ Pulls the information for an event from the database """
    event_manager = Events()
    # Make sure the user has access to the module
    jwt_user = get_jwt_identity()
    user = event_manager.database.get_item('users', jwt_user)

    authorized = conf.EVENT_GROUP in user['modules']
    log_request(request, jwt_user, authorized)

    if not authorized:
        response = {'message': '%s does not have acccess to events'%(jwt_user)}
        return jsonify(response), 403

    fake_data = request.args.get('fake_data')
    fake_data = fake_data is not None and fake_data == 'true'
    event = event_manager.get_event(event_id, fake=fake_data)
    if event:
        return jsonify(event)
    else:
        response = {'message': 'not found'}
        return jsonify(response), 404
Exemple #6
0
def get_member_locations():
    """Pulls in the current breakdown of member location."""
    members = Members()
    jwt_user = get_jwt_identity()

    authorized = utils.check_access(jwt_user, conf.REPORT_GROUP,
                                    members.database)
    utils.log_request(request, jwt_user, authorized)

    if not authorized:
        response = {
            'message': '{} does not have access to reports.'.format(jwt_user)
        }
        return jsonify(response), 403

    level = request.args.get('level')
    level = level if level else 'city'

    now = datetime.datetime.now()
    year_ago = str(now - datetime.timedelta(days=365))[:10]
    five_years_ago = str(now - datetime.timedelta(days=365 * 5))[:10]

    # Hard coding these settings for now, but we can move these
    # to the config files if a client wants something different
    response = {}
    response['all_members'] = members.get_member_locations('city', limit=8)
    response['new_members'] = members.get_member_locations('city',
                                                           limit=8,
                                                           start=year_ago)
    response['year_ago'] = members.get_member_locations('city',
                                                        limit=8,
                                                        end=year_ago)
    response['five_years_ago'] = members.get_member_locations(
        'city', limit=8, end=five_years_ago)
    common_locations = _find_common_locations(response)
    response['percentages'] = build_locations_pct(response, common_locations)
    response['common_locations'] = list(common_locations)
    return jsonify(response)
def get_participant(participant_id):
    """ Pulls a participants information from the database """
    participant_manager = Participants()
    jwt_user = get_jwt_identity()
    user = participant_manager.database.get_item('users', jwt_user)

    authorized = conf.MEMBER_GROUP in user['modules']
    log_request(request, jwt_user, authorized)

    if not authorized:
        response = {
            'message': '%s does not have access to participants' % (jwt_user)
        }
        return jsonify(response), 403

    fake_data = request.args.get('fake_data')
    fake_data = fake_data is not None and fake_data == 'true'
    participant = participant_manager.get_participant(participant_id,
                                                      fake=fake_data)
    if participant:
        return jsonify(participant)
    else:
        response = {'message': 'not found'}
        return jsonify(response), 404
def test_log_request():
    fake_database = FakeDatabase()
    fake_request = FakeRequest()

    utils.log_request(fake_request, 'jabber', False, fake_database)