示例#1
0
文件: vote.py 项目: WEB3-GForce/VOTE
def vote(member_identifier, bill_identifier):
    """Predicts how the specified member will vote on the given bill.

    Arguments:
        member_identifier: A value that identifies the member such as full_name
            or database id. Make sure the value uniquely identifies the member
            in the database.
        bill_identifier: A value that identifies the bill such as bill_number or
            database id. Make sure the value uniquely identifies the bill in the
            database.

    Returns:
        A decision object containing the results of the decision on the vote
    """

    member = PymongoDB.get_db().find_one(db_constants.MEMBERS,
        queries.member_query(member_identifier))
    bill = PymongoDB.get_db().find_one(db_constants.BILLS,
        queries.bill_query(bill_identifier))

    if not member:
        logger.LOGGER.error("Member not found in DB: %s" % member_identifier)
        return None
    if not bill:
        logger.LOGGER.error("Bill not found in DB: %s" % bill_identifier)
        return None

    return _vote_helper(member, bill)
示例#2
0
文件: vote.py 项目: WEB3-GForce/VOTE
def _get_members(member_identifier=None):
    """Retrieves the members for vote_all. If member_identifier is specified,
    the specific member is looked up in the DB. If the name is not specified or
    the member was not found, a cursor for a Pymongo find request is returned.

    Arguments:
        member_identifier: the identifier of the member to retrieve.

    Returns:
        Either an array with the member specified in member_identifier or an
        iterator for all members who will vote.
    """
    member = None
    if member_identifier:
        member = PymongoDB.get_db().find_one(db_constants.MEMBERS,
            queries.member_query(member_identifier))

    if member:
        return [member]
    else:
        if member_identifier:
            logger.LOGGER.error("Bill not found: %s" % member_identifier)
        return PymongoDB.get_db().find(db_constants.MEMBERS)