def create(body):
    request_body = RequestBody(body)
    result = BallotBox.create(electionId=request_body.get("electionId"),
                              ballotBoxId=request_body.get("ballotBoxId"))

    db.session.commit()

    return Schema().dump(result).data, 201
    def __init__(self, tallySheetVersionId, ballotBoxStationaryItemId,
                 numberOfPacketsInserted, numberOfAPacketsFound):
        ballotBox = BallotBox.get_by_id(
            stationaryItemId=ballotBoxStationaryItemId)

        if ballotBox is not None:
            super(TallySheetVersionRow_CE_201_PV_Model, self).__init__(
                tallySheetVersionId=tallySheetVersionId,
                ballotBoxStationaryItemId=ballotBoxStationaryItemId,
                numberOfPacketsInserted=numberOfPacketsInserted,
                numberOfAPacketsFound=numberOfAPacketsFound)
            db.session.add(self)
            db.session.flush()
        else:
            raise NotFoundException(
                "Ballot Box not found (ballotBoxStationaryItemId=%s)" %
                ballotBoxStationaryItemId)
    def __init__(self, tallySheetVersionRow, ballotBoxStationaryItemId):
        ballotBox = BallotBox.get_by_id(
            stationaryItemId=ballotBoxStationaryItemId)

        if ballotBox is None:
            raise NotFoundException(
                "Ballot Box not found. (stationaryItemId=%d)" %
                ballotBoxStationaryItemId)

        if ballotBox.electionId != tallySheetVersionRow.tallySheetVersion.submission.electionId:
            raise NotFoundException(
                "Ballot Box is not registered for the given election. (stationaryItemId=%d)"
                % ballotBoxStationaryItemId)

        super(TallySheetVersionRow_CE_201_BallotBox_Model, self).__init__(
            tallySheetVersionRowId=tallySheetVersionRow.tallySheetVersionRowId,
            ballotBoxStationaryItemId=ballotBoxStationaryItemId)
        db.session.add(self)
        db.session.flush()
def get_all(ballotBoxId=None, electionId=None):
    result = BallotBox.get_all(ballotBoxId=ballotBoxId, electionId=electionId)

    return Schema(many=True).dump(result).data
def get_all(ballotBoxId):
    result = BallotBox.get_all(ballotBoxId=ballotBoxId)

    return Schema(many=True).dump(result).data