示例#1
0
def members(member=None):
    # load network from database
    network = Network.from_dict(
        db.collection('data').document('network').get().to_dict())

    # check to make sure members were successfully loaded
    if network is None:
        return Response(status=503)

    # get member/members from network
    response = network.get_members(member)

    # check that network contained a match
    if response is None:
        return Response(status=404)

    # if specific member was requested, return full member object
    if isinstance(response, Member):
        return jsonify(response.to_dict(abbreviated=False)), 200

    # abbreviate member info (less info)
    member_dict = []
    for member in response.values():
        member_dict.append(member.to_dict(abbreviated=True))

    # return all users
    return jsonify(member_dict), 200
示例#2
0
def members_filter():
    # return error if no tag was provided
    if not all(arg in request.args for arg in ('field', 'value')):
        return jsonify(
            'Incorrect parameters received: %s, need \'field\' and \'value\'' %
            request.args), 400

    # get tag
    field = request.args['field']
    value = request.args['value']

    # get network from firestore
    network = Network.from_dict(
        db.collection('data').document('network').get().to_dict())

    # get members matching tag
    members = network.get_members_of('(%s, %s)' % (field, value))

    # create serializable response
    matches = []
    for member in members:
        matches.append(member.to_dict(abbreviated=True))

    return jsonify(matches), 200