예제 #1
0
def get_household_types():
    """Pulls in a list of the most recent members of the Congregation."""
    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

    response = {}
    all_households = members.get_household_types()
    for item in all_households:
        item['total'] = str(item['total'])
    response['all_households'] = all_households

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

    new_households = members.get_household_types(start=new_start)
    for item in new_households:
        item['total'] = str(item['total'])
    response['new_households'] = new_households

    return jsonify(response)
예제 #2
0
def get_households_by_year():
    """Pulls in a list of the most recent members of the Congregation."""
    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

    years = request.args.get('years')
    years = int(years) if years else 10

    tally = request.args.get('tally')
    tally = 'households' if not tally else tally

    now = datetime.datetime.now()
    end = now.year
    start = end - years

    if tally == 'resignations':
        response = members.get_resignations_by_year(start, end)
    else:
        response = members.get_households_by_year(start, end)
    return jsonify(response)
예제 #3
0
def get_resignation_types():
    """Breaks down resignations over hte past year by type."""
    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

    resignation_types = members.get_resignation_types()
    return jsonify(resignation_types)
예제 #4
0
def get_new_member_count():
    """Pulls the new event counts by quarter."""
    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

    quarters = get_quarters(19)
    response = get_quarterly_new_members(quarters, members)
    response = {k: str(response[k]) for k in response}
    return jsonify(response)
예제 #5
0
def get_report_event_count():
    """Pulls the event counts for the current report."""
    event_manager = Events()
    jwt_user = get_jwt_identity()

    authorized = utils.check_access(jwt_user, conf.REPORT_GROUP,
                                    event_manager.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

    quarters = get_quarters(3)
    response = get_quarterly_event_counts(quarters, event_manager)
    response = convert_counts_to_string(response)
    return jsonify(response)
예제 #6
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)
예제 #7
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)
예제 #8
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 test_check_access():
    fake_database = FakeDatabase()
    assert utils.check_access('Jabber', 'members', fake_database) == True
    assert utils.check_access('Chester', 'members', fake_database) == False